[pypy-commit] pypy cpyext-gc-cycle: Fixed cpyext test

2019-01-11 Thread stevie_92
Author: Stefan Beyer 
Branch: cpyext-gc-cycle
Changeset: r95608:ada4b64c0816
Date: 2018-08-02 10:59 +0200
http://bitbucket.org/pypy/pypy/changeset/ada4b64c0816/

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
@@ -1069,6 +1069,7 @@
 (initproc)Cycle_init,  /* tp_init */
 0, /* tp_alloc */
 Cycle_new, /* tp_new */
+PyObject_GC_Del,   /* tp_free */
 };
 
 extern PyGC_Head *_pypy_rawrefcount_pyobj_list;
@@ -1078,6 +1079,8 @@
  Cycle *c = PyObject_GC_New(Cycle, );
  if (c == NULL)
  return NULL;
+ 
+ Py_INCREF(val);
  c->next = val;
 
  // TODO: check if _pypy_rawrefcount_pyobj_list contains c
@@ -1100,7 +1103,3 @@
 self.print_pyobj_list()
 c = module.create(Example(42))
 self.print_pyobj_list()
-
-# TODO: fix rawrefcount, so that the Cycle objects are properly added
-#   to the ALLOCATED list of leakfinder or alternatively not freed
-#   by collect
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cpyext-gc-cycle: Fixed cpyext test

2019-01-11 Thread stevie_92
Author: Stefan Beyer 
Branch: cpyext-gc-cycle
Changeset: r95609:860d9f8d29b6
Date: 2018-08-02 14:53 +0200
http://bitbucket.org/pypy/pypy/changeset/860d9f8d29b6/

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
@@ -937,7 +937,7 @@
 if self.runappdirect:
 skip('cannot import module with undefined functions')
 
-# TODO: remove unnecessary stuff, add tests for gc_untrack, add asserts
+# TODO: remove unnecessary stuff, add gc_(un)track asserts
 init = """
 if (Py_IsInitialized()) {
 PyObject* m;
@@ -994,7 +994,7 @@
PyObject *kwds)
 {
 Cycle *self;
-self = (Cycle *)type->tp_alloc(type, 0);
+self = PyObject_GC_New(Cycle, type);
 if (self != NULL) {
 self->next = PyString_FromString("");
 if (self->next == NULL) {
@@ -1074,23 +1074,23 @@
 
 extern PyGC_Head *_pypy_rawrefcount_pyobj_list;
 
- static PyObject * Cycle_Create(Cycle *self, PyObject *val)
- {
- Cycle *c = PyObject_GC_New(Cycle, );
- if (c == NULL)
- return NULL;
- 
- Py_INCREF(val);
- c->next = val;
+static PyObject * Cycle_Create(Cycle *self, PyObject *val)
+{
+Cycle *c = (Cycle *)Cycle_new(, NULL, NULL);
+if (c == NULL)
+   return NULL;
+
+Py_INCREF(val);
+c->next = val;
 
- // TODO: check if _pypy_rawrefcount_pyobj_list contains c
+// TODO: check if _pypy_rawrefcount_pyobj_list contains c
 
- return (PyObject *)c;
- }
- static PyMethodDef module_methods[] = {
- {"create", (PyCFunction)Cycle_Create, METH_OLDARGS, ""},
- {NULL}  /* Sentinel */
- };
+return (PyObject *)c;
+}
+static PyMethodDef module_methods[] = {
+{"create", (PyCFunction)Cycle_Create, METH_OLDARGS, ""},
+{NULL}  /* Sentinel */
+};
 """
 module = self.import_module(name='cycle', init=init, body=body)
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cpyext-gc-cycle: Fixed cpyext test

2019-01-11 Thread stevie_92
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;
-}
-