patch: l_ldap_result() now properly raising exceptions
Michael Ströder
michael at stroeder.com
Tue Oct 17 11:29:06 CEST 2000
Konstantin Chuguev wrote:
>
> Oughh. After some late hacking tonight, here we are :-)
GREAT!!! It works.
I have attached Konstantin's patch to this message. Could someone
with more Python/C knowledge look into the patched LDAPObject.c
function l_ldap_result() to make sure that we do not introduce new
memory leaks with this patch?
Note: Since the result() method now properly raises exceptions
caused by LDAP errors one might have to add additional exception
handling to the calling Python code.
Ciao, Michael.
-------------- next part --------------
--- LDAPObject.c.orig Mon Aug 14 23:37:37 2000
+++ LDAPObject.c Mon Oct 16 20:54:10 2000
@@ -1198,7 +1198,7 @@
double timeout = -1.0;
struct timeval tv;
struct timeval* tvp;
- int result;
+ int res_type, result;
LDAPMessage *msg = NULL;
PyObject *result_str, *retval;
@@ -1214,13 +1214,26 @@
}
LDAP_BEGIN_ALLOW_THREADS( self );
- result = ldap_result( self->ldap, msgid, all, tvp, &msg );
+ res_type = ldap_result( self->ldap, msgid, all, tvp, &msg );
LDAP_END_ALLOW_THREADS( self );
- if (result == -1)
+ if (res_type < 0) /* LDAP or system error */
return LDAPerror( self->ldap, "ldap_result" );
- result_str = LDAPconstant( result );
+ if (res_type == 0) /* Timeout has occured */
+ return Py_None;
+
+ if (res_type != LDAP_RES_SEARCH_ENTRY) {
+ LDAP_BEGIN_ALLOW_THREADS( self );
+ result = ldap_result2error( self->ldap, msg, 0 );
+ LDAP_END_ALLOW_THREADS( self );
+
+ if (result != LDAP_SUCCESS) { /* result error */
+ return LDAPerror( self->ldap, "ldap_result2error" );
+ }
+ }
+
+ result_str = LDAPconstant( res_type );
if (msg == NULL) {
retval = Py_BuildValue("(OO)", result_str, Py_None);
More information about the python-ldap
mailing list