Problem with OpenLDAP 2.2: Macro add_int_r() in constants.c?!?

Michael Ströder michael at stroeder.com
Wed Mar 10 18:57:35 CET 2004


HI!

David, please take note of this!

What was the rationale of having this macro in constants.c?
What are "reversibles" in this context?

#define add_int_r(d, name)                                              \
         {                                                               \
             long v = LDAP_##name;                                       \
             PyObject *i = PyInt_FromLong( v );                          \
             PyObject *s = PyString_FromString( #name );                 \
             PyDict_SetItem( d, s, s );                                  \
             PyDict_SetItem( reverse, i, s );                            \
             PyDict_SetItem( forward, s, i );                            \
             Py_DECREF(i);                                               \
             Py_DECREF(s);                                               \
             /* printf("%s -> %ld\n", #name, v );  */                    \
         }

[..]

         /* reversibles */

         zero = PyInt_FromLong( 0 );
         PyDict_SetItem( reverse, zero, Py_None );
         Py_DECREF( zero );

         add_int_r(d,RES_BIND);
         add_int_r(d,RES_SEARCH_ENTRY);
         add_int_r(d,RES_SEARCH_RESULT);
         add_int_r(d,RES_MODIFY);
         add_int_r(d,RES_ADD);
         add_int_r(d,RES_DELETE);
         add_int_r(d,RES_MODRDN);
         add_int_r(d,RES_COMPARE);
         add_int(d,RES_ANY);

         add_int_r(d,RES_SEARCH_REFERENCE);
         add_int_r(d,RES_EXTENDED);
         add_int_r(d,RES_UNSOLICITED);

It seems to map some integers from ldap.h to strings with the constant's 
name. For some unknown reason this does not work with OpenLDAP 2.2 libs 
anymore. E.g. there are integers returned by l_ldap_result() as result type 
and this breaks ldap.async or other code which trys to evaluate the result 
type as string.

I have a working solution without add_int_r() which might be 
backward-compatible if one strictly uses constants. This looks like a good 
compromise for me.

Any comments?

Ciao, Michael.



More information about the python-ldap mailing list