[Python-Dev] Let's update CObject API so it is safe and regular! (original) (raw)

Larry Hastings larry at hastings.org
Wed Apr 1 20:58:00 CEST 2009


Kristján Valur Jónsson wrote:

What are the semantics of the "type" argument for PyCObjectFromVoidPtr()?

From the patch, from the documentation comment above the prototype for PyCObject_FromVoidPtr() in Include/cobject.h:

The "type" string must point to a legal C string of non-zero length,

-Does it do a strdup, or is the type required to be valid while the object exists (e.g. a static string)?

From the patch, continuing on from where we just left off:

and this string must outlive the CObject.

-How is the type match determined, strcmp, or pointer comparison?

From the patch, observing the code in the static function _is_legal_cobject_and_type() in Objects/cobject.c:

    if (!type || !*type) {
        PyErr_SetString(PyExc_TypeError, invalidType);
        return 0;
    }
    if (strcmp(type, self->type)) {
        PyErr_SetString(PyExc_TypeError, incorrectType);
        return 0;
    }

A method for answering further such questions suggests itself,

/larry// /



More information about the Python-Dev mailing list