[pypy-commit] pypy cpyext-refactor-methodobject: fix this CCC and pass a py_tuple also to METH_OLDARGS calls
antocuni
pypy.commits at gmail.com
Sun Oct 22 11:39:52 EDT 2017
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: cpyext-refactor-methodobject
Changeset: r92825:42834b4486db
Date: 2017-10-22 12:05 +0200
http://bitbucket.org/pypy/pypy/changeset/42834b4486db/
Log: fix this CCC and pass a py_tuple also to METH_OLDARGS calls
diff --git a/pypy/module/cpyext/methodobject.py b/pypy/module/cpyext/methodobject.py
--- a/pypy/module/cpyext/methodobject.py
+++ b/pypy/module/cpyext/methodobject.py
@@ -121,13 +121,15 @@
func = self.ml.c_ml_meth
length = len(__args__.arguments_w)
if length == 0:
- w_args = None
+ py_args = lltype.nullptr(PyObject.TO)
elif length == 1:
- w_args = __args__.arguments_w[0]
+ py_args = make_ref(space, __args__.arguments_w[0])
else:
- # CCC: create a py_tuple
- w_args = space.newtuple(__args__.arguments_w)
- return generic_cpy_call(space, func, w_self, w_args)
+ py_args = tuple_from_args_w(space, __args__.arguments_w)
+ try:
+ return generic_cpy_call(space, func, w_self, py_args)
+ finally:
+ decref(space, py_args)
def get_doc(self, space):
doc = self.ml.c_ml_doc
diff --git a/pypy/module/cpyext/test/test_methodobject.py b/pypy/module/cpyext/test/test_methodobject.py
--- a/pypy/module/cpyext/test/test_methodobject.py
+++ b/pypy/module/cpyext/test/test_methodobject.py
@@ -42,25 +42,6 @@
raises(TypeError, mod.getarg_O)
raises(TypeError, mod.getarg_O, 1, 1)
- def test_call_METH_OLDARGS(self):
- mod = self.import_extension('MyModule', [
- ('getarg_OLD', 'METH_OLDARGS',
- '''
- if(args) {
- Py_INCREF(args);
- return args;
- }
- else {
- Py_INCREF(Py_None);
- return Py_None;
- }
- '''
- ),
- ])
- assert mod.getarg_OLD(1) == 1
- assert mod.getarg_OLD() is None
- assert mod.getarg_OLD(1, 2) == (1, 2)
-
def test_call_METH_VARARGS(self):
mod = self.import_extension('MyModule', [
('getarg_VARARGS', 'METH_VARARGS',
@@ -92,6 +73,27 @@
#
raises(TypeError, mod.getarg_VARARGS, k=1)
+ def test_call_METH_OLDARGS(self):
+ mod = self.import_extension('MyModule', [
+ ('getarg_OLD', 'METH_OLDARGS',
+ '''
+ if(args) {
+ return Py_BuildValue("Ol", args, args->ob_refcnt);
+ }
+ else {
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
+ '''
+ ),
+ ])
+ assert mod.getarg_OLD() is None
+ val, refcnt = mod.getarg_OLD(1)
+ assert val == 1
+ val, refcnt = mod.getarg_OLD(1, 2)
+ assert val == (1, 2)
+ assert refcnt == 1 # see the comments in the test above
+
def test_call_METH_KEYWORDS(self):
mod = self.import_extension('MyModule', [
('getarg_KW', 'METH_VARARGS | METH_KEYWORDS',
More information about the pypy-commit
mailing list