[pypy-commit] pypy default: merge heads
arigo
noreply at buildbot.pypy.org
Sat Jun 25 18:08:33 CEST 2011
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r45118:05f990d564e5
Date: 2011-06-25 18:13 +0200
http://bitbucket.org/pypy/pypy/changeset/05f990d564e5/
Log: merge heads
diff --git a/pypy/interpreter/astcompiler/codegen.py b/pypy/interpreter/astcompiler/codegen.py
--- a/pypy/interpreter/astcompiler/codegen.py
+++ b/pypy/interpreter/astcompiler/codegen.py
@@ -134,7 +134,7 @@
def accept_comp_iteration(self, codegen, index):
self.elt.walkabout(codegen)
- codegen.emit_op_arg(ops.SET_ADD, index)
+ codegen.emit_op_arg(ops.SET_ADD, index + 1)
class __extend__(ast.DictComp):
@@ -148,7 +148,7 @@
def accept_comp_iteration(self, codegen, index):
self.value.walkabout(codegen)
self.key.walkabout(codegen)
- codegen.emit_op_arg(ops.MAP_ADD, index)
+ codegen.emit_op_arg(ops.MAP_ADD, index + 1)
# These are frame blocks.
diff --git a/pypy/interpreter/pyopcode.py b/pypy/interpreter/pyopcode.py
--- a/pypy/interpreter/pyopcode.py
+++ b/pypy/interpreter/pyopcode.py
@@ -1048,13 +1048,13 @@
def SET_ADD(self, oparg, next_instr):
w_value = self.popvalue()
- w_set = self.peekvalue(oparg)
+ w_set = self.peekvalue(oparg - 1)
self.space.call_method(w_set, 'add', w_value)
def MAP_ADD(self, oparg, next_instr):
w_key = self.popvalue()
w_value = self.popvalue()
- w_dict = self.peekvalue(oparg)
+ w_dict = self.peekvalue(oparg - 1)
self.space.setitem(w_dict, w_key, w_value)
def SET_LINENO(self, lineno, next_instr):
diff --git a/pypy/module/cpyext/__init__.py b/pypy/module/cpyext/__init__.py
--- a/pypy/module/cpyext/__init__.py
+++ b/pypy/module/cpyext/__init__.py
@@ -39,6 +39,7 @@
import pypy.module.cpyext.object
import pypy.module.cpyext.stringobject
import pypy.module.cpyext.tupleobject
+import pypy.module.cpyext.setobject
import pypy.module.cpyext.dictobject
import pypy.module.cpyext.intobject
import pypy.module.cpyext.longobject
diff --git a/pypy/module/cpyext/setobject.py b/pypy/module/cpyext/setobject.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/cpyext/setobject.py
@@ -0,0 +1,46 @@
+from pypy.interpreter.error import OperationError
+from pypy.rpython.lltypesystem import rffi, lltype
+from pypy.module.cpyext.api import (cpython_api, Py_ssize_t, CANNOT_FAIL,
+ build_type_checkers)
+from pypy.module.cpyext.pyobject import (PyObject, PyObjectP, Py_DecRef,
+ borrow_from, make_ref, from_ref)
+from pypy.module.cpyext.pyerrors import PyErr_BadInternalCall
+from pypy.objspace.std.setobject import W_SetObject, newset
+from pypy.objspace.std.smalltupleobject import W_SmallTupleObject
+
+
+PySet_Check, PySet_CheckExact = build_type_checkers("Set")
+
+
+ at cpython_api([PyObject], PyObject)
+def PySet_New(space, w_iterable):
+ if w_iterable is None:
+ return space.call_function(space.w_set)
+ else:
+ return space.call_function(space.w_set, w_iterable)
+
+ at cpython_api([PyObject, PyObject], rffi.INT_real, error=-1)
+def PySet_Add(space, w_s, w_obj):
+ if not PySet_Check(space, w_s):
+ PyErr_BadInternalCall(space)
+ space.call_method(w_s, 'add', w_obj)
+ return 0
+
+ at cpython_api([PyObject, PyObject], rffi.INT_real, error=-1)
+def PySet_Discard(space, w_s, w_obj):
+ if not PySet_Check(space, w_s):
+ PyErr_BadInternalCall(space)
+ space.call_method(w_s, 'discard', w_obj)
+ return 0
+
+
+ at cpython_api([PyObject], Py_ssize_t, error=CANNOT_FAIL)
+def PySet_GET_SIZE(space, w_s):
+ return space.int_w(space.len(w_s))
+
+ at cpython_api([PyObject], Py_ssize_t, error=-1)
+def PySet_Size(space, ref):
+ if not PySet_Check(space, ref):
+ raise OperationError(space.w_TypeError,
+ space.wrap("expected set object"))
+ return PySet_GET_SIZE(space, ref)
diff --git a/pypy/module/cpyext/test/test_setobject.py b/pypy/module/cpyext/test/test_setobject.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/cpyext/test/test_setobject.py
@@ -0,0 +1,29 @@
+import py
+
+from pypy.module.cpyext.pyobject import PyObject, PyObjectP, make_ref, from_ref
+from pypy.module.cpyext.test.test_api import BaseApiTest
+from pypy.rpython.lltypesystem import rffi, lltype
+from pypy.conftest import gettestobjspace
+
+
+class TestTupleObject(BaseApiTest):
+ def test_setobj(self, space, api):
+ assert not api.PySet_Check(space.w_None)
+ assert api.PySet_Add(space.w_None, space.w_None) == -1
+ api.PyErr_Clear()
+ w_set = space.call_function(space.w_set)
+ space.call_method(w_set, 'update', space.wrap([1,2,3,4]))
+ assert api.PySet_Size(w_set) == 4
+ assert api.PySet_GET_SIZE(w_set) == 4
+ raises(TypeError, api.PySet_Size(space.newlist([])))
+ api.PyErr_Clear()
+
+ def test_set_add_discard(self, space, api):
+ w_set = api.PySet_New(None)
+ assert api.PySet_Size(w_set) == 0
+ w_set = api.PySet_New(space.wrap([1,2,3,4]))
+ assert api.PySet_Size(w_set) == 4
+ api.PySet_Add(w_set, space.wrap(6))
+ assert api.PySet_Size(w_set) == 5
+ api.PySet_Discard(w_set, space.wrap(6))
+ assert api.PySet_Size(w_set) == 4
diff --git a/pypy/module/cpyext/test/test_weakref.py b/pypy/module/cpyext/test/test_weakref.py
--- a/pypy/module/cpyext/test/test_weakref.py
+++ b/pypy/module/cpyext/test/test_weakref.py
@@ -7,6 +7,7 @@
w_ref = api.PyWeakref_NewRef(w_obj, space.w_None)
assert w_ref is not None
assert space.is_w(api.PyWeakref_GetObject(w_ref), w_obj)
+ assert space.is_w(api.PyWeakref_GET_OBJECT(w_ref), w_obj)
assert space.is_w(api.PyWeakref_LockObject(w_ref), w_obj)
w_obj = space.newtuple([])
diff --git a/pypy/module/cpyext/weakrefobject.py b/pypy/module/cpyext/weakrefobject.py
--- a/pypy/module/cpyext/weakrefobject.py
+++ b/pypy/module/cpyext/weakrefobject.py
@@ -21,6 +21,10 @@
"""Return the referenced object from a weak reference. If the referent is
no longer live, returns None. This function returns a borrowed reference.
"""
+ return PyWeakref_GET_OBJECT(space, w_ref)
+
+ at cpython_api([PyObject], PyObject)
+def PyWeakref_GET_OBJECT(space, w_ref):
return borrow_from(w_ref, space.call_function(w_ref))
@cpython_api([PyObject], PyObject)
More information about the pypy-commit
mailing list