[pypy-commit] pypy multiphase: Add more tests; actually set the type name in PyType_FromSpec()
rlamy
pypy.commits at gmail.com
Thu Jun 15 11:03:34 EDT 2017
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: multiphase
Changeset: r91608:eb06701ddfd6
Date: 2017-06-15 16:02 +0100
http://bitbucket.org/pypy/pypy/changeset/eb06701ddfd6/
Log: Add more tests; actually set the type name in PyType_FromSpec()
diff --git a/pypy/module/cpyext/test/test_module.py b/pypy/module/cpyext/test/test_module.py
--- a/pypy/module/cpyext/test/test_module.py
+++ b/pypy/module/cpyext/test/test_module.py
@@ -158,4 +158,16 @@
ex.abc = 0
assert ex.abc == 0
assert module.foo(9, 9) == 18
+ assert isinstance(module.Str(), str)
+ assert module.Str(1) + '23' == '123'
+ raises(module.error, 'raise module.error()')
+ assert module.int_const == 1969
+ assert module.str_const == 'something different'
+ def test_reload(self):
+ import importlib
+ NAME = '_testmultiphase'
+ module = self.import_module(name=NAME)
+ ex_class = module.Example
+ importlib.reload(module)
+ assert ex_class is module.Example
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
@@ -903,15 +903,22 @@
PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases)""",
result_is_ll=True)
def PyType_FromSpecWithBases(space, spec, bases):
+ from pypy.module.cpyext.unicodeobject import PyUnicode_FromString
res = PyType_GenericAlloc(space, space.w_type, 0)
res = cts.cast('PyHeapTypeObject *', res)
typ = res.c_ht_type
typ.c_tp_flags = rffi.cast(lltype.Signed, spec.c_flags)
typ.c_tp_flags |= Py_TPFLAGS_HEAPTYPE
- #s = 'foo'
- #res.c_ht_name = PyUnicode_FromString(s)
- #res.c_ht_qualname = res.c_ht_name
- #incref(space, res.c_ht_qualname)
+ specname = rffi.charp2str(spec.c_name)
+ dotpos = specname.rfind('.')
+ if dotpos < 0:
+ name = specname
+ else:
+ name = specname[dotpos + 1:]
+ res.c_ht_name = make_ref(
+ space, PyUnicode_FromString(space, rffi.str2charp(name)))
+ res.c_ht_qualname = res.c_ht_name
+ incref(space, res.c_ht_qualname)
typ.c_tp_name = spec.c_name
slotdefs = rffi.cast(rffi.CArrayPtr(cts.gettype('PyType_Slot')), spec.c_slots)
if not bases:
More information about the pypy-commit
mailing list