Skip to content

refactor: Merge all header files #541

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ valgrind: build $(PYTHON_SUPP)
autoformat: indent black

indent:
indent Modules/*.c Modules/*.h
indent Modules/*.c
indent -npsl Modules/pythonldap.h
rm -f Modules/*.c~ Modules/*.h~

black:
Expand Down
59 changes: 13 additions & 46 deletions Modules/LDAPObject.c
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
/* See https://www.python-ldap.org/ for details. */

#include "common.h"
#include "pythonldap.h"
#include "patchlevel.h"

#include <math.h>
#include <limits.h>
#include "constants.h"
#include "LDAPObject.h"
#include "ldapcontrol.h"
#include "message.h"
#include "berval.h"
#include "options.h"

#ifdef HAVE_SASL
#include <sasl/sasl.h>
Expand Down Expand Up @@ -276,13 +270,8 @@ attrs_from_List(PyObject *attrlist, char ***attrsp)

if (attrlist == Py_None) {
/* None means a NULL attrlist */
#if PY_MAJOR_VERSION == 2
}
else if (PyBytes_Check(attrlist)) {
#else
}
else if (PyUnicode_Check(attrlist)) {
#endif
/* caught by John Benninghoff <johnb@netscape.com> */
LDAPerror_TypeError
("attrs_from_List(): expected *list* of strings, not a string",
Expand All @@ -293,11 +282,7 @@ attrs_from_List(PyObject *attrlist, char ***attrsp)
PyObject *item = NULL;
Py_ssize_t i, len, strlen;

#if PY_MAJOR_VERSION >= 3
const char *str;
#else
char *str;
#endif

seq = PySequence_Fast(attrlist, "expected list of strings or None");
if (seq == NULL)
Expand All @@ -315,24 +300,12 @@ attrs_from_List(PyObject *attrlist, char ***attrsp)
item = PySequence_Fast_GET_ITEM(seq, i);
if (item == NULL)
goto error;
#if PY_MAJOR_VERSION == 2
/* Encoded in Python to UTF-8 */
if (!PyBytes_Check(item)) {
LDAPerror_TypeError
("attrs_from_List(): expected bytes in list", item);
goto error;
}
if (PyBytes_AsStringAndSize(item, &str, &strlen) == -1) {
goto error;
}
#else
if (!PyUnicode_Check(item)) {
LDAPerror_TypeError
("attrs_from_List(): expected string in list", item);
goto error;
}
str = PyUnicode_AsUTF8AndSize(item, &strlen);
#endif
/* Make a copy. PyBytes_AsString* / PyUnicode_AsUTF8* return
* internal values that must be treated like const char. Python
* 3.7 actually returns a const char.
Expand Down Expand Up @@ -521,7 +494,7 @@ l_ldap_add_ext(LDAPObject *self, PyObject *args)
if (ldaperror != LDAP_SUCCESS)
return LDAPerror(self->ldap);

return PyInt_FromLong(msgid);
return PyLong_FromLong(msgid);
}

/* ldap_simple_bind */
Expand Down Expand Up @@ -572,7 +545,7 @@ l_ldap_simple_bind(LDAPObject *self, PyObject *args)
if (ldaperror != LDAP_SUCCESS)
return LDAPerror(self->ldap);

return PyInt_FromLong(msgid);
return PyLong_FromLong(msgid);
}

#ifdef HAVE_SASL
Expand Down Expand Up @@ -730,7 +703,7 @@ l_ldap_sasl_bind_s(LDAPObject *self, PyObject *args)
}
else if (ldaperror != LDAP_SUCCESS)
return LDAPerror(self->ldap);
return PyInt_FromLong(ldaperror);
return PyLong_FromLong(ldaperror);
}

static PyObject *
Expand All @@ -757,15 +730,9 @@ l_ldap_sasl_interactive_bind_s(LDAPObject *self, PyObject *args)
* unsigned int, we need to use the "I" flag if we're running Python 2.3+ and a
* "i" otherwise.
*/
#if (PY_MAJOR_VERSION == 2) && (PY_MINOR_VERSION < 3)
if (!PyArg_ParseTuple
(args, "sOOOi:sasl_interactive_bind_s", &who, &SASLObject,
&serverctrls, &clientctrls, &sasl_flags))
#else
if (!PyArg_ParseTuple
(args, "sOOOI:sasl_interactive_bind_s", &who, &SASLObject,
&serverctrls, &clientctrls, &sasl_flags))
#endif
return NULL;

if (not_valid(self))
Expand Down Expand Up @@ -809,7 +776,7 @@ l_ldap_sasl_interactive_bind_s(LDAPObject *self, PyObject *args)

if (msgid != LDAP_SUCCESS)
return LDAPerror(self->ldap);
return PyInt_FromLong(msgid);
return PyLong_FromLong(msgid);
}
#endif

Expand Down Expand Up @@ -858,7 +825,7 @@ l_ldap_cancel(LDAPObject *self, PyObject *args)
if (ldaperror != LDAP_SUCCESS)
return LDAPerror(self->ldap);

