12 #ifdef USE_DEBUG_PYTHON 20 #if defined(HAVE_PYTHON) && !defined(CPPPARSER) 24 #include <structmember.h> 30 #if defined(_WIN32) && !defined(LINK_ALL_STATIC) 31 #define EXPORT_THIS __declspec(dllexport) 32 #define IMPORT_THIS extern __declspec(dllimport) 35 #define IMPORT_THIS extern 38 struct Dtool_PyTypedObject;
41 #define PY_PANDA_SIGNATURE 0xbeaf 42 typedef void *(*UpcastFunction)(PyObject *,Dtool_PyTypedObject *);
43 typedef void *(*DowncastFunction)(
void *, Dtool_PyTypedObject *);
44 typedef void *(*CoerceFunction)(PyObject *,
void *);
45 typedef void (*ModuleClassInitFunction)(PyObject *module);
48 struct Dtool_PyInstDef {
54 struct Dtool_PyTypedObject *_My_Type;
61 unsigned short _signature;
71 struct Dtool_PyTypedObject {
78 ModuleClassInitFunction _Dtool_ModuleClassInit;
80 UpcastFunction _Dtool_UpcastInterface;
81 DowncastFunction _Dtool_DowncastInterface;
83 CoerceFunction _Dtool_ConstCoerce;
84 CoerceFunction _Dtool_Coerce;
89 #define Define_Dtool_Class(MODULE_NAME, CLASS_NAME, PUBLIC_NAME) \ 90 extern Dtool_PyTypedObject Dtool_##CLASS_NAME; 94 #define Define_Dtool_new(CLASS_NAME,CNAME)\ 95 static PyObject *Dtool_new_##CLASS_NAME(PyTypeObject *type, PyObject *args, PyObject *kwds) {\ 96 (void) args; (void) kwds;\ 97 PyObject *self = type->tp_alloc(type, 0);\ 98 ((Dtool_PyInstDef *)self)->_signature = PY_PANDA_SIGNATURE;\ 99 ((Dtool_PyInstDef *)self)->_My_Type = &Dtool_##CLASS_NAME;\ 111 #define Define_Dtool_FreeInstance_Private(CLASS_NAME,CNAME)\ 112 static void Dtool_FreeInstance_##CLASS_NAME(PyObject *self) {\ 113 Py_TYPE(self)->tp_free(self);\ 116 #define Define_Dtool_FreeInstance_Private(CLASS_NAME,CNAME)\ 117 static void Dtool_FreeInstance_##CLASS_NAME(PyObject *self) {\ 118 if (DtoolInstance_VOID_PTR(self) != nullptr) {\ 119 if (((Dtool_PyInstDef *)self)->_memory_rules) {\ 120 std::cerr << "Detected leak for " << #CLASS_NAME \ 121 << " which interrogate cannot delete.\n"; \ 124 Py_TYPE(self)->tp_free(self);\ 128 #define Define_Dtool_FreeInstance(CLASS_NAME,CNAME)\ 129 static void Dtool_FreeInstance_##CLASS_NAME(PyObject *self) {\ 130 if (DtoolInstance_VOID_PTR(self) != nullptr) {\ 131 if (((Dtool_PyInstDef *)self)->_memory_rules) {\ 132 delete (CNAME *)DtoolInstance_VOID_PTR(self);\ 135 Py_TYPE(self)->tp_free(self);\ 138 #define Define_Dtool_FreeInstanceRef(CLASS_NAME,CNAME)\ 139 static void Dtool_FreeInstance_##CLASS_NAME(PyObject *self) {\ 140 if (DtoolInstance_VOID_PTR(self) != nullptr) {\ 141 if (((Dtool_PyInstDef *)self)->_memory_rules) {\ 142 unref_delete((CNAME *)DtoolInstance_VOID_PTR(self));\ 145 Py_TYPE(self)->tp_free(self);\ 148 #define Define_Dtool_FreeInstanceRef_Private(CLASS_NAME,CNAME)\ 149 static void Dtool_FreeInstance_##CLASS_NAME(PyObject *self) {\ 150 if (DtoolInstance_VOID_PTR(self) != nullptr) {\ 151 if (((Dtool_PyInstDef *)self)->_memory_rules) {\ 152 unref_delete((ReferenceCount *)(CNAME *)DtoolInstance_VOID_PTR(self));\ 155 Py_TYPE(self)->tp_free(self);\ 158 #define Define_Dtool_Simple_FreeInstance(CLASS_NAME, CNAME)\ 159 static void Dtool_FreeInstance_##CLASS_NAME(PyObject *self) {\ 160 ((Dtool_InstDef_##CLASS_NAME *)self)->_value.~##CLASS_NAME();\ 161 Py_TYPE(self)->tp_free(self);\ 165 #define DtoolInstance_Check(obj) \ 166 (Py_TYPE(obj)->tp_basicsize >= (int)sizeof(Dtool_PyInstDef) && \ 167 ((Dtool_PyInstDef *)obj)->_signature == PY_PANDA_SIGNATURE) 170 #define DtoolInstance_TYPE(obj) (((Dtool_PyInstDef *)obj)->_My_Type) 171 #define DtoolInstance_IS_CONST(obj) (((Dtool_PyInstDef *)obj)->_is_const) 172 #define DtoolInstance_VOID_PTR(obj) (((Dtool_PyInstDef *)obj)->_ptr_to_object) 173 #define DtoolInstance_INIT_PTR(obj, ptr) { ((Dtool_PyInstDef *)obj)->_ptr_to_object = (void*)(ptr); } 174 #define DtoolInstance_UPCAST(obj, type) (((Dtool_PyInstDef *)(obj))->_My_Type->_Dtool_UpcastInterface((obj), &(type))) 180 typedef std::map<std::string, Dtool_PyTypedObject *> Dtool_TypeMap;
182 EXPCL_PYPANDA Dtool_TypeMap *Dtool_GetGlobalTypeMap();
187 EXPCL_PYPANDA
void DTOOL_Call_ExtractThisPointerForType(PyObject *
self, Dtool_PyTypedObject *classdef,
void **answer);
189 EXPCL_PYPANDA
void *DTOOL_Call_GetPointerThisClass(PyObject *
self, Dtool_PyTypedObject *classdef,
int param,
const std::string &function_name,
bool const_ok,
bool report_errors);
191 EXPCL_PYPANDA
bool Dtool_Call_ExtractThisPointer(PyObject *
self, Dtool_PyTypedObject &classdef,
void **answer);
193 EXPCL_PYPANDA
bool Dtool_Call_ExtractThisPointer_NonConst(PyObject *
self, Dtool_PyTypedObject &classdef,
194 void **answer,
const char *method_name);
204 EXPCL_PYPANDA
bool _Dtool_CheckErrorOccurred();
207 #define Dtool_CheckErrorOccurred() (UNLIKELY(_PyErr_OCCURRED() != nullptr)) 209 #define Dtool_CheckErrorOccurred() (UNLIKELY(_Dtool_CheckErrorOccurred())) 212 EXPCL_PYPANDA PyObject *Dtool_Raise_AssertionError();
213 EXPCL_PYPANDA PyObject *Dtool_Raise_TypeError(
const char *message);
214 EXPCL_PYPANDA PyObject *Dtool_Raise_ArgTypeError(PyObject *obj,
int param,
const char *function_name,
const char *type_name);
215 EXPCL_PYPANDA PyObject *Dtool_Raise_AttributeError(PyObject *obj,
const char *attribute);
217 EXPCL_PYPANDA PyObject *_Dtool_Raise_BadArgumentsError();
220 #define Dtool_Raise_BadArgumentsError(x) _Dtool_Raise_BadArgumentsError() 223 #define Dtool_Raise_BadArgumentsError(x) Dtool_Raise_TypeError("Arguments must match:\n" x) 229 EXPCL_PYPANDA PyObject *_Dtool_Return_None();
230 EXPCL_PYPANDA PyObject *Dtool_Return_Bool(
bool value);
231 EXPCL_PYPANDA PyObject *_Dtool_Return(PyObject *value);
234 #define Dtool_Return_None() (LIKELY(_PyErr_OCCURRED() == nullptr) ? (Py_INCREF(Py_None), Py_None) : nullptr) 235 #define Dtool_Return(value) (LIKELY(_PyErr_OCCURRED() == nullptr) ? value : nullptr) 237 #define Dtool_Return_None() _Dtool_Return_None() 238 #define Dtool_Return(value) _Dtool_Return(value) 244 EXPCL_PYPANDA PyTypeObject *Dtool_EnumType_Create(
const char *name, PyObject *names,
245 const char *module =
nullptr);
252 EXPCL_PYPANDA PyObject *DTool_CreatePyInstanceTyped(
void *local_this_in, Dtool_PyTypedObject &known_class_type,
bool memory_rules,
bool is_const,
int RunTimeType);
256 EXPCL_PYPANDA PyObject *
DTool_CreatePyInstance(
void *local_this, Dtool_PyTypedObject &in_classdef,
bool memory_rules,
bool is_const);
262 template<
class T> INLINE PyObject *DTool_CreatePyInstanceTyped(
const T *obj,
bool memory_rules);
263 template<
class T> INLINE PyObject *DTool_CreatePyInstanceTyped(T *obj,
bool memory_rules);
270 #define Define_Module_Class_Internal(MODULE_NAME,CLASS_NAME,CNAME)\ 271 extern struct Dtool_PyTypedObject Dtool_##CLASS_NAME;\ 272 static int Dtool_Init_##CLASS_NAME(PyObject *self, PyObject *args, PyObject *kwds);\ 273 static PyObject *Dtool_new_##CLASS_NAME(PyTypeObject *type, PyObject *args, PyObject *kwds); 275 #define Define_Module_Class(MODULE_NAME,CLASS_NAME,CNAME,PUBLIC_NAME)\ 276 Define_Module_Class_Internal(MODULE_NAME,CLASS_NAME,CNAME)\ 277 Define_Dtool_new(CLASS_NAME,CNAME)\ 278 Define_Dtool_FreeInstance(CLASS_NAME,CNAME)\ 279 Define_Dtool_Class(MODULE_NAME,CLASS_NAME,PUBLIC_NAME) 281 #define Define_Module_Class_Private(MODULE_NAME,CLASS_NAME,CNAME,PUBLIC_NAME)\ 282 Define_Module_Class_Internal(MODULE_NAME,CLASS_NAME,CNAME)\ 283 Define_Dtool_new(CLASS_NAME,CNAME)\ 284 Define_Dtool_FreeInstance_Private(CLASS_NAME,CNAME)\ 285 Define_Dtool_Class(MODULE_NAME,CLASS_NAME,PUBLIC_NAME) 287 #define Define_Module_ClassRef_Private(MODULE_NAME,CLASS_NAME,CNAME,PUBLIC_NAME)\ 288 Define_Module_Class_Internal(MODULE_NAME,CLASS_NAME,CNAME)\ 289 Define_Dtool_new(CLASS_NAME,CNAME)\ 290 Define_Dtool_FreeInstanceRef_Private(CLASS_NAME,CNAME)\ 291 Define_Dtool_Class(MODULE_NAME,CLASS_NAME,PUBLIC_NAME) 293 #define Define_Module_ClassRef(MODULE_NAME,CLASS_NAME,CNAME,PUBLIC_NAME)\ 294 Define_Module_Class_Internal(MODULE_NAME,CLASS_NAME,CNAME)\ 295 Define_Dtool_new(CLASS_NAME,CNAME)\ 296 Define_Dtool_FreeInstanceRef(CLASS_NAME,CNAME)\ 297 Define_Dtool_Class(MODULE_NAME,CLASS_NAME,PUBLIC_NAME) 300 INLINE
int DTool_PyInit_Finalize(PyObject *
self,
void *This, Dtool_PyTypedObject *type,
bool memory_rules,
bool is_const);
305 typedef std::map<std::string, PyMethodDef *> MethodDefmap;
311 struct Dtool_TypeDef {
312 const char *
const name;
313 Dtool_PyTypedObject *type;
317 PyMethodDef *
const _methods;
318 const Dtool_TypeDef *
const _types;
319 Dtool_TypeDef *
const _external_types;
322 #if PY_MAJOR_VERSION >= 3 323 EXPCL_PYPANDA PyObject *Dtool_PyModuleInitHelper(
const LibraryDef *defs[], PyModuleDef *module_def);
325 EXPCL_PYPANDA PyObject *Dtool_PyModuleInitHelper(
const LibraryDef *defs[],
const char *modulename);
331 EXPCL_PYPANDA PyObject *Dtool_BorrowThisReference(PyObject *
self, PyObject *args);
333 #define DTOOL_PyObject_HashPointer DtoolInstance_HashPointer 334 #define DTOOL_PyObject_ComparePointers DtoolInstance_ComparePointers 336 EXPCL_PYPANDA PyObject *
337 copy_from_make_copy(PyObject *
self, PyObject *noargs);
339 EXPCL_PYPANDA PyObject *
340 copy_from_copy_constructor(PyObject *
self, PyObject *noargs);
342 EXPCL_PYPANDA PyObject *
343 map_deepcopy_to_copy(PyObject *
self, PyObject *args);
351 EXPCL_PYPANDA
bool Dtool_ExtractArg(PyObject **result, PyObject *args,
352 PyObject *kwds,
const char *keyword);
353 EXPCL_PYPANDA
bool Dtool_ExtractArg(PyObject **result, PyObject *args,
355 EXPCL_PYPANDA
bool Dtool_ExtractOptionalArg(PyObject **result, PyObject *args,
356 PyObject *kwds,
const char *keyword);
357 EXPCL_PYPANDA
bool Dtool_ExtractOptionalArg(PyObject **result, PyObject *args,
386 #if PY_MAJOR_VERSION >= 0x02060000 390 template<
class T1,
class T2>
391 ALWAYS_INLINE PyObject *
Dtool_WrapValue(
const std::pair<T1, T2> &value);
393 EXPCL_PYPANDA Dtool_PyTypedObject *Dtool_GetSuperBase();
399 #endif // HAVE_PYTHON && !CPPPARSER 401 #endif // PY_PANDA_H_ PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Py_hash_t DtoolInstance_HashPointer(PyObject *self)
Function to create a hash from a wrapped Python object.
bool Dtool_CheckNoArgs(PyObject *args)
Checks that the tuple is empty.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
long Dtool_EnumValue_AsLong(PyObject *value)
Converts the enum value to a C long.
PyObject * DtoolInstance_RichComparePointers(PyObject *v1, PyObject *v2, int op)
Rich comparison function that compares objects by pointer.
PyObject * Dtool_WrapValue(int value)
The following functions wrap an arbitrary C++ value into a PyObject.
PyObject * DTool_CreatePyInstance(const T *obj, bool memory_rules)
These functions wrap a pointer for a class that defines get_type_handle().
int DtoolInstance_ComparePointers(PyObject *v1, PyObject *v2)
Python 2-style comparison function that compares objects by pointer.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
int DTool_PyInit_Finalize(PyObject *self, void *local_this, Dtool_PyTypedObject *type, bool memory_rules, bool is_const)
Finishes initializing the Dtool_PyInstDef.
TypeHandle is the identifier used to differentiate C++ class types.
bool DtoolInstance_GetPointer(PyObject *self, T *&into)
Template function that can be used to extract any TypedObject pointer from a wrapped Python object.