Author: Antonio Cuni <[email protected]>
Branch: hpy
Changeset: r98089:a117a040ec4f
Date: 2019-11-17 00:52 +0100
http://bitbucket.org/pypy/pypy/changeset/a117a040ec4f/
Log: implement handles.close
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
@@ -15,11 +15,18 @@
self.handles_w[index] = w_object
return index
+ def close(self, index):
+ assert index > 0
+ self.handles_w[index] = None
+ self.free_list.append(index)
+
def consume(self, index):
+ """
+ Like close, but also return the w_object which was pointed by the
handled
+ """
assert index > 0
w_object = self.handles_w[index]
- self.handles_w[index] = None
- self.free_list.append(index)
+ self.close(index)
return w_object
def dup(self, index):
diff --git a/pypy/module/hpy_universal/test/test_handles.py
b/pypy/module/hpy_universal/test/test_handles.py
--- a/pypy/module/hpy_universal/test/test_handles.py
+++ b/pypy/module/hpy_universal/test/test_handles.py
@@ -7,6 +7,12 @@
h = mgr.new('hello')
assert mgr.handles_w[h] == 'hello'
+ def test_close(self):
+ mgr = HandleManager(None)
+ h = mgr.new('hello')
+ assert mgr.close(h) is None
+ assert mgr.handles_w[h] is None
+
def test_consume(self):
mgr = HandleManager(None)
h = mgr.new('hello')
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit