[pypy-commit] pypy hpy: progress towards passing test_self_is_module: implement HPy_Dup

antocuni pypy.commits at gmail.com
Sat Nov 16 19:16:15 EST 2019


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: hpy
Changeset: r98086:33150b74ce8b
Date: 2019-11-17 00:37 +0100
http://bitbucket.org/pypy/pypy/changeset/33150b74ce8b/

Log:	progress towards passing test_self_is_module: implement HPy_Dup

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
@@ -22,6 +22,10 @@
         self.free_list.append(index)
         return w_object
 
+    def dup(self, index):
+        w_object = self.handles_w[index]
+        return self.new(w_object)
+
 
 def new(space, w_object):
     mgr = space.fromcache(HandleManager)
@@ -30,3 +34,7 @@
 def consume(space, index):
     mgr = space.fromcache(HandleManager)
     return mgr.consume(index)
+
+def dup(space, index):
+    mgr = space.fromcache(HandleManager)
+    return mgr.dup(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
@@ -51,6 +51,10 @@
 def HPyNone_Get(space, ctx):
     return handles.new(space, space.w_None)
 
+ at apifunc([llapi.HPyContext, llapi.HPy], llapi.HPy, error=0)
+def HPy_Dup(space, ctx, h):
+    return handles.dup(space, h)
+
 
 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
@@ -44,3 +44,6 @@
         #
         funcptr = interp_hpy.HPyNone_Get.get_llhelper(space)
         self.ctx.ctx_None_Get = rffi.cast(rffi.VOIDP, funcptr)
+        #
+        funcptr = interp_hpy.HPy_Dup.get_llhelper(space)
+        self.ctx.ctx_Dup = 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
@@ -40,3 +40,15 @@
             @INIT
         """)
         assert mod.f() is None
+
+    def test_self_is_module(self):
+        mod = self.make_module("""
+            HPy_FUNCTION(f)
+            static HPy f_impl(HPyContext ctx, HPy self, HPy args)
+            {
+                return HPy_Dup(ctx, self);
+            }
+            @EXPORT f METH_NOARGS
+            @INIT
+        """)
+        assert mod.f() is mod


More information about the pypy-commit mailing list