These are chat archives for dropbox/pyston

13th
Jun 2016
Sun
@Daetalus
Jun 13 2016 10:09
Hi @undingen , I just want to update the Cython to 0.24, and retrieve it from github directly.
Marius Wachtler
@undingen
Jun 13 2016 10:48
cool :-) but meanwhile I will merge my dropbox/pyston#1248 which just changes the url so that travis ci is not broken
Sun
@Daetalus
Jun 13 2016 10:55
I see.
An Long
@aisk
Jun 13 2016 13:34
Hi @undingen , I tried to replace abstract.cpp with cpython's abstract.c, but got this error while making:
Remaining object addresses:
0x2b6d0e394a68 [1] str     watch -l ((PyObject*)0x2b6d0e394a68)->ob_refcnt
../../src/runtime/types.cpp:4747: void Py_Finalize(): Assertion `_Py_RefTotal == 0' failed: 1 refs remaining!
Aborted (core dumped)
do you have any ideas to to find out where the problem is?
Marius Wachtler
@undingen
Jun 13 2016 14:53
that means we are leaking memory (or at least thing that we are leaking): it's probably caused by a static variable which get's initialized with a interned string.
something like:
    static PyObject *int_name = NULL;
    if (int_name == NULL) {
        int_name = PyString_InternFromString("__int__");
        if (int_name == NULL)
            return NULL;
    }
An Long
@aisk
Jun 13 2016 14:54
I think i'll caught it soon
(using binary search ...)
Marius Wachtler
@undingen
Jun 13 2016 14:55
this needs to be changed to:
    static PyObject *int_name = NULL;
    if (int_name == NULL) {
        int_name = PyString_InternFromString("__int__");
        if (int_name == NULL)
            return NULL;
        // Pyston change:
        PyGC_RegisterStaticConstant(int_name);
    }
without the PyGC_RegisterStaticConstant pyston would complain that there is a reference to a string left because the static variable will never decref the reference
we are a little stricter than cpython which checking that there are no references left :-)
An Long
@aisk
Jun 13 2016 14:57
can we provide another functions in from_cpython to automacaltolly do this?
another PyString_InternFromString
Marius Wachtler
@undingen
Jun 13 2016 15:16
in the c++ class we have getStaticString() but it is not exposed to the CAPI, but if you want to mechanically replace it I think it's fine to replace PyString_InternFromString(<str>) with PyGC_RegisterStaticConstant(PyString_InternFromString(<str>))
An Long
@aisk
Jun 13 2016 15:35
another question, It seems we do not use the PyInstanceObject defined in CPython, so if it was used in the from_cpython?
I think we can't cast it to BoxedInstance because it's a C++ class
Marius Wachtler
@undingen
Jun 13 2016 16:03
exactly currently one can't use the PyInstanceObject struct because our c++ class has a different layout. where did you run into that?
If it's required we could add a dummy PyInstanceObject with the same size as our c++ class but we probably can't expose in_dict because we use a different mechanism to implement it
Kevin Modzelewski
@kmod
Jun 13 2016 19:43
yeah, we probably want to keep the struct opaque, and then add apis for accessing/setting the members
We could also add PyString_GetStaticString to wrap getStaticString (which is just PyGC_RegisterStaticConstant(PyString_InternFromString()))
if you get a reference leak, you can put that watch command into gdb and it will show you where the object got created