[pypy-commit] pypy hpy: (ronan, arigo)
arigo
pypy.commits at gmail.com
Sat Nov 16 11:58:17 EST 2019
Author: Armin Rigo <arigo at tunes.org>
Branch: hpy
Changeset: r98077:5d81fcd424a5
Date: 2019-11-16 17:57 +0100
http://bitbucket.org/pypy/pypy/changeset/5d81fcd424a5/
Log: (ronan, arigo)
in-progress: start to make C stuff and link it to RPython stuff (for
now, that's mostly the HPyContext)
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,19 +1,36 @@
-from rpython.rtyper.lltypesystem import rffi
+from rpython.rtyper.lltypesystem import lltype, llmemory, 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.module.hpy_universal import llapi
+from pypy.module.cpyext.api import generic_cpy_call_dont_convert_result
+
+
+class State:
+ def __init__(self, space):
+ "NOT_RPYTHON"
+ self.space = space
+ self.ctx = llmemory.NULL
+
+ def setup(self):
+ if not self.ctx:
+ #_HPy_FillFunction(0, HPy_ModuleCreate)
+ self.ctx = llapi._HPy_GetGlobalCtx()
+
def create_hpy_module(space, name, origin, lib, initfunc):
state = space.fromcache(State)
- ctx = state.context
- h_module = generic_cpy_call_dont_convert_result(space, initfunc, ctx)
+ initfunc = rffi.cast(llapi.HPyInitFuncPtr, initfunc)
+ h_module = generic_cpy_call_dont_convert_result(space, initfunc, state.ctx)
return from_hpy(h_module)
@unwrap_spec(origin='fsencode', init_name='text')
def descr_load(space, origin, init_name):
# XXX: this looks a lot like cpyext.api.create_extension_module()
+ state = space.fromcache(State)
+ state.setup()
name = init_name[len('HPyInit_'):]
try:
with rffi.scoped_str2charp(origin) as ll_libname:
diff --git a/pypy/module/hpy_universal/llapi.py b/pypy/module/hpy_universal/llapi.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/hpy_universal/llapi.py
@@ -0,0 +1,62 @@
+import os
+from rpython.rtyper.lltypesystem import lltype, llmemory, rffi
+from rpython.translator.tool.cbuild import ExternalCompilationInfo
+
+
+HPy = lltype.Signed
+HPyContext = llmemory.Address
+
+HPyInitFuncPtr = lltype.Ptr(lltype.FuncType([HPyContext], HPy))
+
+
+# ----------------------------------------------------------------
+
+# XXX temporary location
+INCLUDE_DIR = os.path.join(os.path.dirname(__file__),
+ "test", "_vendored", "include")
+
+eci = ExternalCompilationInfo(includes=["universal/hpy.h"],
+ include_dirs=[INCLUDE_DIR],
+ post_include_bits=["""
+
+RPY_EXTERN void _HPy_FillFunction(int index, void *function);
+RPY_EXTERN void *_HPy_GetGlobalCtx(void);
+"""],
+ separate_module_sources=["""
+
+struct _HPyRawContext_s {
+ int ctx_version;
+ void *ctx_raw_functions[1];
+};
+
+union _HPyContext_s_union {
+ struct _HPyContext_s ctx;
+ struct _HPyRawContext_s rawctx;
+};
+
+union _HPyContext_s_union hpy_global_ctx = {
+ {
+ .ctx_version = 1,
+ }
+};
+
+void _HPy_FillFunction(int index, void *function)
+{
+ hpy_global_ctx.rawctx.ctx_raw_functions[index] = function;
+}
+
+void *_HPy_GetGlobalCtx(void)
+{
+ return &hpy_global_ctx;
+}
+
+"""])
+
+
+_HPy_FillFunction = rffi.llexternal('_HPy_FillFunction',
+ [rffi.INT_real, llmemory.Address],
+ lltype.Void,
+ compilation_info=eci, _nowrapper=True)
+
+_HPy_GetGlobalCtx = rffi.llexternal('_HPy_GetGlobalCtx', [], HPyContext,
+ compilation_info=eci, _nowrapper=True)
diff --git a/pypy/module/hpy_universal/moduledef.py b/pypy/module/hpy_universal/moduledef.py
--- a/pypy/module/hpy_universal/moduledef.py
+++ b/pypy/module/hpy_universal/moduledef.py
@@ -1,7 +1,9 @@
from pypy.interpreter.mixedmodule import MixedModule
class Module(MixedModule):
+
+ appleveldefs = {}
+
interpleveldefs = {
'load': 'interp_hpy.descr_load'
}
- appleveldefs = {}
More information about the pypy-commit
mailing list