Commit 17903837 authored by Guido van Rossum's avatar Guido van Rossum

Explicitly close pipes so test_ctypes won't appear to randomly leak

+33 or -33 references.  (See discussion in #1597.)
parent b9d706fb
...@@ -50,8 +50,10 @@ elif os.name == "posix": ...@@ -50,8 +50,10 @@ elif os.name == "posix":
'$CC -Wl,-t -o ' + ccout + ' 2>&1 -l' + name '$CC -Wl,-t -o ' + ccout + ' 2>&1 -l' + name
try: try:
f = os.popen(cmd) f = os.popen(cmd)
trace = f.read() try:
f.close() trace = f.read()
finally:
f.close()
finally: finally:
try: try:
os.unlink(ccout) os.unlink(ccout)
...@@ -70,7 +72,12 @@ elif os.name == "posix": ...@@ -70,7 +72,12 @@ elif os.name == "posix":
if not f: if not f:
return None return None
cmd = "/usr/ccs/bin/dump -Lpv 2>/dev/null " + f 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: if not res:
return None return None
return res.group(1) return res.group(1)
...@@ -80,7 +87,12 @@ elif os.name == "posix": ...@@ -80,7 +87,12 @@ elif os.name == "posix":
if not f: if not f:
return None return None
cmd = "objdump -p -j .dynamic 2>/dev/null " + f cmd = "objdump -p -j .dynamic 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: if not res:
return None return None
return res.group(1) return res.group(1)
...@@ -103,8 +115,12 @@ elif os.name == "posix": ...@@ -103,8 +115,12 @@ elif os.name == "posix":
def find_library(name): def find_library(name):
ename = re.escape(name) ename = re.escape(name)
expr = r':-l%s\.\S+ => \S*/(lib%s\.\S+)' % (ename, ename) expr = r':-l%s\.\S+ => \S*/(lib%s\.\S+)' % (ename, ename)
res = re.findall(expr, f = os.popen('/sbin/ldconfig -r 2>/dev/null')
os.popen('/sbin/ldconfig -r 2>/dev/null').read()) try:
data = f.read()
finally:
f.close()
res = re.findall(expr, data)
if not res: if not res:
return _get_soname(_findLib_gcc(name)) return _get_soname(_findLib_gcc(name))
res.sort(cmp= lambda x,y: cmp(_num_version(x), _num_version(y))) res.sort(cmp= lambda x,y: cmp(_num_version(x), _num_version(y)))
...@@ -115,12 +131,21 @@ elif os.name == "posix": ...@@ -115,12 +131,21 @@ elif os.name == "posix":
def _findLib_ldconfig(name): def _findLib_ldconfig(name):
# XXX assuming GLIBC's ldconfig (with option -p) # XXX assuming GLIBC's ldconfig (with option -p)
expr = r'/[^\(\)\s]*lib%s\.[^\(\)\s]*' % re.escape(name) expr = r'/[^\(\)\s]*lib%s\.[^\(\)\s]*' % re.escape(name)
res = re.search(expr, f = os.popen('/sbin/ldconfig -p 2>/dev/null')
os.popen('/sbin/ldconfig -p 2>/dev/null').read()) try:
data = f.read()
finally:
f.close()
res = re.search(expr, data)
if not res: if not res:
# Hm, this works only for libs needed by the python executable. # Hm, this works only for libs needed by the python executable.
cmd = 'ldd %s 2>/dev/null' % sys.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: if not res:
return None return None
return res.group(0) return res.group(0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment