Author: Ronan Lamy <[email protected]>
Branch: cpyext-cleanup
Changeset: r89360:66f4e5e9c8f3
Date: 2017-01-04 13:48 +0000
http://bitbucket.org/pypy/pypy/changeset/66f4e5e9c8f3/
Log: Split StaticObjectBuilder into 2 subclasses: one for translation and
one for tests
diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py
--- a/pypy/module/cpyext/api.py
+++ b/pypy/module/cpyext/api.py
@@ -1101,7 +1101,7 @@
space.fromcache(State).install_dll(eci)
# populate static data
- builder = space.fromcache(StaticObjectBuilder)
+ builder = space.fromcache(State).builder = TestingObjBuilder()
for name, (typ, expr) in GLOBALS.iteritems():
from pypy.module import cpyext # for the eval() below
w_obj = eval(expr)
@@ -1138,7 +1138,7 @@
builder.prepare(py_obj, w_obj)
else:
assert False, "Unknown static object: %s %s" % (typ, name)
- builder.attach_all()
+ builder.attach_all(space)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
@@ -1156,9 +1156,8 @@
return modulename.new(ext='')
-class StaticObjectBuilder:
- def __init__(self, space):
- self.space = space
+class StaticObjectBuilder(object):
+ def __init__(self):
self.static_pyobjs = []
self.static_objs_w = []
self.cpyext_type_init = None
@@ -1174,13 +1173,12 @@
self.static_pyobjs.append(py_obj)
self.static_objs_w.append(w_obj)
- def attach_all(self):
+ def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_reference
#
- space = self.space
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
for i in range(len(static_objs_w)):
@@ -1201,6 +1199,12 @@
finish_type_1(space, pto)
finish_type_2(space, pto, w_type)
+class TestingObjBuilder(StaticObjectBuilder):
+ """The StaticObjectBuilder used in tests."""
+
+class TranslationObjBuilder(StaticObjectBuilder):
+ """The StaticObjectBuilder used during translation."""
+
def mangle_name(prefix, name):
if name.startswith('Py'):
@@ -1416,7 +1420,7 @@
setup_va_functions(eci)
# emit uninitialized static data
- builder = space.fromcache(StaticObjectBuilder)
+ builder = space.fromcache(State).builder = TranslationObjBuilder()
lines = ['PyObject *pypy_static_pyobjs[] = {\n']
include_lines = ['RPY_EXTERN PyObject *pypy_static_pyobjs[];\n']
for name, (typ, expr) in sorted(GLOBALS.items()):
@@ -1463,9 +1467,6 @@
trunk_include = pypydir.dirpath() / 'include'
copy_header_files(trunk_include, use_micronumpy)
-def init_static_data_translated(space):
- builder = space.fromcache(StaticObjectBuilder)
- builder.attach_all()
def _load_from_cffi(space, name, path, initptr):
from pypy.module._cffi_backend import cffi1_module
diff --git a/pypy/module/cpyext/state.py b/pypy/module/cpyext/state.py
--- a/pypy/module/cpyext/state.py
+++ b/pypy/module/cpyext/state.py
@@ -14,6 +14,7 @@
self.reset()
self.programname = lltype.nullptr(rffi.CCHARP.TO)
self.version = lltype.nullptr(rffi.CCHARP.TO)
+ self.builder = None
if space.config.translation.gc != "boehm":
pyobj_dealloc_action = PyObjDeallocAction(space)
self.dealloc_trigger = lambda: pyobj_dealloc_action.fire()
@@ -84,17 +85,15 @@
def startup(self, space):
"This function is called when the program really starts"
-
from pypy.module.cpyext.typeobject import setup_new_method_def
from pypy.module.cpyext.api import INIT_FUNCTIONS
- from pypy.module.cpyext.api import init_static_data_translated
if we_are_translated():
if space.config.translation.gc != "boehm":
rawrefcount.init(
llhelper(rawrefcount.RAWREFCOUNT_DEALLOC_TRIGGER,
self.dealloc_trigger))
- init_static_data_translated(space)
+ self.builder.attach_all(space)
setup_new_method_def(space)
diff --git a/pypy/module/cpyext/typeobject.py b/pypy/module/cpyext/typeobject.py
--- a/pypy/module/cpyext/typeobject.py
+++ b/pypy/module/cpyext/typeobject.py
@@ -87,7 +87,7 @@
py_getsetdef.c_set = rffi.cast(setter, 0)
py_getsetdef.c_closure = rffi.cast(rffi.VOIDP, 0)
return py_getsetdef
-
+
class W_MemberDescr(GetSetProperty):
name = 'member_descriptor'
@@ -711,7 +711,7 @@
pto.c_tp_free = llslot(space, PyObject_Free)
pto.c_tp_alloc = llslot(space, PyType_GenericAlloc)
- builder = space.fromcache(StaticObjectBuilder)
+ builder = space.fromcache(State).builder
if ((pto.c_tp_flags & Py_TPFLAGS_HEAPTYPE) != 0
and builder.cpyext_type_init is None):
# this ^^^ is not None only during startup of cpyext. At that
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit