LDAPObject.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /* See http://www.python-ldap.org/ for details.
  2. * $Id: LDAPObject.h,v 1.10 2009/04/17 12:19:09 stroeder Exp $ */
  3. #ifndef __h_LDAPObject
  4. #define __h_LDAPObject
  5. #include "common.h"
  6. #include "lber.h"
  7. #include "ldap.h"
  8. #if LDAP_API_VERSION < 2000
  9. #error Current python-ldap requires OpenLDAP 2.x
  10. #endif
  11. #if PYTHON_API_VERSION < 1007
  12. typedef PyObject* _threadstate;
  13. #else
  14. typedef PyThreadState* _threadstate;
  15. #endif
  16. typedef struct {
  17. PyObject_HEAD
  18. LDAP* ldap;
  19. _threadstate _save; /* for thread saving on referrals */
  20. int valid;
  21. } LDAPObject;
  22. extern PyTypeObject LDAP_Type;
  23. #define LDAPObject_Check(v) ((v)->ob_type == &LDAP_Type)
  24. extern LDAPObject *newLDAPObject( LDAP* );
  25. /* macros to allow thread saving in the context of an LDAP connection */
  26. #define LDAP_BEGIN_ALLOW_THREADS( l ) \
  27. { \
  28. LDAPObject *lo = (l); \
  29. if (lo->_save != NULL) \
  30. Py_FatalError( "saving thread twice?" ); \
  31. lo->_save = PyEval_SaveThread(); \
  32. }
  33. #define LDAP_END_ALLOW_THREADS( l ) \
  34. { \
  35. LDAPObject *lo = (l); \
  36. _threadstate _save = lo->_save; \
  37. lo->_save = NULL; \
  38. PyEval_RestoreThread( _save ); \
  39. }
  40. #endif /* __h_LDAPObject */