/client/common/Python-dynload.h

https://github.com/n1nj4sec/pupy · C Header · 219 lines · 155 code · 54 blank · 10 comment · 9 complexity · e0e173f99d7b0ac46ef5f31f03c1ddf7 MD5 · raw file

  1. /*
  2. WARNING !
  3. DEPENDS ON PYTHON ABI!
  4. */
  5. #ifndef PYTHON_DYNLOAD_H
  6. #define PYTHON_DYNLOAD_H
  7. #include <stdint.h>
  8. #include <string.h>
  9. #include <sys/types.h>
  10. #define CO_MAXBLOCKS 20
  11. typedef void *PyObject;
  12. typedef struct {
  13. int b_type;
  14. int b_handler;
  15. int b_level;
  16. } PyTryBlock;
  17. typedef PyObject *(*PyCFunction)(PyObject *, PyObject *);
  18. typedef
  19. enum {PyGILState_LOCKED, PyGILState_UNLOCKED}
  20. PyGILState_STATE;
  21. typedef struct {
  22. char *ml_name;
  23. PyCFunction ml_meth;
  24. int ml_flags;
  25. char *ml_doc;
  26. } PyMethodDef;
  27. struct py_imports {
  28. char *name;
  29. void (*proc)();
  30. };
  31. #if defined(_MSC_VER) && _MSC_VER < 1600
  32. #ifdef _WIN64
  33. #define ssize_t signed long long
  34. #else
  35. #define ssize_t signed long
  36. #endif
  37. #endif
  38. #ifndef Py_ssize_t
  39. #define Py_ssize_t ssize_t
  40. #endif
  41. #ifndef BOOL
  42. typedef int BOOL;
  43. #define TRUE 1
  44. #define FALSE 0
  45. #endif
  46. #ifndef Py_INCREF
  47. #define Py_INCREF Py_IncRef
  48. #endif
  49. #ifndef Py_DECREF
  50. #define Py_DECREF Py_DecRef
  51. #endif
  52. #ifndef Py_XINCREF
  53. #define Py_XINCREF(op) do { if ((op) == NULL) ; else Py_INCREF(op); } while (0)
  54. #endif
  55. #ifndef Py_XDECREF
  56. #define Py_XDECREF(op) do { if ((op) == NULL) ; else Py_DECREF(op); } while (0)
  57. #endif
  58. #ifdef _WIN32
  59. #define snprintf _snprintf
  60. #endif
  61. #define METH_OLDARGS 0x0000
  62. #define METH_VARARGS 0x0001
  63. #define METH_KEYWORDS 0x0002
  64. /* METH_NOARGS and METH_O must not be combined with the flags above. */
  65. #define METH_NOARGS 0x0004
  66. #define METH_O 0x0008
  67. /* METH_CLASS and METH_STATIC are a little different; these control
  68. the construction of methods for a class. These cannot be used for
  69. functions in modules. */
  70. #define METH_CLASS 0x0010
  71. #define METH_STATIC 0x0020
  72. #define PyCFunction_New(ML, SELF) PyCFunction_NewEx((ML), (SELF), NULL)
  73. #define PyInt_Check(op) PyObject_IsInstance(op, &PyInt_Type) /* ??? */
  74. #define Py_None (&_Py_NoneStruct)
  75. #define DL_EXPORT(x) x
  76. #define PYTHON_API_VERSION 1013
  77. #define Py_InitModule3(name, methods, doc) \
  78. Py_InitModule4(name, methods, doc, (PyObject *)NULL, \
  79. PYTHON_API_VERSION)
  80. int Py_RefCnt(const PyObject *object);
  81. extern struct py_imports py_sym_table[];
  82. BOOL initialize_python(int argc, char *argv[], BOOL is_shared_object);
  83. void run_pupy(void);
  84. void deinitialize_python(void);
  85. #define VPATH_PREFIX "pupy://"
  86. #define VPATH_EXT ".pyo"
  87. typedef struct {
  88. Py_ssize_t ob_refcnt;
  89. struct _typeobject *ob_type;
  90. int co_argcount;
  91. int co_nlocals;
  92. int co_stacksize;
  93. int co_flags;
  94. PyObject *co_code;
  95. PyObject *co_consts;
  96. PyObject *co_names;
  97. PyObject *co_varnames;
  98. PyObject *co_freevars;
  99. PyObject *co_cellvars;
  100. PyObject *co_filename;
  101. PyObject *co_name;
  102. int co_firstlineno;
  103. PyObject *co_lnotab;
  104. void *co_zombieframe;
  105. PyObject *co_weakreflist;
  106. } PyCodeObject;
  107. typedef struct _is {
  108. struct _is *next;
  109. struct _ts *tstate_head;
  110. PyObject *modules;
  111. PyObject *sysdict;
  112. PyObject *builtins;
  113. PyObject *modules_reloading;
  114. PyObject *codec_search_path;
  115. PyObject *codec_search_cache;
  116. PyObject *codec_error_registry;
  117. /* PRIVATE PART OMITTED */
  118. } PyInterpreterState;
  119. struct _frame;
  120. typedef struct _ts {
  121. struct _ts *next;
  122. PyInterpreterState *interp;
  123. struct _frame *frame;
  124. int recursion_depth;
  125. int tracing;
  126. int use_tracing;
  127. void *c_profilefunc;
  128. void *c_tracefunc;
  129. PyObject *c_profileobj;
  130. PyObject *c_traceobj;
  131. PyObject *curexc_type;
  132. PyObject *curexc_value;
  133. PyObject *curexc_traceback;
  134. PyObject *exc_type;
  135. PyObject *exc_value;
  136. PyObject *exc_traceback;
  137. PyObject *dict;
  138. int tick_counter;
  139. int gilstate_counter;
  140. PyObject *async_exc;
  141. long thread_id;
  142. int trash_delete_nesting;
  143. PyObject *trash_delete_later;
  144. } PyThreadState;
  145. typedef struct _frame {
  146. Py_ssize_t ob_refcnt;
  147. struct _typeobject *ob_type;
  148. Py_ssize_t ob_size;
  149. struct _frame *f_back;
  150. PyCodeObject *f_code;
  151. PyObject *f_builtins;
  152. PyObject *f_globals;
  153. PyObject *f_locals;
  154. PyObject **f_valuestack;
  155. PyObject **f_stacktop;
  156. PyObject *f_trace;
  157. PyObject *f_exc_type, *f_exc_value, *f_exc_traceback;
  158. PyThreadState *f_tstate;
  159. int f_lasti;
  160. int f_lineno;
  161. int f_iblock;
  162. /* PRIVATE */
  163. } PyFrameObject;
  164. #include "import-tab.h"
  165. #endif // PYTHON_DYNLOAD_H