This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author scoder
Recipients barry, gvanrossum, scoder, serhiy.storchaka
Date 2015-06-19.16:56:33
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <558449BF.8000607@behnel.de>
In-reply-to <1434723397.81.0.530058377904.issue24469@psf.upfronthosting.co.za>
Content
> 1) The intended solution is to require that int subclasses override tp_free.

In the way I showed? By calling either PyObject_GC_Del() or PyObject_Del()
directly? I'll happily do that (Py2.7 and Py2 "int" being dead ends makes
that pretty future proof), but it's neither obvious nor very clean.

> 2) I don't see any constructors that don't call PyInt_FromLong() -- what am I missing?

Not sure what you mean. int_new() immediately calls int_subtype_new(),
which then calls type->tp_alloc(). No call to PyInt_FromLong() involved.

"""
static PyObject *
int_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
    PyObject *x = NULL;
    int base = -909;
    static char *kwlist[] = {"x", "base", 0};

    if (type != &PyInt_Type)
        return int_subtype_new(type, args, kwds); /* Wimp out */
...

static PyObject *
int_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
    ...
    tmp = int_new(&PyInt_Type, args, kwds);
    if (tmp == NULL)
        return NULL;
    if (!PyInt_Check(tmp)) {
        ival = PyLong_AsLong(tmp);
        if (ival == -1 && PyErr_Occurred()) {
            Py_DECREF(tmp);
            return NULL;
        }
    } else {
        ival = ((PyIntObject *)tmp)->ob_ival;
    }

    newobj = type->tp_alloc(type, 0);
    if (newobj == NULL) {
        Py_DECREF(tmp);
        return NULL;
    }
    ((PyIntObject *)newobj)->ob_ival = ival;
    Py_DECREF(tmp);
    return newobj;
}
"""
History
Date User Action Args
2015-06-19 16:56:33scodersetrecipients: + scoder, gvanrossum, barry, serhiy.storchaka
2015-06-19 16:56:33scoderlinkissue24469 messages
2015-06-19 16:56:33scodercreate