Author: Armin Rigo <[email protected]>
Branch: hpy
Changeset: r98113:38f49b4e8f05
Date: 2019-11-18 13:07 +0100
http://bitbucket.org/pypy/pypy/changeset/38f49b4e8f05/
Log: Use h_None, h_False, h_True
diff --git a/pypy/module/hpy_universal/handles.py
b/pypy/module/hpy_universal/handles.py
--- a/pypy/module/hpy_universal/handles.py
+++ b/pypy/module/hpy_universal/handles.py
@@ -1,9 +1,16 @@
+
+CONSTANTS = [
+ ('NULL', lambda space: None),
+ ('None', lambda space: space.w_None),
+ ('False', lambda space: space.w_False),
+ ('True', lambda space: space.w_True),
+ ]
class HandleManager:
def __init__(self, space):
- self.handles_w = [None]
+ self.handles_w = [build_value(space) for name, build_value in
CONSTANTS]
self.free_list = []
def new(self, w_object):
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
@@ -48,10 +48,6 @@
return handles.new(space, w_mod)
-@apifunc([llapi.HPyContext], llapi.HPy, error=0)
-def HPyNone_Get(space, ctx):
- return handles.new(space, space.w_None)
-
@apifunc([llapi.HPyContext, llapi.HPy], llapi.HPy, error=0)
def HPy_Dup(space, ctx, h):
return handles.dup(space, h)
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
@@ -23,13 +23,15 @@
HPy = lltype.Signed
HPyContextS = rffi.CStruct('_HPyContext_s',
('ctx_version', rffi.INT_real),
+ ('h_None', HPy),
+ ('h_True', HPy),
+ ('h_False', HPy),
('ctx_Module_Create', rffi.VOIDP),
- ('ctx_None_Get', rffi.VOIDP),
('ctx_Dup', rffi.VOIDP),
('ctx_Close', rffi.VOIDP),
('ctx_Long_FromLong', rffi.VOIDP),
('ctx_Long_AsLong', rffi.VOIDP),
- ('ctx_Arg_ParseTuple', rffi.VOIDP),
+ ('ctx_Arg_Parse', rffi.VOIDP),
('ctx_Number_Add', rffi.VOIDP),
('ctx_Unicode_FromString', rffi.VOIDP),
('ctx_FromPyObject', rffi.VOIDP),
diff --git a/pypy/module/hpy_universal/state.py
b/pypy/module/hpy_universal/state.py
--- a/pypy/module/hpy_universal/state.py
+++ b/pypy/module/hpy_universal/state.py
@@ -4,9 +4,10 @@
from rpython.rlib import jit
from rpython.rlib.unroll import unrolling_iterable
from rpython.rlib.objectmodel import specialize
-from pypy.module.hpy_universal import llapi
+from pypy.module.hpy_universal import llapi, handles
CONTEXT_NAMES = unrolling_iterable(llapi.HPyContext.TO._names)
+CONSTANT_NAMES = unrolling_iterable([name for name, _ in handles.CONSTANTS])
DUMMY_FUNC = lltype.FuncType([], lltype.Void)
@specialize.memo()
@@ -29,24 +30,28 @@
if self.ctx:
return
+ space = self.space
self.ctx = llapi._HPy_GetGlobalCtx()
for name in CONTEXT_NAMES:
- if name != 'c_ctx_version':
+ if name == 'c_ctx_version':
+ continue
+ if name.startswith('c_ctx_'):
missing_function = make_missing_function(name)
funcptr = llhelper(lltype.Ptr(DUMMY_FUNC), missing_function)
setattr(self.ctx, name, rffi.cast(rffi.VOIDP, funcptr))
+ i = 0
+ for name in CONSTANT_NAMES:
+ if name != 'NULL':
+ setattr(self.ctx, 'c_h_' + name, i)
+ i = i + 1
# XXX collect all these functions automatically
from pypy.module.hpy_universal import interp_hpy
- space = self.space
funcptr = interp_hpy.HPyModule_Create.get_llhelper(space)
self.ctx.c_ctx_Module_Create = rffi.cast(rffi.VOIDP, funcptr)
#
- funcptr = interp_hpy.HPyNone_Get.get_llhelper(space)
- self.ctx.c_ctx_None_Get = rffi.cast(rffi.VOIDP, funcptr)
- #
funcptr = interp_hpy.HPy_Dup.get_llhelper(space)
self.ctx.c_ctx_Dup = rffi.cast(rffi.VOIDP, funcptr)
#
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit