Bugs item #1144263, was opened at 2005-02-19 03:20
Message generated for change (Comment added) made by logistix
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1144263&group_id=5470

Category: Python Interpreter Core
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Submitted By: Matthew G. Knepley (knepley)
Assigned to: Nobody/Anonymous (nobody)
Summary: reload() is broken for C extension objects

Initial Comment:
1) A C extension module (foo.so) is imported

      import foo

2) The library foo.so is rebuilt with changes

3) We reload the module

      foo = reload(foo)

The reload() method calls imp.load_dynamic() which
eventually gets down to _PyImport_GetDynLoadFunc().
This just calls dlopen(), which returns the old filehandle.

This problem can be fixed by augmenting imp with
unload_dynamic(), which could easily be implemented in
a _PyImport_GetDynUnloadFunc(), which would just
consult its handles[] array, and call dlclose() on the
appropriate handle. This will work if Python was the
only program to dlopen() foo.so.

----------------------------------------------------------------------

Comment By: logistix (logistix)
Date: 2005-03-08 14:59

Message:
Logged In: YES 
user_id=699438

I don't know if this is a viable general-purpose fix.  Keep in 
mind that python tracks everything by references, and 
reloading doesn't correct existing bindings.  If you recompile it 
is going to screw up existing function pointers in 
PyCFunction objects.  In the example below calling a() will 
probably end up executing random code or generting a 
memory fault.

>>> import select
>>> a = select.select

... imaginary recompile ...

>>> reload(select)
<module 'select' from 'C:\Python24\DLLs\select.pyd'>
>>> b = select.select
>>> id(a)
18165472
>>> id(b)
18165476
>>> a() #BOOM!

----------------------------------------------------------------------

Comment By: Matthew G. Knepley (knepley)
Date: 2005-02-19 22:34

Message:
Logged In: YES 
user_id=58554

I have coded the proposed solution (changed import.c,
importdl.c, and dynload_shlib.c). I will assemble a test
case for it next week.

----------------------------------------------------------------------

Comment By: Matthew G. Knepley (knepley)
Date: 2005-02-19 15:37

Message:
Logged In: YES 
user_id=58554

I am only interested in fixing it for the dlopen() case,
which I thnk subsumes every architecture likely to have this
problem appear. I have no problem fixing it myself, but I
need to get all the CVS stuff setup. And I am not sure how
to easily generate the patch to send (I'm used to BK).

----------------------------------------------------------------------

Comment By: Michael Hudson (mwh)
Date: 2005-02-19 15:27

Message:
Logged In: YES 
user_id=6656

I don't believe this is quite as easy as you make out.  It might be 
possible to make something that works for platforms that use dlopen 
though...

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1144263&group_id=5470
_______________________________________________
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to