/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/_export_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:
15
15
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 */
17
17
 
18
 
 
19
18
/* This file contains helper functions for exporting a C API for a CPython
20
19
 * extension module.
21
20
 */
43
42
_export_function(PyObject *module, char *funcname, void *func, char *signature)
44
43
{
45
44
    PyObject *d = NULL;
46
 
    PyObject *c_obj = NULL;
 
45
    PyObject *capsule = NULL;
47
46
 
48
 
    /* (char *) is because python2.4 declares this api as 'char *' rather than
49
 
     * const char* which it really is.
50
 
     */
51
 
    d = PyObject_GetAttrString(module, (char *)_C_API_NAME);
 
47
    d = PyObject_GetAttrString(module, _C_API_NAME);
52
48
    if (!d) {
53
49
        PyErr_Clear();
54
50
        d = PyDict_New();
55
51
        if (!d)
56
52
            goto bad;
57
53
        Py_INCREF(d);
58
 
        if (PyModule_AddObject(module, (char *)_C_API_NAME, d) < 0)
 
54
        if (PyModule_AddObject(module, _C_API_NAME, d) < 0)
59
55
            goto bad;
60
56
    }
61
 
    c_obj = PyCObject_FromVoidPtrAndDesc(func, signature, 0);
62
 
    if (!c_obj)
 
57
    capsule = PyCapsule_New(func, signature, 0);
 
58
    if (!capsule)
63
59
        goto bad;
64
 
    if (PyDict_SetItemString(d, funcname, c_obj) < 0)
 
60
    if (PyDict_SetItemString(d, funcname, capsule) < 0)
65
61
        goto bad;
66
62
    Py_DECREF(d);
67
63
    return 0;
68
64
bad:
69
 
    Py_XDECREF(c_obj);
 
65
    Py_XDECREF(capsule);
70
66
    Py_XDECREF(d);
71
67
    return -1;
72
68
}