Author: Manuel Jacob <m...@manueljacob.de> Branch: Changeset: r90784:af67b08ae873 Date: 2017-03-22 08:53 +0100 http://bitbucket.org/pypy/pypy/changeset/af67b08ae873/
Log: Implement PyModule_New(). diff --git a/pypy/module/cpyext/modsupport.py b/pypy/module/cpyext/modsupport.py --- a/pypy/module/cpyext/modsupport.py +++ b/pypy/module/cpyext/modsupport.py @@ -10,6 +10,14 @@ from pypy.module.cpyext.state import State from pypy.interpreter.error import oefmt +@cpython_api([rffi.CCHARP], PyObject) +def PyModule_New(space, name): + """ + Return a new module object with the __name__ attribute set to name. + Only the module's __doc__ and __name__ attributes are filled in; + the caller is responsible for providing a __file__ attribute.""" + return Module(space, space.newtext(rffi.charp2str(name))) + #@cpython_api([rffi.CCHARP], PyObject) def PyImport_AddModule(space, name): """Return the module object corresponding to a module name. The name argument diff --git a/pypy/module/cpyext/stubs.py b/pypy/module/cpyext/stubs.py --- a/pypy/module/cpyext/stubs.py +++ b/pypy/module/cpyext/stubs.py @@ -1365,13 +1365,6 @@ """ raise NotImplementedError -@cpython_api([rffi.CCHARP], PyObject) -def PyModule_New(space, name): - """Return a new module object with the __name__ attribute set to name. Only - the module's __doc__ and __name__ attributes are filled in; the caller is - responsible for providing a __file__ attribute.""" - raise NotImplementedError - @cpython_api([PyObject], rffi.CCHARP) def PyModule_GetFilename(space, module): """Return the name of the file from which module was loaded using module's 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 @@ -1,8 +1,15 @@ +from pypy.module.cpyext.modsupport import PyModule_New from pypy.module.cpyext.test.test_api import BaseApiTest from rpython.rtyper.lltypesystem import rffi class TestModuleObject(BaseApiTest): + def test_module_new(self, space): + with rffi.scoped_str2charp('testname') as buf: + w_mod = PyModule_New(space, buf) + assert space.eq_w(space.getattr(w_mod, space.newtext('__name__')), + space.newtext('testname')) + def test_module_getname(self, space, api): w_sys = space.wrap(space.sys) p = api.PyModule_GetName(w_sys) _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit