diff options
-rw-r--r-- | lib-python/3/sysconfig.py | 4 | ||||
-rw-r--r-- | pypy/module/cpyext/api.py | 1 | ||||
-rw-r--r-- | pypy/module/cpyext/include/modsupport.h | 2 | ||||
-rw-r--r-- | pypy/module/cpyext/modsupport.py | 10 | ||||
-rw-r--r-- | pypy/module/cpyext/parse/cpyext_moduleobject.h | 6 | ||||
-rw-r--r-- | pypy/module/cpyext/src/modsupport.c | 10 | ||||
-rw-r--r-- | pypy/module/cpyext/test/test_module.py | 17 | ||||
-rw-r--r-- | pypy/module/thread/os_local.py | 13 | ||||
-rw-r--r-- | pypy/module/thread/test/test_local.py | 13 |
9 files changed, 67 insertions, 9 deletions
diff --git a/lib-python/3/sysconfig.py b/lib-python/3/sysconfig.py index 6701b96875..efe9c827d0 100644 --- a/lib-python/3/sysconfig.py +++ b/lib-python/3/sysconfig.py @@ -44,8 +44,8 @@ _INSTALL_SCHEMES = { 'pypy': { 'stdlib': '{installed_base}/lib-python', 'platstdlib': '{base}/lib-python', - 'purelib': '{base}/lib-python', - 'platlib': '{base}/lib-python', + 'purelib': '{base}/site-packages', + 'platlib': '{base}/site-packages', 'include': '{installed_base}/include', 'platinclude': '{installed_base}/include', 'scripts': '{base}/bin', diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py index c1daea4111..790805b5e4 100644 --- a/pypy/module/cpyext/api.py +++ b/pypy/module/cpyext/api.py @@ -565,6 +565,7 @@ SYMBOLS_C = [ 'PyUnicode_FromFormat', 'PyUnicode_FromFormatV', 'PyUnicode_AsWideCharString', 'PyUnicode_GetSize', 'PyUnicode_GetLength', 'PyModule_AddObject', 'PyModule_AddIntConstant', 'PyModule_AddStringConstant', + 'PyModule_GetDef', 'Py_BuildValue', 'Py_VaBuildValue', 'PyTuple_Pack', '_PyArg_Parse_SizeT', '_PyArg_ParseTuple_SizeT', '_PyArg_ParseTupleAndKeywords_SizeT', '_PyArg_VaParse_SizeT', diff --git a/pypy/module/cpyext/include/modsupport.h b/pypy/module/cpyext/include/modsupport.h index 1b08e2cd82..677d90f142 100644 --- a/pypy/module/cpyext/include/modsupport.h +++ b/pypy/module/cpyext/include/modsupport.h @@ -70,6 +70,8 @@ PyAPI_FUNC(int) PyModule_AddStringConstant(PyObject *m, const char *name, const #define PyModule_AddIntMacro(m, c) PyModule_AddIntConstant(m, #c, c) #define PyModule_AddStringMacro(m, c) PyModule_AddStringConstant(m, #c, c) +PyAPI_FUNC(struct PyModuleDef*) PyModule_GetDef(PyObject*); + PyAPI_FUNC(PyObject *) Py_BuildValue(const char *, ...); PyAPI_FUNC(PyObject *) Py_VaBuildValue(const char *, va_list); diff --git a/pypy/module/cpyext/modsupport.py b/pypy/module/cpyext/modsupport.py index 5c9b27b361..06c12a4e74 100644 --- a/pypy/module/cpyext/modsupport.py +++ b/pypy/module/cpyext/modsupport.py @@ -1,8 +1,8 @@ from rpython.rtyper.lltypesystem import rffi, lltype from pypy.module.cpyext.api import ( cpython_api, METH_STATIC, METH_CLASS, METH_COEXIST, CANNOT_FAIL, cts, - parse_dir) -from pypy.module.cpyext.pyobject import PyObject, as_pyobj + parse_dir, bootstrap_function) +from pypy.module.cpyext.pyobject import PyObject, as_pyobj, make_typedescr from pypy.interpreter.module import Module from pypy.module.cpyext.methodobject import ( W_PyCFunctionObject, PyCFunction_NewEx, PyDescr_NewMethod, @@ -13,6 +13,11 @@ from pypy.interpreter.error import oefmt cts.parse_header(parse_dir / 'cpyext_moduleobject.h') PyModuleDef = cts.gettype('PyModuleDef *') +PyModuleObject = cts.gettype('PyModuleObject *') + +@bootstrap_function +def init_moduleobject(space): + make_typedescr(Module.typedef, basestruct=PyModuleObject.TO) @cpython_api([PyModuleDef, rffi.INT_real], PyObject) def PyModule_Create2(space, module, api_version): @@ -35,6 +40,7 @@ def PyModule_Create2(space, module, api_version): if f_name is not None: modname = f_name w_mod = Module(space, space.newtext(modname)) + rffi.cast(PyModuleObject, as_pyobj(space, w_mod)).c_md_def = module state.package_context = None, None if f_path is not None: diff --git a/pypy/module/cpyext/parse/cpyext_moduleobject.h b/pypy/module/cpyext/parse/cpyext_moduleobject.h index f0ec8b76b9..16384d02bb 100644 --- a/pypy/module/cpyext/parse/cpyext_moduleobject.h +++ b/pypy/module/cpyext/parse/cpyext_moduleobject.h @@ -36,3 +36,9 @@ typedef struct PyModuleDef{ inquiry m_clear; freefunc m_free; } PyModuleDef; + +typedef struct { + PyObject_HEAD + struct PyModuleDef *md_def; + //void *md_state; +} PyModuleObject; diff --git a/pypy/module/cpyext/src/modsupport.c b/pypy/module/cpyext/src/modsupport.c index 08884eab5b..fef6ccd577 100644 --- a/pypy/module/cpyext/src/modsupport.c +++ b/pypy/module/cpyext/src/modsupport.c @@ -592,3 +592,13 @@ PyModule_AddStringConstant(PyObject *m, const char *name, const char *value) Py_DECREF(o); return result < 0 ? -1 : 0; } + +PyModuleDef* +PyModule_GetDef(PyObject* m) +{ + if (!PyModule_Check(m)) { + PyErr_BadArgument(); + return NULL; + } + return ((PyModuleObject *)m)->md_def; +} diff --git a/pypy/module/cpyext/test/test_module.py b/pypy/module/cpyext/test/test_module.py index 39df39936b..a88a0c2f33 100644 --- a/pypy/module/cpyext/test/test_module.py +++ b/pypy/module/cpyext/test/test_module.py @@ -1,4 +1,5 @@ from pypy.module.cpyext.test.test_api import BaseApiTest +from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase from rpython.rtyper.lltypesystem import rffi @@ -10,3 +11,19 @@ class TestModuleObject(BaseApiTest): p2 = api.PyModule_GetName(w_sys) assert p2 == p self.raises(space, api, SystemError, api.PyModule_GetName, space.w_True) + + +class AppTestModuleObject(AppTestCpythonExtensionBase): + def test_getdef(self): + module = self.import_extension('foo', [ + ("check_getdef_same", "METH_NOARGS", + """ + return PyBool_FromLong(PyModule_GetDef(mod_global) == &moduledef); + """ + )], prologue=""" + static struct PyModuleDef moduledef; + static PyObject *mod_global; + """, more_init=""" + mod_global = mod; + """) + assert module.check_getdef_same() diff --git a/pypy/module/thread/os_local.py b/pypy/module/thread/os_local.py index 4f5324fa34..f3c9ecad1d 100644 --- a/pypy/module/thread/os_local.py +++ b/pypy/module/thread/os_local.py @@ -1,6 +1,7 @@ import weakref from rpython.rlib import jit from pypy.interpreter.baseobjspace import W_Root +from pypy.interpreter.error import oefmt from pypy.interpreter.executioncontext import ExecutionContext from pypy.interpreter.typedef import (TypeDef, interp2app, GetSetProperty, descr_get_dict) @@ -75,18 +76,20 @@ class Local(W_Root): return w_dict def descr_local__new__(space, w_subtype, __args__): + from pypy.objspace.std.typeobject import _precheck_for_new + w_subtype = _precheck_for_new(space, w_subtype) + if __args__.arguments_w or __args__.keywords: + w_parent_init, _ = space.lookup_in_type_where(w_subtype, '__init__') + if w_parent_init is space.w_object: + raise oefmt(space.w_TypeError, + "Initialization arguments are not supported") local = space.allocate_instance(Local, w_subtype) Local.__init__(local, space, __args__) return local - def descr_local__init__(self, space): - # No arguments allowed - pass - Local.typedef = TypeDef("thread._local", __doc__ = "Thread-local data", __new__ = interp2app(Local.descr_local__new__.im_func), - __init__ = interp2app(Local.descr_local__init__), __dict__ = GetSetProperty(descr_get_dict, cls=Local), ) diff --git a/pypy/module/thread/test/test_local.py b/pypy/module/thread/test/test_local.py index 256d9ede0c..17c4b14369 100644 --- a/pypy/module/thread/test/test_local.py +++ b/pypy/module/thread/test/test_local.py @@ -72,6 +72,19 @@ class AppTestLocal(GenericTestThread): assert seen1 == [1, 2, 3, 4, 5] assert tags == ['???'] + def test_local_init2(self): + import thread + + class A(object): + def __init__(self, n): + assert n == 42 + self.n = n + class X(thread._local, A): + pass + + x = X(42) + assert x.n == 42 + def test_local_setdict(self): import _thread x = _thread._local() |