Skip to content

Commit

Permalink
Refactor: Keep information about OpenLDAP constants in Python, genera…
Browse files Browse the repository at this point in the history
…te C

Modules/errors.{c,h} are merged into Modules/constants.{c,h}

The function LDAPerror_TypeError is moved to common.{c,h}, as it's not
concerned with LDAPError.

Add a new Python module, ldap.constants, to keep information about
all OpenLDAP constants that we know about, including those that aren't
available in the OpenLDAP used.

Generate a C header file, Modules/constants_generated.h, from this information.
(Checking generated files into Git is better avoided, but it's much
more straightforward than generating the file from setup.py.)

Use proper error checking when adding the constants.
  • Loading branch information
Petr Viktorin committed Nov 27, 2017
1 parent 8807e75 commit 48a9241
Show file tree
Hide file tree
Showing 15 changed files with 950 additions and 591 deletions.
402 changes: 402 additions & 0 deletions Lib/ldap/constants.py

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion Modules/LDAPObject.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

#include <math.h>
#include <limits.h>
#include "errors.h"
#include "constants.h"
#include "LDAPObject.h"
#include "ldapcontrol.h"
Expand Down
12 changes: 12 additions & 0 deletions Modules/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,15 @@ LDAPadd_methods( PyObject* d, PyMethodDef* methods )
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;
}
2 changes: 2 additions & 0 deletions Modules/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#define streq( a, b ) \
( (*(a)==*(b)) && 0==strcmp(a,b) )

extern PyObject* LDAPerror_TypeError(const char *, PyObject *);

void LDAPadd_methods( PyObject*d, PyMethodDef*methods );
#define PyNone_Check(o) ((o) == Py_None)

Expand Down
Loading

0 comments on commit 48a9241

Please sign in to comment.