summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2011-03-26 22:56:28 (GMT)
committerBenjamin Peterson <benjamin@python.org>2011-03-26 22:56:28 (GMT)
commit8d6c62dd892de77295e9db7b1c56fec041726afb (patch)
tree95c6866844be8485c210b2f456747e759e551d28 /Lib
parentb8a5769a6d35931f4dc5395686f590b5dcb58cdd (diff)
downloadcpython-8d6c62dd892de77295e9db7b1c56fec041726afb.zip
cpython-8d6c62dd892de77295e9db7b1c56fec041726afb.tar.gz
cpython-8d6c62dd892de77295e9db7b1c56fec041726afb.tar.bz2
check possible recursive _as_parameter_ to prevent segfault (closes #1838)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/ctypes/test/test_as_parameter.py12
-rw-r--r--Lib/lib2to3/refactor.py2
-rw-r--r--Lib/lib2to3/tests/test_refactor.py17
3 files changed, 30 insertions, 1 deletions
diff --git a/Lib/ctypes/test/test_as_parameter.py b/Lib/ctypes/test/test_as_parameter.py
index 835398f..475d595 100644
--- a/Lib/ctypes/test/test_as_parameter.py
+++ b/Lib/ctypes/test/test_as_parameter.py
@@ -187,6 +187,18 @@ class BasicWrapTestCase(unittest.TestCase):
self.assertEqual((s8i.a, s8i.b, s8i.c, s8i.d, s8i.e, s8i.f, s8i.g, s8i.h),
(9*2, 8*3, 7*4, 6*5, 5*6, 4*7, 3*8, 2*9))
+ def test_recursive_as_param(self):
+ from ctypes import c_int
+
+ class A(object):
+ pass
+
+ a = A()
+ a._as_parameter_ = a
+ with self.assertRaises(RuntimeError):
+ c_int.from_param(a)
+
+
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class AsParamWrapper(object):
diff --git a/Lib/lib2to3/refactor.py b/Lib/lib2to3/refactor.py
index ae5e40f..ca07be6 100644
--- a/Lib/lib2to3/refactor.py
+++ b/Lib/lib2to3/refactor.py
@@ -500,7 +500,7 @@ class RefactoringTool(object):
node = new
def processed_file(self, new_text, filename, old_text=None, write=False,
- encoding=None):
+ encoding=None, newlines=None):
"""
Called when a file has been refactored, and there are changes.
"""
diff --git a/Lib/lib2to3/tests/test_refactor.py b/Lib/lib2to3/tests/test_refactor.py
index 73122d8..b6d5b57 100644
--- a/Lib/lib2to3/tests/test_refactor.py
+++ b/Lib/lib2to3/tests/test_refactor.py
@@ -231,6 +231,23 @@ from __future__ import print_function"""
os.path.join("a_dir", "stuff.py")]
check(tree, tree)
+ def test_preserve_file_newlines(self):
+ rt = self.rt(fixers=_2TO3_FIXERS)
+ for nl in ("\r\n", "\n"):
+ data = "print y%s%syes%sok%s" % ((nl,) * 4)
+ handle, tmp = tempfile.mkstemp()
+ os.close(handle)
+ try:
+ with open(tmp, "w") as fp:
+ fp.write(data)
+ rt.refactor_file(tmp)
+ with open(tmp, "r") as fp:
+ contents = fp.read()
+ finally:
+ os.unlink(tmp)
+ for line in contents.splitlines(True):
+ self.assertTrue(line.endswith(nl))
+
def test_file_encoding(self):
fn = os.path.join(TEST_DATA_DIR, "different_encoding.py")
self.check_file_refactoring(fn)