File: common.c

package info (click to toggle)
python-ldap 3.4.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,756 kB
  • sloc: python: 9,558; ansic: 3,052; makefile: 139; sh: 79
file content (33 lines) | stat: -rw-r--r-- 743 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/* Miscellaneous common routines
 * See https://www.python-ldap.org/ for details. */

#include "common.h"

/* dynamically add the methods into the module dictionary d */

void
LDAPadd_methods(PyObject *d, PyMethodDef *methods)
{
    PyMethodDef *meth;

    for (meth = methods; meth->ml_meth; meth++) {
        PyObject *f = PyCFunction_New(meth, NULL);

        PyDict_SetItemString(d, meth->ml_name, f);
        Py_DECREF(f);
    }
}

/* Raise TypeError with custom message and object */
PyObject *
LDAPerror_TypeError(const char *msg, PyObject *obj)
{
    PyObject *args = Py_BuildValue("sO", msg, obj);

    if (args == NULL) {
        return NULL;
    }
    PyErr_SetObject(PyExc_TypeError, args);
    Py_DECREF(args);
    return NULL;
}