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.

objectkeymacros.h 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #define KEYMACROS_H "$Id$\n"
  2. #define KEY_TYPE PyObject *
  3. #define KEY_TYPE_IS_PYOBJECT
  4. #include "Python.h"
  5. #include "_compat.h"
  6. static PyObject *object_; /* initialized in BTreeModuleTemplate init */
  7. static int
  8. check_argument_cmp(PyObject *arg)
  9. {
  10. /* printf("check cmp %p %p %p %p\n", */
  11. /* arg->ob_type->tp_richcompare, */
  12. /* ((PyTypeObject *)object_)->ob_type->tp_richcompare, */
  13. /* arg->ob_type->tp_compare, */
  14. /* ((PyTypeObject *)object_)->ob_type->tp_compare); */
  15. if (arg == Py_None) {
  16. return 1;
  17. }
  18. #ifdef PY3K
  19. if (Py_TYPE(arg)->tp_richcompare == Py_TYPE(object_)->tp_richcompare)
  20. #else
  21. if (Py_TYPE(arg)->tp_richcompare == NULL
  22. && Py_TYPE(arg)->tp_compare == Py_TYPE(object_)->tp_compare)
  23. #endif
  24. {
  25. PyErr_SetString(PyExc_TypeError, "Object has default comparison");
  26. return 0;
  27. }
  28. return 1;
  29. }
  30. #define TEST_KEY_SET_OR(V, KEY, TARGET) \
  31. if ( ( (V) = COMPARE((KEY),(TARGET)) ), PyErr_Occurred() )
  32. #define INCREF_KEY(k) Py_INCREF(k)
  33. #define DECREF_KEY(KEY) Py_DECREF(KEY)
  34. #define COPY_KEY(KEY, E) KEY=(E)
  35. #define COPY_KEY_TO_OBJECT(O, K) O=(K); Py_INCREF(O)
  36. #define COPY_KEY_FROM_ARG(TARGET, ARG, S) \
  37. TARGET=(ARG); \
  38. (S) = 1;
  39. #define KEY_CHECK_ON_SET check_argument_cmp