mock issues on ia64 with LoadLibrary("libc.so.6")

Doug Chapman doug.chapman at hp.com
Thu Dec 20 14:25:50 UTC 2007


On Thu, 2007-12-20 at 01:19 -0800, Roland McGrath wrote:
> What mock is doing there is a little freaky.  Since the functions you want
> are in libc and you know it's always going to be there, you don't really
> need to ask for the right libc object by name.  
> You can use dlsym (RTLD_DEFAULT, "function") to look up the functions in
> the global scope that the python executable uses, which gets to libc.
> 
> The python code doesn't seem to have a way to use RTLD_DEFAULT.
> But, when you do:
> 
> 	_libc = ctypes.cdll.LoadLibrary(None)
> 
> That translates to dlopen (NULL, ...), which in fact works the same as
> dlopen ("", ...), i.e. opens the executable itself (python).  Since libc is
> a dependency of the executable, its symbols are found by dlsym on the
> handle from dlopen (NULL, ...).
> 
> In short, to the extent this whole kludge of the python code knowing the
> ABI details of some libc symbols is sane at all, it's probably fine enough
> to use "_libc = ctypes.cdll.LoadLibrary(None)" and be "portable".
> 

Roland,

Thanks for the tip.  I have verified this does indeed do the trick.

Could one of the mock maintainers make the fix?  Patch is below.

thanks,

- Doug



diff -up mock-0.9.3/py/mock/uid.py.broken mock-0.9.3/py/mock/uid.py
--- mock-0.9.3/py/mock/uid.py.broken	2007-12-20 09:23:05.000000000 -0500
+++ mock-0.9.3/py/mock/uid.py	2007-12-20 09:23:26.000000000 -0500
@@ -70,7 +70,7 @@ class uidManager(object):
 # python doesnt have native versions of these. :(
 
 import ctypes
-_libc = ctypes.cdll.LoadLibrary("libc.so.6")
+_libc = ctypes.cdll.LoadLibrary(None)
 _errno = ctypes.c_int.in_dll(_libc, "errno")
 
 def getresuid():
diff -up mock-0.9.3/py/mock/util.py.broken mock-0.9.3/py/mock/util.py
--- mock-0.9.3/py/mock/util.py.broken	2007-12-20 09:22:57.000000000 -0500
+++ mock-0.9.3/py/mock/util.py	2007-12-20 09:23:15.000000000 -0500
@@ -193,7 +193,7 @@ personality_defs = {
 }
 
 import ctypes
-_libc = ctypes.cdll.LoadLibrary("libc.so.6")
+_libc = ctypes.cdll.LoadLibrary(None)
 _errno = ctypes.c_int.in_dll(_libc, "errno")
 _libc.personality.argtypes = [ctypes.c_ulong]
 _libc.personality.restype = ctypes.c_int





More information about the Fedora-buildsys-list mailing list