[pypy-commit] pypy default: fix for MSVC by allowing additional code in init function (like cpyext/test/foo3.c)
mattip
noreply at buildbot.pypy.org
Wed Jun 18 23:48:36 CEST 2014
Author: mattip <matti.picus at gmail.com>
Branch:
Changeset: r72100:6b9f7c1857b7
Date: 2014-06-18 22:07 +0300
http://bitbucket.org/pypy/pypy/changeset/6b9f7c1857b7/
Log: fix for MSVC by allowing additional code in init function (like
cpyext/test/foo3.c)
diff --git a/pypy/module/cpyext/test/test_cpyext.py b/pypy/module/cpyext/test/test_cpyext.py
--- a/pypy/module/cpyext/test/test_cpyext.py
+++ b/pypy/module/cpyext/test/test_cpyext.py
@@ -301,9 +301,9 @@
space.sys.get('modules'),
space.wrap(name))
- @unwrap_spec(modname=str, prologue=str, PY_SSIZE_T_CLEAN=bool)
+ @unwrap_spec(modname=str, prologue=str, more_init=str, PY_SSIZE_T_CLEAN=bool)
def import_extension(space, modname, w_functions, prologue="",
- PY_SSIZE_T_CLEAN=False):
+ more_init="", PY_SSIZE_T_CLEAN=False):
functions = space.unwrap(w_functions)
methods_table = []
codes = []
@@ -326,6 +326,8 @@
};
""" % ('\n'.join(methods_table),)
init = """Py_InitModule("%s", methods);""" % (modname,)
+ if more_init:
+ init += more_init
return import_module(space, name=modname, init=init, body=body,
PY_SSIZE_T_CLEAN=PY_SSIZE_T_CLEAN)
diff --git a/pypy/module/cpyext/test/test_intobject.py b/pypy/module/cpyext/test/test_intobject.py
--- a/pypy/module/cpyext/test/test_intobject.py
+++ b/pypy/module/cpyext/test/test_intobject.py
@@ -150,7 +150,7 @@
/*tp_methods*/ 0,
/*tp_members*/ enum_members,
/*tp_getset*/ 0,
- /*tp_base*/ &PyInt_Type,
+ /*tp_base*/ 0, /* set to &PyInt_Type in init function for MSVC */
/*tp_dict*/ 0,
/*tp_descr_get*/ 0,
/*tp_descr_set*/ 0,
@@ -159,7 +159,9 @@
/*tp_alloc*/ 0,
/*tp_new*/ 0
};
- """)
+ """, more_init = '''
+ Enum_Type.tp_base = &PyInt_Type;
+ ''')
a = module.newEnum("ULTIMATE_ANSWER", 42)
assert type(a).__name__ == "Enum"
@@ -173,12 +175,13 @@
("test_int", "METH_NOARGS",
"""
PyObject * obj = PyInt_FromLong(42);
+ PyObject * val;
if (!PyInt_Check(obj)) {
Py_DECREF(obj);
PyErr_SetNone(PyExc_ValueError);
return NULL;
}
- PyObject * val = PyInt_FromLong(((PyIntObject *)obj)->ob_ival);
+ val = PyInt_FromLong(((PyIntObject *)obj)->ob_ival);
Py_DECREF(obj);
return val;
"""
More information about the pypy-commit
mailing list