From: Zac Medico Date: Thu, 10 Jan 2013 14:41:15 +0000 (-0800) Subject: Revert "_ctypes: don't cache library, bug #448858" X-Git-Tag: v2.2.0_alpha150 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=8451f343034831bfc8dd06dd55fbce40b320882c;p=portage.git Revert "_ctypes: don't cache library, bug #448858" This reverts commit 9e37cca4f54260bd8c45a3041fcee00938c71649. As noted in bug #448858, comment #14, dlclose is not called automatically, so we may as well cache our library handles. In order to protect ourselves, we use a fork since commit 7ebb2f54877edb28621c33e380f8777b1b1dc201. --- diff --git a/pym/portage/util/_ctypes.py b/pym/portage/util/_ctypes.py index f419b1926..4e5aa2a6b 100644 --- a/pym/portage/util/_ctypes.py +++ b/pym/portage/util/_ctypes.py @@ -31,15 +31,17 @@ def find_library(name): return None return filename +_library_handles = {} + def LoadLibrary(name): """ Calls ctypes.cdll.LoadLibrary(name) if the ctypes module is available, - and otherwise returns None. Results are not cached, since that can - cause problems when libraries are updated (see bug #448858). + and otherwise returns None. Results are cached for future invocations. """ - handle = None + handle = _library_handles.get(name) - if ctypes is not None: + if handle is None and ctypes is not None: handle = ctypes.cdll.LoadLibrary(name) + _library_handles[name] = handle return handle