Author: Stefan Beyer
Branch: cpyext-gc-cycle
Changeset: r95611:fa88e83164e0
Date: 2018-08-03 13:11 +0200
http://bitbucket.org/pypy/pypy/changeset/fa88e83164e0/
Log:Fixed cpyext test
diff --git a/pypy/module/cpyext/test/test_cpyext.py
b/pypy/module/cpyext/test/test_cpyext.py
--- a/pypy/module/cpyext/test/test_cpyext.py
+++ b/pypy/module/cpyext/test/test_cpyext.py
@@ -3,7 +3,7 @@
import pytest
from pypy.tool.cpyext.extbuild import SystemCompilationInfo, HERE
-from pypy.interpreter.gateway import unwrap_spec, interp2app
+from pypy.interpreter.gateway import unwrap_spec, interp2app, ObjSpace
from pypy.interpreter.error import OperationError
from rpython.rtyper.lltypesystem import lltype
from pypy.module.cpyext import api
@@ -214,8 +214,8 @@
def debug_collect(space):
rawrefcount._collect()
-def print_pyobj_list(space):
-rawrefcount._print_pyobj_list()
+def in_pygclist(space, int_addr):
+return space.wrap(rawrefcount._in_pygclist(int_addr))
class AppTestCpythonExtensionBase(LeakCheckingTest):
@@ -227,7 +227,8 @@
if not cls.runappdirect:
cls.sys_info = get_cpyext_info(space)
cls.w_debug_collect = space.wrap(interp2app(debug_collect))
-cls.w_print_pyobj_list = space.wrap(interp2app(print_pyobj_list))
+cls.w_in_pygclist = space.wrap(
+interp2app(in_pygclist, unwrap_spec=[ObjSpace, int]))
cls.preload_builtins(space)
else:
def w_import_module(self, name, init=None, body='', filename=None,
@@ -929,7 +930,7 @@
),
])
-def test_gc_pyobj_list(self):
+def test_gc_track(self):
"""
Test if Py_GC_Track and Py_GC_Untrack are adding and removing container
objects from the list of all garbage-collected PyObjects.
@@ -937,17 +938,16 @@
if self.runappdirect:
skip('cannot import module with undefined functions')
-# TODO: remove unnecessary stuff, add gc_(un)track asserts
init = """
if (Py_IsInitialized()) {
PyObject* m;
-if (PyType_Ready() < 0)
+if (PyType_Ready() < 0)
return;
-m = Py_InitModule("cycle", module_methods);
+m = Py_InitModule("foo", module_methods);
if (m == NULL)
return;
-Py_INCREF();
-PyModule_AddObject(m, "Cycle", (PyObject *));
+Py_INCREF();
+PyModule_AddObject(m, "Foo", (PyObject *));
}
"""
body = """
@@ -955,85 +955,22 @@
#include "structmember.h"
typedef struct {
PyObject_HEAD
-PyObject *next;
-PyObject *val;
-} Cycle;
-static PyTypeObject CycleType;
-static int Cycle_traverse(Cycle *self, visitproc visit, void *arg)
-{
-int vret;
-if (self->next) {
-vret = visit(self->next, arg);
-if (vret != 0)
-return vret;
-}
-if (self->val) {
-vret = visit(self->val, arg);
-if (vret != 0)
-return vret;
-}
-return 0;
-}
-static int Cycle_clear(Cycle *self)
-{
-PyObject *tmp;
-tmp = self->next;
-self->next = NULL;
-Py_XDECREF(tmp);
-tmp = self->val;
-self->val = NULL;
-Py_XDECREF(tmp);
-return 0;
-}
-static void Cycle_dealloc(Cycle* self)
-{
-Cycle_clear(self);
-Py_TYPE(self)->tp_free((PyObject*)self);
-}
-static PyObject* Cycle_new(PyTypeObject *type, PyObject *args,
+} Foo;
+static PyTypeObject FooType;
+static PyObject* Foo_new(PyTypeObject *type, PyObject *args,
PyObject *kwds)
{
-Cycle *self;
-self = PyObject_GC_New(Cycle, type);
-if (self != NULL) {
-self->next = PyString_FromString("");
-if (self->next == NULL) {
-Py_DECREF(self);
-return NULL;
-}
-}
+Foo *self;
+self = PyObject_GC_New(Foo, type);
PyObject_GC_Track(self);
return (PyObject *)self;
}
-static int Cycle_init(Cycle *self, PyObject *args, PyObject *kwds)
-{
-PyObject *next=NULL, *tmp;
-static char *kwlist[] = {"next", NULL};
-if (! PyArg_ParseTupleAndKeywords(args, kwds, "|O", kwlist,
- ))
-return -1;
-if (next) {
-tmp = self->next;
-Py_INCREF(next);
-self->next = next;
-Py_XDECREF(tmp);
-}
-return 0;
-}
-