/breezy/trunk

To get this branch, use:
bzr branch https://code.breezy-vcs.org/breezy/trunk

« back to all changes in this revision

Viewing changes to breezy/_import_c_api.h

  • Committer: Jelmer Vernooij
  • Date: 2017-07-23 22:06:41 UTC
  • mfrom: (6738 trunk)
  • mto: This revision was merged to the branch mainline in revision 6739.
  • Revision ID: jelmer@jelmer.uk-20170723220641-69eczax9bmv8d6kk
Merge trunk, address review comments.

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
                            void **func, const char *signature)
45
45
{
46
46
    PyObject *d = NULL;
47
 
    PyObject *c_obj = NULL;
48
 
    const char *desc = NULL;
 
47
    PyObject *capsule = NULL;
 
48
    void *pointer;
49
49
 
50
 
    /* (char *) because Python2.4 defines this as (char *) rather than
51
 
     * (const char *)
52
 
     */
53
 
    d = PyObject_GetAttrString(module, (char *)_C_API_NAME);
 
50
    d = PyObject_GetAttrString(module, _C_API_NAME);
54
51
    if (!d) {
55
52
        // PyObject_GetAttrString sets an appropriate exception
56
53
        goto bad;
57
54
    }
58
 
    c_obj = PyDict_GetItemString(d, funcname);
59
 
    if (!c_obj) {
 
55
    capsule = PyDict_GetItemString(d, funcname);
 
56
    if (!capsule) {
60
57
        // PyDict_GetItemString does not set an exception
61
58
        PyErr_Format(PyExc_AttributeError,
62
59
            "Module %s did not export a function named %s\n",
63
60
            PyModule_GetName(module), funcname);
64
61
        goto bad;
65
62
    }
66
 
    desc = (char *)PyCObject_GetDesc(c_obj);
67
 
    if (!desc || strcmp(desc, signature) != 0) {
68
 
        if (desc == NULL) {
69
 
            desc = "<null>";
70
 
        }
71
 
        PyErr_Format(PyExc_TypeError,
72
 
            "C function %s.%s has wrong signature (expected %s, got %s)",
73
 
                PyModule_GetName(module), funcname, signature, desc);
 
63
    pointer = PyCapsule_GetPointer(capsule, signature);
 
64
    if (!pointer) {
 
65
        // PyCapsule_GetPointer sets an error with a little context
74
66
        goto bad;
75
67
    }
76
 
    *func = PyCObject_AsVoidPtr(c_obj);
 
68
    *func = pointer;
77
69
    Py_DECREF(d);
78
70
    return 0;
79
71
bad: