Skip to content

Commit

Permalink
Fix declaration after statement for C90
Browse files Browse the repository at this point in the history
In strict ISO C90 mode and on some platforms (e.g. older MSVC), it is
not allowed to declare new variables after a statement. I also find it
good practice to declare first.

Fixes error: ISO C90 forbids mixed declarations and code
[-Werror=declaration-after-statement]

https://github.com/python-ldap/python-ldap/pull/53
Signed-off-by: Christian Heimes <cheimes@redhat.com>
  • Loading branch information
Christian Heimes authored and Petr Viktorin committed Nov 29, 2017
1 parent a62695e commit de6da53
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ env:
global:
# -Wno-int-in-bool-context: don't complain about PyMem_MALLOC()
# -Werror: turn all warnings into fatal errors
- CFLAGS="-Wno-int-in-bool-context -Werror"
# -Werror=declaration-after-statement: strict ISO C90
- CFLAGS="-std=c90 -Wno-int-in-bool-context -Werror -Werror=declaration-after-statement"
# pass CFLAGS and WITH_GCOV to tox tasks
- TOX_TESTENV_PASSENV="CFLAGS WITH_GCOV"

Expand Down
6 changes: 3 additions & 3 deletions Modules/LDAPObject.c
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,9 @@ l_ldap_result4( LDAPObject* self, PyObject *args )
int res_msgid = 0;
char *retoid = 0;
PyObject *valuestr = NULL;
int result = LDAP_SUCCESS;
char **refs = NULL;
LDAPControl **serverctrls = 0;

if (!PyArg_ParseTuple( args, "|iidiii", &msgid, &all, &timeout, &add_ctrls, &add_intermediates, &add_extop ))
return NULL;
Expand Down Expand Up @@ -1033,9 +1036,6 @@ l_ldap_result4( LDAPObject* self, PyObject *args )
if (msg)
res_msgid = ldap_msgid(msg);

int result = LDAP_SUCCESS;
char **refs = NULL;
LDAPControl **serverctrls = 0;
if (res_type == LDAP_RES_SEARCH_ENTRY) {
/* LDAPmessage_to_python will parse entries and read the controls for each entry */
} else if (res_type == LDAP_RES_SEARCH_REFERENCE) {
Expand Down
3 changes: 1 addition & 2 deletions Modules/constants.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,11 @@ LDAPerror( LDAP *l, char *msg )
PyObject *info;
PyObject *str;
PyObject *pyerrno;
char *matched, *error;

/* at first save errno for later use before it gets overwritten by another call */
myerrno = errno;

char *matched, *error;

opt_errnum = ldap_get_option(l, LDAP_OPT_ERROR_NUMBER, &errnum);
if (opt_errnum != LDAP_OPT_SUCCESS)
errnum = opt_errnum;
Expand Down
9 changes: 5 additions & 4 deletions Modules/ldapmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ PyObject* init_ldap_module(void)
{
PyObject *m, *d;

/* Initialize LDAP class */
if (PyType_Ready(&LDAP_Type) < 0)
return NULL;

/* Create the module and add the functions */
#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef ldap_moduledef = {
Expand All @@ -58,6 +54,11 @@ PyObject* init_ldap_module(void)
#else
m = Py_InitModule("_ldap", methods);
#endif
/* Initialize LDAP class */
if (PyType_Ready(&LDAP_Type) < 0) {
Py_DECREF(m);
return NULL;
}

/* Add some symbolic constants to the module */
d = PyModule_GetDict(m);
Expand Down
5 changes: 3 additions & 2 deletions Modules/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,11 @@ LDAPmessage_to_python(LDAP *ld, LDAPMessage *m, int add_ctrls, int add_intermedi
) {
PyObject* valuelist;
PyObject* pyattr;
struct berval **bvals;

pyattr = PyUnicode_FromString(attr);

struct berval ** bvals =
ldap_get_values_len( ld, entry, attr );
bvals = ldap_get_values_len( ld, entry, attr );

/* Find which list to append to */
if ( PyDict_Contains( attrdict, pyattr ) ) {
Expand Down

0 comments on commit de6da53

Please sign in to comment.