/src/libpython_clj/jna/concrete/cfunction.clj

https://github.com/cnuernber/libpython-clj · Clojure · 76 lines · 41 code · 16 blank · 19 comment · 0 complexity · 6ce749de6127ad5aaac28116affe23bb MD5 · raw file

  1. (ns libpython-clj.jna.concrete.cfunction
  2. (:require [libpython-clj.jna.base
  3. :refer [def-pylib-fn
  4. ensure-pyobj
  5. as-pyobj
  6. ensure-pytuple
  7. ensure-pydict
  8. size-t-type
  9. *python-library*]
  10. :as libpy-base]
  11. [tech.jna :as jna])
  12. (:import [com.sun.jna CallbackReference Pointer Callback]
  13. [libpython_clj.jna
  14. CFunction$KeyWordFunction
  15. CFunction$TupleFunction
  16. PyMethodDef
  17. PyObject]))
  18. ;; #define METH_OLDARGS 0x0000 -- unsupported now
  19. (def METH_VARARGS 0x0001)
  20. (def METH_KEYWORDS 0x0002)
  21. ;; METH_NOARGS and METH_O must not be combined with the flags above.
  22. (def METH_NOARGS 0x0004)
  23. (def METH_O 0x0008)
  24. ;; /* METH_CLASS and METH_STATIC are a little different; these control
  25. ;; the construction of methods for a class. These cannot be used for
  26. ;; functions in modules. */
  27. (def METH_CLASS 0x0010)
  28. (def METH_STATIC 0x0020)
  29. ;; /* METH_COEXIST allows a method to be entered even though a slot has
  30. ;; already filled the entry. When defined, the flag allows a separate
  31. ;; method, "__contains__" for example, to coexist with a defined
  32. ;; slot like sq_contains. */
  33. (def METH_COEXIST 0x0040)
  34. ;; We aren't going there for either of these...
  35. ;; #ifndef Py_LIMITED_API
  36. ;; #define METH_FASTCALL 0x0080
  37. ;; #endif
  38. ;; /* This bit is preserved for Stackless Python */
  39. ;; #ifdef STACKLESS
  40. ;; #define METH_STACKLESS 0x0100
  41. ;; #else
  42. ;; #define METH_STACKLESS 0x0000
  43. ;; #endif
  44. (def-pylib-fn PyCFunction_NewEx
  45. "Create a new callable from an item."
  46. Pointer
  47. [method-def (partial jna/ensure-type PyMethodDef)]
  48. [self as-pyobj]
  49. [module as-pyobj])
  50. (def-pylib-fn PyInstanceMethod_New
  51. "Return value: New reference.
  52. Return a new instance method object, with func being any callable object func is the
  53. function that will be called when the instance method is called."
  54. Pointer
  55. [func ensure-pyobj])
  56. (def-pylib-fn PyInstanceMethod_Function
  57. "Return value: Borrowed reference.
  58. Return the function object associated with the instance method im."
  59. Pointer
  60. [im ensure-pyobj])