From e9365c606a134c4ea96986066d4f9df26d2af896 Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Fri, 20 Nov 2009 14:15:30 -0500 Subject: Move .cocci files and typeobject.py into a new "fixes" subdirectory --- 2to3c | 2 +- RO.cocci | 5 --- fixes/RO.cocci | 5 +++ fixes/__init__.py | 0 fixes/int-to-long.cocci | 82 +++++++++++++++++++++++++++++++++++++++++++++++++ fixes/ob_type.cocci | 27 ++++++++++++++++ fixes/repr.cocci | 27 ++++++++++++++++ fixes/typeobject.py | 66 +++++++++++++++++++++++++++++++++++++++ int-to-long.cocci | 82 ------------------------------------------------- ob_type.cocci | 27 ---------------- repr.cocci | 27 ---------------- typeobject.py | 66 --------------------------------------- 12 files changed, 208 insertions(+), 208 deletions(-) delete mode 100644 RO.cocci create mode 100644 fixes/RO.cocci create mode 100644 fixes/__init__.py create mode 100644 fixes/int-to-long.cocci create mode 100644 fixes/ob_type.cocci create mode 100644 fixes/repr.cocci create mode 100644 fixes/typeobject.py delete mode 100644 int-to-long.cocci delete mode 100644 ob_type.cocci delete mode 100644 repr.cocci delete mode 100644 typeobject.py diff --git a/2to3c b/2to3c index c31d991..c6c96d7 100755 --- a/2to3c +++ b/2to3c @@ -1,7 +1,7 @@ #!/usr/bin/env python def get_fixers(): - from typeobject import fixup_typeobject_initializers + from fixes.typeobject import fixup_typeobject_initializers return [fixup_typeobject_initializers] def fixup_content(content): diff --git a/RO.cocci b/RO.cocci deleted file mode 100644 index 14e0229..0000000 --- a/RO.cocci +++ /dev/null @@ -1,5 +0,0 @@ -// structmember.h lost the #define alias RO for READONLY; replace accordingly: -@@ -@@ --RO -+READONLY \ No newline at end of file diff --git a/fixes/RO.cocci b/fixes/RO.cocci new file mode 100644 index 0000000..14e0229 --- /dev/null +++ b/fixes/RO.cocci @@ -0,0 +1,5 @@ +// structmember.h lost the #define alias RO for READONLY; replace accordingly: +@@ +@@ +-RO ++READONLY \ No newline at end of file diff --git a/fixes/__init__.py b/fixes/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/fixes/int-to-long.cocci b/fixes/int-to-long.cocci new file mode 100644 index 0000000..110d97d --- /dev/null +++ b/fixes/int-to-long.cocci @@ -0,0 +1,82 @@ +@@ +expression E1; +@@ +-PyInt_AsLong(E1) ++PyLong_AsLong(E1) + +@@ +expression E1; +@@ +-PyInt_Check(E1) ++PyLong_Check(E1) + +@@ +expression E1, E2, E3; +@@ +-PyInt_FromString(E1, E2, E3) ++PyLong_FromString(E1, E2, E3) + +@@ +expression E1, E2, E3; +@@ +-PyInt_FromUnicode(E1, E2, E3) ++PyLong_FromUnicode(E1, E2, E3) + +@@ +expression E1; +@@ +-PyInt_FromLong(E1) ++PyLong_FromLong(E1) + +@@ +expression E1; +@@ +-PyInt_FromSize_t(E1) ++PyLong_FromSize_t(E1) + +@@ +expression E1; +@@ +-PyInt_FromSsize_t(E1) ++PyLong_FromSsize_t(E1) + +@@ +expression E1; +@@ +-PyInt_AsLong(E1) ++PyLong_AsLong(E1) + +@@ +expression E1; +@@ +-PyInt_AsSsize_t(E1) ++PyLong_AsSsize_t(E1) + +@@ +expression E1; +@@ +-PyInt_AsUnsignedLongMask(E1) ++PyLong_AsUnsignedLongMask(E1) + +@@ +expression E1; +@@ +-PyInt_AsUnsignedLongLongMask(E1) ++PyLong_AsUnsignedLongLongMask(E1) + +@@ +expression E1; +@@ +-PyInt_AS_LONG(E1) ++PyLong_AS_LONG(E1) + +@@ +expression E1; +@@ +-PyNumber_Int(E1) ++PyNumber_Long(E1) + +@@ +@@ +-PyInt_Type ++PyLong_Type \ No newline at end of file diff --git a/fixes/ob_type.cocci b/fixes/ob_type.cocci new file mode 100644 index 0000000..daf6d96 --- /dev/null +++ b/fixes/ob_type.cocci @@ -0,0 +1,27 @@ +// Convert non-PyObject* deferences of "ob_type" to use Py_TYPE macro instead +@@ +PyObject *py_obj_ptr; +type T; +T non_py_obj_ptr; +@@ +( + py_obj_ptr->ob_type +| +- non_py_obj_ptr->ob_type ++ Py_TYPE(non_py_obj_ptr) +) + +@@ +identifier F; // FIXME: must be an initial field of a struct +type T; +T non_py_obj_ptr; +@@ +- non_py_obj_ptr->F.ob_type ++ Py_TYPE(non_py_obj_ptr) + +@@ +PyTypeObject typeobj; +@@ +- typeobj.ob_type ++ Py_TYPE(&typeobj) + diff --git a/fixes/repr.cocci b/fixes/repr.cocci new file mode 100644 index 0000000..dfa1ef4 --- /dev/null +++ b/fixes/repr.cocci @@ -0,0 +1,27 @@ +// tp_repr functions should return unicode in py3k +// FIXME: need to restrict to just tp_repr functions: +@@ +type T; +function FN_repr; +expression E; +@@ +PyObject * +FN_repr(T *self) +{ + ... +- return PyString_FromString(E); ++ return PyUnicode_FromString(E); +} + +@@ +type T; +function FN_repr; +expression E1, E2; +@@ +PyObject * +FN_repr(T *self) +{ + ... +- return PyString_FromFormat(E1, E2); ++ return PyUnicode_FromFormat(E1, E2); +} diff --git a/fixes/typeobject.py b/fixes/typeobject.py new file mode 100644 index 0000000..1710a74 --- /dev/null +++ b/fixes/typeobject.py @@ -0,0 +1,66 @@ +import sys +import re +from difflib import unified_diff + +# Whitespace patterns: +req_ws = r'\s+' +opt_ws = r'\s*' +c_identifier = r'([_A-Za-z][_0-9A-Za-z]*)' + +pat = ('.*' + r'PyTypeObject' + req_ws + + c_identifier + opt_ws + + r'=' + opt_ws + r'\{' + opt_ws + + r'(PyObject_HEAD_INIT\((.*)\)' + opt_ws + + r'([0-9]+)' + opt_ws + r',).*' + ) + +def fixup_typeobject_initializers(content): + while True: + m = re.match(pat, content, re.DOTALL) + if m: + if False: + print m.groups() + print m.group(2) + print m.group(3) + print m.group(4) + print m.span(2) + content = (content[:m.start(2)] + + 'PyVarObject_HEAD_INIT(%s, %s)' % (m.group(3),m.group(4)) + + content[m.end(2):]) + else: + return content + +import unittest +class TestFixups(unittest.TestCase): + def test_fixups(self): + self.assertEquals(fixup_typeobject_initializers(''' +PyTypeObject DBusPyIntBase_Type = { + PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) + 0, + "_dbus_bindings._IntBase", +''' + ), + ''' +PyTypeObject DBusPyIntBase_Type = { + PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0) + "_dbus_bindings._IntBase", +''' + ) + + +def fixup_file(filename, options): + content = open(filename, 'r').read() + fixed_content = fixup_typeobject_initializers(content) + if content != fixed_content: + for line in unified_diff(content.splitlines(), + fixed_content.splitlines(), + fromfile = filename+'.orig', + tofile = filename, + lineterm=''): + print line + + if options.write: + open(filename, 'w').write(fixed_content) + +if __name__ == '__main__': + unittest.main() diff --git a/int-to-long.cocci b/int-to-long.cocci deleted file mode 100644 index 110d97d..0000000 --- a/int-to-long.cocci +++ /dev/null @@ -1,82 +0,0 @@ -@@ -expression E1; -@@ --PyInt_AsLong(E1) -+PyLong_AsLong(E1) - -@@ -expression E1; -@@ --PyInt_Check(E1) -+PyLong_Check(E1) - -@@ -expression E1, E2, E3; -@@ --PyInt_FromString(E1, E2, E3) -+PyLong_FromString(E1, E2, E3) - -@@ -expression E1, E2, E3; -@@ --PyInt_FromUnicode(E1, E2, E3) -+PyLong_FromUnicode(E1, E2, E3) - -@@ -expression E1; -@@ --PyInt_FromLong(E1) -+PyLong_FromLong(E1) - -@@ -expression E1; -@@ --PyInt_FromSize_t(E1) -+PyLong_FromSize_t(E1) - -@@ -expression E1; -@@ --PyInt_FromSsize_t(E1) -+PyLong_FromSsize_t(E1) - -@@ -expression E1; -@@ --PyInt_AsLong(E1) -+PyLong_AsLong(E1) - -@@ -expression E1; -@@ --PyInt_AsSsize_t(E1) -+PyLong_AsSsize_t(E1) - -@@ -expression E1; -@@ --PyInt_AsUnsignedLongMask(E1) -+PyLong_AsUnsignedLongMask(E1) - -@@ -expression E1; -@@ --PyInt_AsUnsignedLongLongMask(E1) -+PyLong_AsUnsignedLongLongMask(E1) - -@@ -expression E1; -@@ --PyInt_AS_LONG(E1) -+PyLong_AS_LONG(E1) - -@@ -expression E1; -@@ --PyNumber_Int(E1) -+PyNumber_Long(E1) - -@@ -@@ --PyInt_Type -+PyLong_Type \ No newline at end of file diff --git a/ob_type.cocci b/ob_type.cocci deleted file mode 100644 index daf6d96..0000000 --- a/ob_type.cocci +++ /dev/null @@ -1,27 +0,0 @@ -// Convert non-PyObject* deferences of "ob_type" to use Py_TYPE macro instead -@@ -PyObject *py_obj_ptr; -type T; -T non_py_obj_ptr; -@@ -( - py_obj_ptr->ob_type -| -- non_py_obj_ptr->ob_type -+ Py_TYPE(non_py_obj_ptr) -) - -@@ -identifier F; // FIXME: must be an initial field of a struct -type T; -T non_py_obj_ptr; -@@ -- non_py_obj_ptr->F.ob_type -+ Py_TYPE(non_py_obj_ptr) - -@@ -PyTypeObject typeobj; -@@ -- typeobj.ob_type -+ Py_TYPE(&typeobj) - diff --git a/repr.cocci b/repr.cocci deleted file mode 100644 index dfa1ef4..0000000 --- a/repr.cocci +++ /dev/null @@ -1,27 +0,0 @@ -// tp_repr functions should return unicode in py3k -// FIXME: need to restrict to just tp_repr functions: -@@ -type T; -function FN_repr; -expression E; -@@ -PyObject * -FN_repr(T *self) -{ - ... -- return PyString_FromString(E); -+ return PyUnicode_FromString(E); -} - -@@ -type T; -function FN_repr; -expression E1, E2; -@@ -PyObject * -FN_repr(T *self) -{ - ... -- return PyString_FromFormat(E1, E2); -+ return PyUnicode_FromFormat(E1, E2); -} diff --git a/typeobject.py b/typeobject.py deleted file mode 100644 index 1710a74..0000000 --- a/typeobject.py +++ /dev/null @@ -1,66 +0,0 @@ -import sys -import re -from difflib import unified_diff - -# Whitespace patterns: -req_ws = r'\s+' -opt_ws = r'\s*' -c_identifier = r'([_A-Za-z][_0-9A-Za-z]*)' - -pat = ('.*' + r'PyTypeObject' + req_ws - + c_identifier + opt_ws - + r'=' + opt_ws + r'\{' + opt_ws - + r'(PyObject_HEAD_INIT\((.*)\)' + opt_ws - + r'([0-9]+)' + opt_ws + r',).*' - ) - -def fixup_typeobject_initializers(content): - while True: - m = re.match(pat, content, re.DOTALL) - if m: - if False: - print m.groups() - print m.group(2) - print m.group(3) - print m.group(4) - print m.span(2) - content = (content[:m.start(2)] - + 'PyVarObject_HEAD_INIT(%s, %s)' % (m.group(3),m.group(4)) - + content[m.end(2):]) - else: - return content - -import unittest -class TestFixups(unittest.TestCase): - def test_fixups(self): - self.assertEquals(fixup_typeobject_initializers(''' -PyTypeObject DBusPyIntBase_Type = { - PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) - 0, - "_dbus_bindings._IntBase", -''' - ), - ''' -PyTypeObject DBusPyIntBase_Type = { - PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0) - "_dbus_bindings._IntBase", -''' - ) - - -def fixup_file(filename, options): - content = open(filename, 'r').read() - fixed_content = fixup_typeobject_initializers(content) - if content != fixed_content: - for line in unified_diff(content.splitlines(), - fixed_content.splitlines(), - fromfile = filename+'.orig', - tofile = filename, - lineterm=''): - print line - - if options.write: - open(filename, 'w').write(fixed_content) - -if __name__ == '__main__': - unittest.main() -- cgit