Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

proxy.h 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #ifndef _proxy_H_
  2. #define _proxy_H_ 1
  3. typedef struct {
  4. PyObject_HEAD
  5. PyObject *proxy_object;
  6. } ProxyObject;
  7. #define Proxy_GET_OBJECT(ob) (((ProxyObject *)(ob))->proxy_object)
  8. typedef struct {
  9. PyTypeObject *proxytype;
  10. int (*check)(PyObject *obj);
  11. PyObject *(*create)(PyObject *obj);
  12. PyObject *(*getobject)(PyObject *proxy);
  13. } ProxyInterface;
  14. #ifndef PROXY_MODULE
  15. /* These are only defined in the public interface, and are not
  16. * available within the module implementation. There we use the
  17. * classic Python/C API only.
  18. */
  19. static ProxyInterface *_proxy_api = NULL;
  20. static int
  21. Proxy_Import(void)
  22. {
  23. if (_proxy_api == NULL) {
  24. PyObject *m = PyImport_ImportModule("zope.proxy");
  25. if (m != NULL) {
  26. PyObject *tmp = PyObject_GetAttrString(m, "_CAPI");
  27. if (tmp != NULL) {
  28. #if PY_VERSION_HEX < 0x02070000
  29. if (PyCObject_Check(tmp))
  30. _proxy_api = (ProxyInterface *)
  31. PyCObject_AsVoidPtr(tmp);
  32. #else
  33. if (PyCapsule_CheckExact(tmp))
  34. _proxy_api = (ProxyInterface *)
  35. PyCapsule_GetPointer(tmp, NULL);
  36. #endif
  37. Py_DECREF(tmp);
  38. }
  39. }
  40. }
  41. return (_proxy_api == NULL) ? -1 : 0;
  42. }
  43. #define ProxyType (*_proxy_api->proxytype)
  44. #define Proxy_Check(obj) (_proxy_api->check((obj)))
  45. #define Proxy_CheckExact(obj) ((obj)->ob_type == ProxyType)
  46. #define Proxy_New(obj) (_proxy_api->create((obj)))
  47. #define Proxy_GetObject(proxy) (_proxy_api->getobject((proxy)))
  48. #endif /* PROXY_MODULE */
  49. #endif /* _proxy_H_ */