[pypy-commit] pypy hpy: (ronan, arigo, antocuni just arrived now)
arigo
pypy.commits at gmail.com
Sat Nov 16 12:58:11 EST 2019
Author: Armin Rigo <arigo at tunes.org>
Branch: hpy
Changeset: r98078:b3357dcf16a7
Date: 2019-11-16 18:57 +0100
http://bitbucket.org/pypy/pypy/changeset/b3357dcf16a7/
Log: (ronan, arigo, antocuni just arrived now)
Yay, we can now import the empty module
diff --git a/pypy/module/hpy_universal/handles.py b/pypy/module/hpy_universal/handles.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/hpy_universal/handles.py
@@ -0,0 +1,32 @@
+
+
+class HandleManager:
+
+ def __init__(self, space):
+ self.handles_w = [None]
+ self.free_list = []
+
+ def new(self, w_object):
+ if len(self.free_list) == 0:
+ index = len(self.handles_w)
+ self.handles_w.append(w_object)
+ else:
+ index = self.free_list.pop()
+ self.handles_w[index] = w_object
+ return index
+
+ def consume(self, index):
+ assert index > 0
+ w_object = self.handles_w[index]
+ self.handles_w[index] = None
+ self.free_list.append(index)
+ return w_object
+
+
+def new(space, w_object):
+ mgr = space.fromcache(HandleManager)
+ return mgr.new(w_object)
+
+def consume(space, index):
+ mgr = space.fromcache(HandleManager)
+ return mgr.consume(index)
diff --git a/pypy/module/hpy_universal/interp_hpy.py b/pypy/module/hpy_universal/interp_hpy.py
--- a/pypy/module/hpy_universal/interp_hpy.py
+++ b/pypy/module/hpy_universal/interp_hpy.py
@@ -1,30 +1,43 @@
-from rpython.rtyper.lltypesystem import lltype, llmemory, rffi
+from rpython.rtyper.lltypesystem import lltype, rffi
from rpython.rlib.rdynload import dlopen, dlsym, DLOpenError
from pypy.interpreter.gateway import unwrap_spec
from pypy.interpreter.error import raise_import_error
+from pypy.interpreter.module import Module
-from pypy.module.hpy_universal import llapi
+from pypy.module.hpy_universal import llapi, handles
from pypy.module.cpyext.api import generic_cpy_call_dont_convert_result
+from pypy.module.cpyext.api import slot_function
class State:
def __init__(self, space):
"NOT_RPYTHON"
self.space = space
- self.ctx = llmemory.NULL
+ self.ctx = lltype.nullptr(rffi.VOIDP.TO)
def setup(self):
if not self.ctx:
- #_HPy_FillFunction(0, HPy_ModuleCreate)
+ space = self.space
+ funcptr = HPyModule_Create.api_func.get_llhelper(space)
+ llapi._HPy_FillFunction(rffi.cast(rffi.INT_real, 0),
+ rffi.cast(rffi.VOIDP, funcptr))
self.ctx = llapi._HPy_GetGlobalCtx()
+ at slot_function([llapi.HPyContext, lltype.Ptr(llapi.HPyModuleDef)],
+ llapi.HPy, error=0)
+def HPyModule_Create(space, ctx, hpydef):
+ modname = rffi.charp2str(hpydef.c_m_name)
+ w_mod = Module(space, space.newtext(modname))
+ return handles.new(space, w_mod)
+
+
def create_hpy_module(space, name, origin, lib, initfunc):
state = space.fromcache(State)
initfunc = rffi.cast(llapi.HPyInitFuncPtr, initfunc)
h_module = generic_cpy_call_dont_convert_result(space, initfunc, state.ctx)
- return from_hpy(h_module)
+ return handles.consume(space, h_module)
@unwrap_spec(origin='fsencode', init_name='text')
def descr_load(space, origin, init_name):
diff --git a/pypy/module/hpy_universal/llapi.py b/pypy/module/hpy_universal/llapi.py
--- a/pypy/module/hpy_universal/llapi.py
+++ b/pypy/module/hpy_universal/llapi.py
@@ -1,13 +1,36 @@
import os
-from rpython.rtyper.lltypesystem import lltype, llmemory, rffi
+from rpython.rtyper.lltypesystem import lltype, rffi
from rpython.translator.tool.cbuild import ExternalCompilationInfo
HPy = lltype.Signed
-HPyContext = llmemory.Address
+HPyContext = rffi.VOIDP
HPyInitFuncPtr = lltype.Ptr(lltype.FuncType([HPyContext], HPy))
+_HPyCFunctionPtr = lltype.Ptr(lltype.FuncType([HPyContext, HPy, HPy], HPy))
+_HPy_CPyCFunctionPtr = rffi.VOIDP # not used here
+
+_HPyMethodPairFuncPtr = lltype.Ptr(lltype.FuncType([
+ rffi.CArrayPtr(_HPyCFunctionPtr),
+ rffi.CArrayPtr(_HPy_CPyCFunctionPtr)],
+ lltype.Void))
+
+HPyMethodDef = rffi.CStruct('HPyMethodDef',
+ ('ml_name', rffi.CCHARP),
+ ('ml_meth', _HPyMethodPairFuncPtr),
+ ('ml_flags', rffi.INT_real),
+ ('ml_doc', rffi.CCHARP),
+)
+
+HPyModuleDef = rffi.CStruct('HPyModuleDef',
+ ('dummy', rffi.VOIDP),
+ ('m_name', rffi.CCHARP),
+ ('m_doc', rffi.CCHARP),
+ ('m_size', lltype.Signed),
+ ('m_methods', rffi.CArrayPtr(HPyMethodDef)),
+)
+
# ----------------------------------------------------------------
@@ -54,7 +77,7 @@
_HPy_FillFunction = rffi.llexternal('_HPy_FillFunction',
- [rffi.INT_real, llmemory.Address],
+ [rffi.INT_real, rffi.VOIDP],
lltype.Void,
compilation_info=eci, _nowrapper=True)
diff --git a/pypy/module/hpy_universal/test/test_basic.py b/pypy/module/hpy_universal/test/test_basic.py
--- a/pypy/module/hpy_universal/test/test_basic.py
+++ b/pypy/module/hpy_universal/test/test_basic.py
@@ -11,7 +11,13 @@
@INIT
""")
assert type(mod) is type(sys)
+
+ def test_empty_module_initialization(self):
+ import sys
+ mod = self.make_module("""
+ @INIT
+ """)
+ assert type(mod) is type(sys)
assert mod.__loader__.name == 'mytest'
assert mod.__spec__.loader is mod.__loader__
assert mod.__file__
-
More information about the pypy-commit
mailing list