From 8451f343034831bfc8dd06dd55fbce40b320882c Mon Sep 17 00:00:00 2001
From: Zac Medico <zmedico@gentoo.org>
Date: Thu, 10 Jan 2013 06:41:15 -0800
Subject: [PATCH] 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.
---
 pym/portage/util/_ctypes.py | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

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
-- 
2.26.2