pypy / pypy / module / cpyext / test /

from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase

class AppTestStringObject(AppTestCpythonExtensionBase):
    def test_pycobject_import(self):
        module = self.import_extension('foo', [
            ("set_ptr", "METH_O",
                 PyObject *pointer, *module;
                 void *ptr = PyLong_AsVoidPtr(args);
                 if (PyErr_Occurred()) return NULL;
                 pointer = PyCObject_FromVoidPtr(ptr, NULL);
                 if (PyErr_Occurred()) return NULL;
                 module = PyImport_ImportModule("foo");
                 PyModule_AddObject(module, "_ptr", pointer);
                 Py_DECREF(pointer);  /* XXX <--- anti-workaround */
                 if (PyErr_Occurred()) return NULL;
            ("get_ptr", "METH_NOARGS",
                 void *ptr = PyCObject_Import("foo", "_ptr");
                 if (PyErr_Occurred()) return NULL;
                 return PyLong_FromVoidPtr(ptr);
        assert "PyCObject object" in str(module._ptr)
        import gc; gc.collect()
        assert module.get_ptr() == 1234
        del module._ptr
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.