Author: Armin Rigo <[email protected]>
Branch: hpy
Changeset: r98099:25a647d7d077
Date: 2019-11-17 19:08 +0100
http://bitbucket.org/pypy/pypy/changeset/25a647d7d077/
Log: HPy_Close(), HPyNumber_Add()
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
@@ -55,6 +55,10 @@
def HPy_Dup(space, ctx, h):
return handles.dup(space, h)
+@apifunc([llapi.HPyContext, llapi.HPy], lltype.Void, error=None)
+def HPy_Close(space, ctx, h):
+ handles.close(space, h)
+
@apifunc([llapi.HPyContext, rffi.LONG], llapi.HPy, error=0)
def HPyLong_FromLong(space, ctx, value):
w_obj = space.newint(rffi.cast(lltype.Signed, value))
@@ -70,6 +74,13 @@
# ...
return result
+@apifunc([llapi.HPyContext, llapi.HPy, llapi.HPy], llapi.HPy, error=0)
+def HPyNumber_Add(space, ctx, h1, h2):
+ w_obj1 = handles.deref(space, h1)
+ w_obj2 = handles.deref(space, h2)
+ w_result = space.add(w_obj1, w_obj2)
+ return handles.new(space, w_result)
+
def create_hpy_module(space, name, origin, lib, initfunc):
state = space.fromcache(State)
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
@@ -50,8 +50,14 @@
funcptr = interp_hpy.HPy_Dup.get_llhelper(space)
self.ctx.c_ctx_Dup = rffi.cast(rffi.VOIDP, funcptr)
#
+ funcptr = interp_hpy.HPy_Close.get_llhelper(space)
+ self.ctx.c_ctx_Close = rffi.cast(rffi.VOIDP, funcptr)
+ #
funcptr = interp_hpy.HPyLong_FromLong.get_llhelper(space)
self.ctx.c_ctx_Long_FromLong = rffi.cast(rffi.VOIDP, funcptr)
#
funcptr = interp_hpy.HPyLong_AsLong.get_llhelper(space)
self.ctx.c_ctx_Long_AsLong = rffi.cast(rffi.VOIDP, funcptr)
+ #
+ funcptr = interp_hpy.HPyNumber_Add.get_llhelper(space)
+ self.ctx.c_ctx_Number_Add = rffi.cast(rffi.VOIDP, funcptr)
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
@@ -102,3 +102,20 @@
mod.f_o()
with raises(TypeError):
mod.f_o(1, 2)
+
+ def test_close(self):
+ mod = self.make_module("""
+ HPy_FUNCTION(f)
+ static HPy f_impl(HPyContext ctx, HPy self, HPy arg)
+ {
+ HPy one = HPyLong_FromLong(ctx, 1);
+ if (HPy_IsNull(one))
+ return HPy_NULL;
+ HPy res = HPyNumber_Add(ctx, arg, one);
+ HPy_Close(ctx, one);
+ return res;
+ }
+ @EXPORT f METH_O
+ @INIT
+ """)
+ assert mod.f(41.5) == 42.5
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit