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 pdox
Recipients pdox
Date 2017-10-15.06:22:28
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1508048549.34.0.213398074469.issue31791@psf.upfronthosting.co.za>
In-reply-to
Content
Ensure that every function pointer in every PyTypeObject is set to a non-NULL default, to spare the cost of checking for NULL with every use. As a basic example, consider PyNumber_Negative:

PyObject *
PyNumber_Negative(PyObject *o)
{
    PyNumberMethods *m;

    if (o == NULL) {
        return null_error();
    }

    m = o->ob_type->tp_as_number;
    if (m && m->nb_negative)
        return (*m->nb_negative)(o);

    return type_error("bad operand type for unary -: '%.200s'", o);
}

If "tp_as_number" and "nb_negative" were always guaranteed non-NULL, then the function could omit the second if statement, and invoke the function pointer directly. To maintain the existing behavior, the default nb_negative function would be set to the following:

PyObject* nb_negative_default(PyObject *o) {
    return type_error("bad operand type for unary -: '%.200s'", o);
}

This removes two NULL-checks from the PyNumber_Negative. Many other operators and builtins would be able to benefit in the same way.
History
Date User Action Args
2017-10-15 06:22:29pdoxsetrecipients: + pdox
2017-10-15 06:22:29pdoxsetmessageid: <1508048549.34.0.213398074469.issue31791@psf.upfronthosting.co.za>
2017-10-15 06:22:29pdoxlinkissue31791 messages
2017-10-15 06:22:28pdoxcreate