summaryrefslogtreecommitdiffstats
path: root/Lib/ctypes/util.py
diff options
context:
space:
mode:
authorEric Smith <eric@trueblade.com>2009-10-22 20:13:14 (GMT)
committerEric Smith <eric@trueblade.com>2009-10-22 20:13:14 (GMT)
commit84da0905e4c484f84e3572305e1e7ab58f72c141 (patch)
tree5e9013f87d1a4955807463f442f95d4b0c09ce26 /Lib/ctypes/util.py
parent60bae6f12343e61582435aeb8ec182fd310cd720 (diff)
downloadcpython-84da0905e4c484f84e3572305e1e7ab58f72c141.zip
cpython-84da0905e4c484f84e3572305e1e7ab58f72c141.tar.gz
cpython-84da0905e4c484f84e3572305e1e7ab58f72c141.tar.bz2
Per the discussion in issue6882, backport the try/finally work that was done to the py3k version (mostly in r59477, I think).
Diffstat (limited to 'Lib/ctypes/util.py')
-rw-r--r--Lib/ctypes/util.py51
1 files changed, 40 insertions, 11 deletions
diff --git a/Lib/ctypes/util.py b/Lib/ctypes/util.py
index 35b0b1e..8f6e338 100644
--- a/Lib/ctypes/util.py
+++ b/Lib/ctypes/util.py
@@ -96,8 +96,10 @@ elif os.name == "posix":
'$CC -Wl,-t -o ' + ccout + ' 2>&1 -l' + name
try:
f = os.popen(cmd)
- trace = f.read()
- rv = f.close()
+ try:
+ trace = f.read()
+ finally:
+ rv = f.close()
finally:
try:
os.unlink(ccout)
@@ -118,7 +120,12 @@ elif os.name == "posix":
if not f:
return None
cmd = "/usr/ccs/bin/dump -Lpv 2>/dev/null " + f
- res = re.search(r'\[.*\]\sSONAME\s+([^\s]+)', os.popen(cmd).read())
+ f = os.popen(cmd)
+ try:
+ data = f.read()
+ finally:
+ f.close()
+ res = re.search(r'\[.*\]\sSONAME\s+([^\s]+)', data)
if not res:
return None
return res.group(1)
@@ -134,7 +141,12 @@ elif os.name == "posix":
rv = f.close()
if rv == 10:
raise OSError, 'objdump command not found'
- res = re.search(r'\sSONAME\s+([^\s]+)', os.popen(cmd).read())
+ f = os.popen(cmd)
+ try:
+ data = f.read()
+ finally:
+ f.close()
+ res = re.search(r'\sSONAME\s+([^\s]+)', data)
if not res:
return None
return res.group(1)
@@ -157,8 +169,12 @@ elif os.name == "posix":
def find_library(name):
ename = re.escape(name)
expr = r':-l%s\.\S+ => \S*/(lib%s\.\S+)' % (ename, ename)
- res = re.findall(expr,
- os.popen('/sbin/ldconfig -r 2>/dev/null').read())
+ f = os.popen('/sbin/ldconfig -r 2>/dev/null')
+ try:
+ data = f.read()
+ finally:
+ f.close()
+ res = re.findall(expr, data)
if not res:
return _get_soname(_findLib_gcc(name))
res.sort(cmp= lambda x,y: cmp(_num_version(x), _num_version(y)))
@@ -169,12 +185,21 @@ elif os.name == "posix":
def _findLib_ldconfig(name):
# XXX assuming GLIBC's ldconfig (with option -p)
expr = r'/[^\(\)\s]*lib%s\.[^\(\)\s]*' % re.escape(name)
- res = re.search(expr,
- os.popen('/sbin/ldconfig -p 2>/dev/null').read())
+ f = os.popen('/sbin/ldconfig -p 2>/dev/null')
+ try:
+ data = f.read()
+ finally:
+ f.close()
+ res = re.search(expr, data)
if not res:
# Hm, this works only for libs needed by the python executable.
cmd = 'ldd %s 2>/dev/null' % sys.executable
- res = re.search(expr, os.popen(cmd).read())
+ f = os.popen(cmd)
+ try:
+ data = f.read()
+ finally:
+ f.close()
+ res = re.search(expr, data)
if not res:
return None
return res.group(0)
@@ -197,8 +222,12 @@ elif os.name == "posix":
# XXX assuming GLIBC's ldconfig (with option -p)
expr = r'(\S+)\s+\((%s(?:, OS ABI:[^\)]*)?)\)[^/]*(/[^\(\)\s]*lib%s\.[^\(\)\s]*)' \
% (abi_type, re.escape(name))
- res = re.search(expr,
- os.popen('/sbin/ldconfig -p 2>/dev/null').read())
+ f = os.popen('/sbin/ldconfig -p 2>/dev/null')
+ try:
+ data = f.read()
+ finally:
+ f.close()
+ res = re.search(expr, data)
if not res:
return None
return res.group(1)