return PyInt_FromLong(msgid);
return PyLong_FromLong(msgid);
}

#endif
Expand Down Expand Up @@ -912,7 +879,7 @@ l_ldap_compare_ext(LDAPObject *self, PyObject *args)
if (ldaperror != LDAP_SUCCESS)
return LDAPerror(self->ldap);

return PyInt_FromLong(msgid);
return PyLong_FromLong(msgid);
}

/* ldap_delete_ext */
Expand Down Expand Up @@ -958,7 +925,7 @@ l_ldap_delete_ext(LDAPObject *self, PyObject *args)
if (ldaperror != LDAP_SUCCESS)
return LDAPerror(self->ldap);

return PyInt_FromLong(msgid);
return PyLong_FromLong(msgid);
}

/* ldap_modify_ext */
Expand Down Expand Up @@ -1015,7 +982,7 @@ l_ldap_modify_ext(LDAPObject *self, PyObject *args)
if (ldaperror != LDAP_SUCCESS)
return LDAPerror(self->ldap);

return PyInt_FromLong(msgid);
return PyLong_FromLong(msgid);
}

/* ldap_rename */
Expand Down Expand Up @@ -1065,7 +1032,7 @@ l_ldap_rename(LDAPObject *self, PyObject *args)
if (ldaperror != LDAP_SUCCESS)
return LDAPerror(self->ldap);

return PyInt_FromLong(msgid);
return PyLong_FromLong(msgid);
}

/* ldap_result4 */
Expand Down Expand Up @@ -1281,7 +1248,7 @@ l_ldap_search_ext(LDAPObject *self, PyObject *args)
if (ldaperror != LDAP_SUCCESS)
return LDAPerror(self->ldap);

return PyInt_FromLong(msgid);
return PyLong_FromLong(msgid);
}

/* ldap_whoami_s (available since OpenLDAP 2.1.13) */
Expand Down Expand Up @@ -1451,7 +1418,7 @@ l_ldap_passwd(LDAPObject *self, PyObject *args)
if (ldaperror != LDAP_SUCCESS)
return LDAPerror(self->ldap);

return PyInt_FromLong(msgid);
return PyLong_FromLong(msgid);
}

/* ldap_extended_operation */
Expand Down Expand Up @@ -1502,7 +1469,7 @@ l_ldap_extended_operation(LDAPObject *self, PyObject *args)
if (ldaperror != LDAP_SUCCESS)
return LDAPerror(self->ldap);

return PyInt_FromLong(msgid);
return PyLong_FromLong(msgid);
}

/* methods */
Expand Down
38 changes: 0 additions & 38 deletions Modules/LDAPObject.h

This file was deleted.

3 changes: 1 addition & 2 deletions Modules/berval.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* See https://www.python-ldap.org/ for details. */

#include "common.h"
#include "berval.h"
#include "pythonldap.h"

/*
* Copies out the data from a berval, and returns it as a new Python object,
Expand Down
11 changes: 0 additions & 11 deletions Modules/berval.h

This file was deleted.

2 changes: 1 addition & 1 deletion Modules/common.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* Miscellaneous common routines
* See https://www.python-ldap.org/ for details. */

#include "common.h"
#include "pythonldap.h"

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

Expand Down
68 changes: 0 additions & 68 deletions Modules/common.h

This file was deleted.

12 changes: 5 additions & 7 deletions Modules/constants.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/* constants defined for LDAP
* See https://www.python-ldap.org/ for details. */

#include "common.h"
#include "constants.h"
#include "ldapcontrol.h"
#include "pythonldap.h"

/* the base exception class */

Expand Down Expand Up @@ -107,20 +105,20 @@ LDAPraise_for_message(LDAP *l, LDAPMessage *m)
}

if (msgtype > 0) {
pyresult = PyInt_FromLong(msgtype);
pyresult = PyLong_FromLong(msgtype);
if (pyresult)
PyDict_SetItemString(info, "msgtype", pyresult);
Py_XDECREF(pyresult);
}

if (msgid >= 0) {
pyresult = PyInt_FromLong(msgid);
pyresult = PyLong_FromLong(msgid);
if (pyresult)
PyDict_SetItemString(info, "msgid", pyresult);
Py_XDECREF(pyresult);
}

pyresult = PyInt_FromLong(errnum);
pyresult = PyLong_FromLong(errnum);
if (pyresult)
PyDict_SetItemString(info, "result", pyresult);
Py_XDECREF(pyresult);
Expand All @@ -131,7 +129,7 @@ LDAPraise_for_message(LDAP *l, LDAPMessage *m)
Py_XDECREF(str);

if (myerrno != 0) {
pyerrno = PyInt_FromLong(myerrno);
pyerrno = PyLong_FromLong(myerrno);
if (pyerrno)
PyDict_SetItemString(info, "errno", pyerrno);
Py_XDECREF(pyerrno);
Expand Down
Loading