Panda3D
 All Classes Functions Variables Enumerations
py_panda.h
1 #ifndef PY_PANDA_H_
2 #define PY_PANDA_H_
3 // Filename: py_panda.h
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 //////////////////////////////////////////////////////////////////////////////////////////////
15 // Too do list ..
16 // We need a better dispatcher for the functions.. The behavior today is
17 // try one till it works or you run out of possibilities.. This is anything but optimal
18 // for performance and is treading on thin ice for function python or c++ will
19 // course there types to other types.
20 //
21 // The linking step will produce allot of warnings
22 // warning LNK4049: locally defined symbol..
23 //
24 // Get a second coder to review this file and the generated code ..
25 //
26 //////////////////////////////////////////////////////////////////////////////////////////////
27 #include <set>
28 #include <map>
29 #include <string>
30 
31 #ifdef USE_DEBUG_PYTHON
32 #define Py_DEBUG
33 #endif
34 
35 #ifndef NO_RUNTIME_TYPES
36 
37 #include "dtoolbase.h"
38 #include "typedObject.h"
39 #include "typeRegistry.h"
40 
41 #endif
42 
43 #include "pnotify.h"
44 
45 #if defined(HAVE_PYTHON) && !defined(CPPPARSER)
46 
47 #ifdef _POSIX_C_SOURCE
48 #undef _POSIX_C_SOURCE
49 #endif
50 
51 #define PY_SSIZE_T_CLEAN 1
52 
53 #include "Python.h"
54 #include "structmember.h"
55 
56 #ifndef HAVE_LONG_LONG
57 #define PyLong_FromLongLong(x) PyLong_FromLong((long) (x))
58 #define PyLong_FromUnsignedLongLong(x) PyLong_FromUnsignedLong((unsigned long) (x))
59 #define PyLong_AsLongLong(x) PyLong_AsLong(x)
60 #define PyLong_AsUnsignedLongLong(x) PyLong_AsUnsignedLong(x)
61 #define PyLong_AsUnsignedLongLongMask(x) PyLong_AsUnsignedLongMask(x)
62 #define PyLong_AsLongLongAndOverflow(x) PyLong_AsLongAndOverflow(x)
63 #endif
64 
65 #if PY_VERSION_HEX < 0x02050000
66 
67 // Prior to Python 2.5, we didn't have Py_ssize_t.
68 typedef int Py_ssize_t;
69 #define PyInt_FromSsize_t PyInt_FromLong
70 #define PyInt_AsSsize_t PyInt_AsLong
71 
72 #endif // PY_VERSION_HEX
73 
74 // 2.4 macros which aren't available in 2.3
75 #ifndef Py_RETURN_NONE
76 inline PyObject* doPy_RETURN_NONE()
77 { Py_INCREF(Py_None); return Py_None; }
78 #define Py_RETURN_NONE return doPy_RETURN_NONE()
79 #endif
80 
81 #ifndef Py_RETURN_TRUE
82 inline PyObject* doPy_RETURN_TRUE()
83 {Py_INCREF(Py_True); return Py_True;}
84 #define Py_RETURN_TRUE return doPy_RETURN_TRUE()
85 #endif
86 
87 #ifndef Py_RETURN_FALSE
88 inline PyObject* doPy_RETURN_FALSE()
89 {Py_INCREF(Py_False); return Py_False;}
90 #define Py_RETURN_FALSE return doPy_RETURN_FALSE()
91 #endif
92 
93 #ifndef PyVarObject_HEAD_INIT
94 #define PyVarObject_HEAD_INIT(type, size) \
95  PyObject_HEAD_INIT(type) size,
96 #endif
97 
98 #ifndef Py_TYPE
99 #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
100 #endif
101 
102 #ifndef Py_TPFLAGS_CHECKTYPES
103 // Always on in Python 3
104 #define Py_TPFLAGS_CHECKTYPES 0
105 #endif
106 
107 #if PY_MAJOR_VERSION >= 3
108 // For writing code that will compile in both versions.
109 #define nb_nonzero nb_bool
110 #define nb_divide nb_true_divide
111 #define nb_inplace_divide nb_inplace_true_divide
112 
113 #define PyLongOrInt_Check(x) PyLong_Check(x)
114 #define PyLongOrInt_FromSize_t PyLong_FromSize_t
115 #define PyLongOrInt_FromSsize_t PyLong_FromSsize_t
116 #define PyLongOrInt_FromLong PyLong_FromLong
117 #define PyLongOrInt_FromUnsignedLong PyLong_FromUnsignedLong
118 #define PyLongOrInt_AS_LONG PyLong_AS_LONG
119 #define PyInt_Check PyLong_Check
120 #define PyInt_AsLong PyLong_AsLong
121 #define PyInt_AS_LONG PyLong_AS_LONG
122 #else
123 #define PyLongOrInt_Check(x) (PyInt_Check(x) || PyLong_Check(x))
124 // PyInt_FromSize_t automatically picks the right type.
125 #define PyLongOrInt_FromSize_t PyInt_FromSize_t
126 #define PyLongOrInt_FromSsize_t PyInt_FromSsize_t
127 #define PyLongOrInt_FromLong PyInt_FromLong
128 #define PyLongOrInt_AS_LONG PyInt_AsLong
129 
130 // For more portably defining hash functions.
131 typedef long Py_hash_t;
132 #endif
133 
134 using namespace std;
135 
136 ///////////////////////////////////////////////////////////////////////////////////
137 // this is tempory .. untill this is glued better into the panda build system
138 ///////////////////////////////////////////////////////////////////////////////////
139 
140 #if defined(_WIN32) && !defined(LINK_ALL_STATIC)
141 #define EXPORT_THIS __declspec(dllexport)
142 #define IMPORT_THIS extern __declspec(dllimport)
143 #else
144 #define EXPORT_THIS
145 #define IMPORT_THIS extern
146 #endif
147 ///////////////////////////////////////////////////////////////////////////////////
148 
149 struct Dtool_PyTypedObject;
150 typedef std::map<int, Dtool_PyTypedObject *> RunTimeTypeDictionary;
151 typedef std::set<int> RunTimeTypeList;
152 
153 EXPCL_DTOOLCONFIG RunTimeTypeDictionary &GetRunTimeDictionary();
154 EXPCL_DTOOLCONFIG RunTimeTypeList &GetRunTimeTypeList();
155 
156 //////////////////////////////////////////////////////////
157 // used to stamp dtool instance..
158 #define PY_PANDA_SIGNATURE 0xbeaf
159 typedef void *(*UpcastFunction)(PyObject *,Dtool_PyTypedObject *);
160 typedef void *(*DowncastFunction)(void *, Dtool_PyTypedObject *);
161 
162 //inline Dtool_PyTypedObject * Dtool_RuntimeTypeDtoolType(int type);
163 //inline void Dtool_Deallocate_General(PyObject * self);
164 //inline int DTOOL_PyObject_Compare(PyObject *v1, PyObject *v2);
165 //
166 ////////////////////////////////////////////////////////////////////////
167 // THIS IS THE INSTANCE CONTAINER FOR ALL panda py objects....
168 ////////////////////////////////////////////////////////////////////////
169 struct Dtool_PyInstDef {
170  PyObject_HEAD
171 
172  // This is a pointer to the Dtool_PyTypedObject type. It's tempting
173  // not to store this and to instead use PY_TYPE(self) and upcast that,
174  // but that breaks when someone inherits from our class in Python.
175  struct Dtool_PyTypedObject *_My_Type;
176 
177  // Pointer to the underlying C++ object.
178  void *_ptr_to_object;
179 
180  // This is always set to PY_PANDA_SIGNATURE, so that we can quickly
181  // detect whether an object is a Panda object.
182  unsigned short _signature;
183 
184  // True if we own the pointer and should delete it or unref it.
185  bool _memory_rules;
186 
187  // True if this is a "const" pointer.
188  bool _is_const;
189 };
190 
191 ////////////////////////////////////////////////////////////////////////
192 // A Offset Dictionary Defining How to read the Above Object..
193 ////////////////////////////////////////////////////////////////////////
194 extern EXPCL_DTOOLCONFIG PyMemberDef standard_type_members[];
195 
196 ////////////////////////////////////////////////////////////////////////
197 // The Class Definition Structor For a Dtool python type.
198 ////////////////////////////////////////////////////////////////////////
199 struct Dtool_PyTypedObject {
200  // Standard Python Features..
201  PyTypeObject _PyType;
202 
203  // My Class Level Features..
204  UpcastFunction _Dtool_UpcastInterface; // The Upcast Function By Slot
205  DowncastFunction _Dtool_DowncastInterface; // The Downcast Function By Slot
206 
207  // May be TypeHandle::none() to indicate a non-TypedObject class.
208  TypeHandle _type;
209 
210  // some convenience functions..
211  inline PyTypeObject &As_PyTypeObject() { return _PyType; };
212  inline PyObject &As_PyObject() { return (PyObject &)_PyType; };
213 };
214 
215 // This is now simply a forward declaration. The actual definition is created
216 // by the code generator.
217 #define Define_Dtool_Class(MODULE_NAME, CLASS_NAME, PUBLIC_NAME) \
218  extern Dtool_PyTypedObject Dtool_##CLASS_NAME;
219 
220 ////////////////////////////////////////////////////////////////////////
221 // More Macro(s) to Implement class functions.. Usually used if C++ needs type information
222 ////////////////////////////////////////////////////////////////////////
223 #define Define_Dtool_new(CLASS_NAME,CNAME)\
224 PyObject *Dtool_new_##CLASS_NAME(PyTypeObject *type, PyObject *args, PyObject *kwds) {\
225  (void) args; (void) kwds;\
226  PyObject *self = type->tp_alloc(type, 0);\
227  ((Dtool_PyInstDef *)self)->_signature = PY_PANDA_SIGNATURE;\
228  ((Dtool_PyInstDef *)self)->_My_Type = &Dtool_##CLASS_NAME;\
229  return self;\
230 }
231 
232 // The following used to be in the above macro, but it doesn't seem to
233 // be necessary as tp_alloc memsets the object to 0.
234  //((Dtool_PyInstDef *)self)->_ptr_to_object = NULL;\
235  //((Dtool_PyInstDef *)self)->_memory_rules = false;\
236  //((Dtool_PyInstDef *)self)->_is_const = false;\
237 
238 ////////////////////////////////////////////////////////////////////////
239 /// Delete functions..
240 ////////////////////////////////////////////////////////////////////////
241 #ifdef NDEBUG
242 #define Define_Dtool_FreeInstance_Private(CLASS_NAME,CNAME)\
243 static void Dtool_FreeInstance_##CLASS_NAME(PyObject *self) {\
244  Py_TYPE(self)->tp_free(self);\
245 }
246 #else // NDEBUG
247 #define Define_Dtool_FreeInstance_Private(CLASS_NAME,CNAME)\
248 static void Dtool_FreeInstance_##CLASS_NAME(PyObject *self) {\
249  if (((Dtool_PyInstDef *)self)->_ptr_to_object != NULL) {\
250  if (((Dtool_PyInstDef *)self)->_memory_rules) {\
251  cerr << "Detected leak for " << #CLASS_NAME \
252  << " which interrogate cannot delete.\n"; \
253  }\
254  }\
255  Py_TYPE(self)->tp_free(self);\
256 }
257 #endif // NDEBUG
258 
259 #define Define_Dtool_FreeInstance(CLASS_NAME,CNAME)\
260 static void Dtool_FreeInstance_##CLASS_NAME(PyObject *self) {\
261  if (((Dtool_PyInstDef *)self)->_ptr_to_object != NULL) {\
262  if (((Dtool_PyInstDef *)self)->_memory_rules) {\
263  delete ((CNAME *)((Dtool_PyInstDef *)self)->_ptr_to_object);\
264  }\
265  }\
266  Py_TYPE(self)->tp_free(self);\
267 }
268 
269 #define Define_Dtool_FreeInstanceRef(CLASS_NAME,CNAME)\
270 static void Dtool_FreeInstance_##CLASS_NAME(PyObject *self) {\
271  if (((Dtool_PyInstDef *)self)->_ptr_to_object != NULL) {\
272  if (((Dtool_PyInstDef *)self)->_memory_rules) {\
273  unref_delete((CNAME *)((Dtool_PyInstDef *)self)->_ptr_to_object);\
274  }\
275  }\
276  Py_TYPE(self)->tp_free(self);\
277 }
278 
279 #define Define_Dtool_Simple_FreeInstance(CLASS_NAME, CNAME)\
280 static void Dtool_FreeInstance_##CLASS_NAME(PyObject *self) {\
281  ((Dtool_InstDef_##CLASS_NAME *)self)->_value.~##CLASS_NAME();\
282  Py_TYPE(self)->tp_free(self);\
283 }
284 
285 ////////////////////////////////////////////////////////////////////////
286 /// Simple Recognition Functions..
287 ////////////////////////////////////////////////////////////////////////
288 EXPCL_DTOOLCONFIG bool DtoolCanThisBeAPandaInstance(PyObject *self);
289 
290 ///////////////////////////////////////////////////////////////////////////////
291 // ** HACK ** allert..
292 //
293 // Need to keep a runtime type dictionary ... that is forward declared of typed object.
294 // We rely on the fact that typed objects are uniquly defined by an integer.
295 //
296 ///////////////////////////////////////////////////////////////////////////////
297 
298 EXPCL_DTOOLCONFIG void RegisterRuntimeClass(Dtool_PyTypedObject *otype, int class_id);
299 
300 ///////////////////////////////////////////////////////////////////////////////
301 ///////////////////////////////////////////////////////////////////////////////
302 EXPCL_DTOOLCONFIG Dtool_PyTypedObject *Dtool_RuntimeTypeDtoolType(int type);
303 
304 ////////////////////////////////////////////////////////////////////////
305 // Function : DTOOL_Call_ExtractThisPointerForType
306 //
307 // These are the wrappers that allow for down and upcast from type ..
308 // needed by the Dtool py interface.. Be very careful if you muck
309 // with these as the generated code depends on how this is set
310 // up..
311 ////////////////////////////////////////////////////////////////////////
312 EXPCL_DTOOLCONFIG void DTOOL_Call_ExtractThisPointerForType(PyObject *self, Dtool_PyTypedObject * classdef, void ** answer);
313 
314 EXPCL_DTOOLCONFIG void *DTOOL_Call_GetPointerThisClass(PyObject *self, Dtool_PyTypedObject *classdef, int param, const string &function_name, bool const_ok, bool report_errors);
315 
316 EXPCL_DTOOLCONFIG void *DTOOL_Call_GetPointerThis(PyObject *self);
317 
318 EXPCL_DTOOLCONFIG bool Dtool_Call_ExtractThisPointer(PyObject *self, Dtool_PyTypedObject &classdef, void **answer);
319 
320 EXPCL_DTOOLCONFIG bool Dtool_Call_ExtractThisPointer_NonConst(PyObject *self, Dtool_PyTypedObject &classdef,
321  void **answer, const char *method_name);
322 
323 template<class T> INLINE bool DTOOL_Call_ExtractThisPointer(PyObject *self, T *&into) {
324  if (DtoolCanThisBeAPandaInstance(self)) {
325  Dtool_PyTypedObject *target_class = Dtool_RuntimeTypeDtoolType(get_type_handle(T).get_index());
326  if (target_class != NULL) {
327  into = (T*) ((Dtool_PyInstDef *)self)->_My_Type->_Dtool_UpcastInterface(self, target_class);
328  return (into != NULL);
329  }
330  }
331  into = NULL;
332  return false;
333 }
334 
335 // Functions related to error reporting.
336 
337 #ifdef NDEBUG
338 // _PyErr_OCCURRED is an undocumented inline version of PyErr_Occurred.
339 #define Dtool_CheckErrorOccurred() (_PyErr_OCCURRED() != NULL)
340 #else
341 EXPCL_DTOOLCONFIG bool Dtool_CheckErrorOccurred();
342 #endif
343 
344 EXPCL_DTOOLCONFIG PyObject *Dtool_Raise_AssertionError();
345 EXPCL_DTOOLCONFIG PyObject *Dtool_Raise_TypeError(const char *message);
346 EXPCL_DTOOLCONFIG PyObject *Dtool_Raise_ArgTypeError(PyObject *obj, int param, const char *function_name, const char *type_name);
347 EXPCL_DTOOLCONFIG PyObject *Dtool_Raise_AttributeError(PyObject *obj, const char *attribute);
348 
349 EXPCL_DTOOLCONFIG PyObject *_Dtool_Raise_BadArgumentsError();
350 #ifdef NDEBUG
351 // Define it to a function that just prints a generic message.
352 #define Dtool_Raise_BadArgumentsError(x) _Dtool_Raise_BadArgumentsError()
353 #else
354 // Expand this to a TypeError listing all of the overloads.
355 #define Dtool_Raise_BadArgumentsError(x) Dtool_Raise_TypeError("Arguments must match:\n" x)
356 #endif
357 
358 EXPCL_DTOOLCONFIG PyObject *_Dtool_Return_None();
359 EXPCL_DTOOLCONFIG PyObject *Dtool_Return_Bool(bool value);
360 EXPCL_DTOOLCONFIG PyObject *_Dtool_Return(PyObject *value);
361 
362 #ifdef NDEBUG
363 #define Dtool_Return_None() (_PyErr_OCCURRED() != NULL ? NULL : (Py_INCREF(Py_None), Py_None))
364 #define Dtool_Return(value) (_PyErr_OCCURRED() != NULL ? NULL : value)
365 #else
366 #define Dtool_Return_None() _Dtool_Return_None()
367 #define Dtool_Return(value) _Dtool_Return(value)
368 #endif
369 
370 ////////////////////////////////////////////////////////////////////////
371 // Function : DTool_CreatePyInstanceTyped
372 //
373 // this function relies on the behavior of typed objects in the panda system.
374 //
375 ////////////////////////////////////////////////////////////////////////
376 EXPCL_DTOOLCONFIG PyObject *DTool_CreatePyInstanceTyped(void *local_this_in, Dtool_PyTypedObject &known_class_type, bool memory_rules, bool is_const, int RunTimeType);
377 
378 ////////////////////////////////////////////////////////////////////////
379 // DTool_CreatePyInstance .. wrapper function to finalize the existance of a general
380 // dtool py instance..
381 ////////////////////////////////////////////////////////////////////////
382 EXPCL_DTOOLCONFIG PyObject *DTool_CreatePyInstance(void *local_this, Dtool_PyTypedObject &in_classdef, bool memory_rules, bool is_const);
383 
384 // These template methods allow use when the Dtool_PyTypedObject is not known.
385 // They require a get_class_type() to be defined for the class.
386 template<class T> INLINE PyObject *DTool_CreatePyInstance(const T *obj, bool memory_rules) {
387  Dtool_PyTypedObject *known_class = Dtool_RuntimeTypeDtoolType(get_type_handle(T).get_index());
388  nassertr(known_class != NULL, NULL);
389  return DTool_CreatePyInstance((void*) obj, *known_class, memory_rules, true);
390 }
391 
392 template<class T> INLINE PyObject *DTool_CreatePyInstance(T *obj, bool memory_rules) {
393  Dtool_PyTypedObject *known_class = Dtool_RuntimeTypeDtoolType(get_type_handle(T).get_index());
394  nassertr(known_class != NULL, NULL);
395  return DTool_CreatePyInstance((void*) obj, *known_class, memory_rules, false);
396 }
397 
398 template<class T> INLINE PyObject *DTool_CreatePyInstanceTyped(const T *obj, bool memory_rules) {
399  Dtool_PyTypedObject *known_class = Dtool_RuntimeTypeDtoolType(get_type_handle(T).get_index());
400  nassertr(known_class != NULL, NULL);
401  return DTool_CreatePyInstanceTyped((void*) obj, *known_class, memory_rules, true, obj->get_type().get_index());
402 }
403 
404 template<class T> INLINE PyObject *DTool_CreatePyInstanceTyped(T *obj, bool memory_rules) {
405  Dtool_PyTypedObject *known_class = Dtool_RuntimeTypeDtoolType(get_type_handle(T).get_index());
406  nassertr(known_class != NULL, NULL);
407  return DTool_CreatePyInstanceTyped((void*) obj, *known_class, memory_rules, false, obj->get_type().get_index());
408 }
409 
410 ///////////////////////////////////////////////////////////////////////////////
411 // Macro(s) class definition .. Used to allocate storage and
412 // init some values for a Dtool Py Type object.
413 /////////////////////////////////////////////////////////////////////////////////
414 ///////////////////////////////////////////////////////////////////////////////
415 //struct Dtool_PyTypedObject Dtool_##CLASS_NAME;
416 
417 #define Define_Module_Class_Internal(MODULE_NAME,CLASS_NAME,CNAME)\
418 extern EXPORT_THIS Dtool_PyTypedObject Dtool_##CLASS_NAME;\
419 int Dtool_Init_##CLASS_NAME(PyObject *self, PyObject *args, PyObject *kwds);\
420 PyObject * Dtool_new_##CLASS_NAME(PyTypeObject *type, PyObject *args, PyObject *kwds);\
421 void * Dtool_UpcastInterface_##CLASS_NAME(PyObject *self, Dtool_PyTypedObject *requested_type);\
422 void * Dtool_DowncastInterface_##CLASS_NAME(void *self, Dtool_PyTypedObject *requested_type);
423 
424 ///////////////////////////////////////////////////////////////////////////////
425 #define Define_Module_Class(MODULE_NAME,CLASS_NAME,CNAME,PUBLIC_NAME)\
426 Define_Module_Class_Internal(MODULE_NAME,CLASS_NAME,CNAME)\
427 Define_Dtool_new(CLASS_NAME,CNAME)\
428 Define_Dtool_FreeInstance(CLASS_NAME,CNAME)\
429 Define_Dtool_Class(MODULE_NAME,CLASS_NAME,PUBLIC_NAME)
430 
431 ///////////////////////////////////////////////////////////////////////////////
432 #define Define_Module_Class_Private(MODULE_NAME,CLASS_NAME,CNAME,PUBLIC_NAME)\
433 Define_Module_Class_Internal(MODULE_NAME,CLASS_NAME,CNAME)\
434 Define_Dtool_new(CLASS_NAME,CNAME)\
435 Define_Dtool_FreeInstance_Private(CLASS_NAME,CNAME)\
436 Define_Dtool_Class(MODULE_NAME,CLASS_NAME,PUBLIC_NAME)
437 
438 ///////////////////////////////////////////////////////////////////////////////
439 #define Define_Module_ClassRef_Private(MODULE_NAME,CLASS_NAME,CNAME,PUBLIC_NAME)\
440 Define_Module_Class_Internal(MODULE_NAME,CLASS_NAME,CNAME)\
441 Define_Dtool_new(CLASS_NAME,CNAME)\
442 Define_Dtool_FreeInstance_Private(CLASS_NAME,CNAME)\
443 Define_Dtool_Class(MODULE_NAME,CLASS_NAME,PUBLIC_NAME)
444 
445 ///////////////////////////////////////////////////////////////////////////////
446 #define Define_Module_ClassRef(MODULE_NAME,CLASS_NAME,CNAME,PUBLIC_NAME)\
447 Define_Module_Class_Internal(MODULE_NAME,CLASS_NAME,CNAME)\
448 Define_Dtool_new(CLASS_NAME,CNAME)\
449 Define_Dtool_FreeInstanceRef(CLASS_NAME,CNAME)\
450 Define_Dtool_Class(MODULE_NAME,CLASS_NAME,PUBLIC_NAME)
451 
452 ///////////////////////////////////////////////////////////////////////////////
453 /// Th Finalizer for simple instances..
454 ///////////////////////////////////////////////////////////////////////////////
455 EXPCL_DTOOLCONFIG int DTool_PyInit_Finalize(PyObject *self, void *This, Dtool_PyTypedObject *type, bool memory_rules, bool is_const);
456 
457 ///////////////////////////////////////////////////////////////////////////////
458 /// A heler function to glu methed definition together .. that can not be done at
459 // code generation time becouse of multiple generation passes in interigate..
460 //
461 ///////////////////////////////////////////////////////////////////////////////
462 typedef std::map<std::string, PyMethodDef *> MethodDefmap;
463 
464 EXPCL_DTOOLCONFIG void Dtool_Accum_MethDefs(PyMethodDef in[], MethodDefmap &themap);
465 
466 ///////////////////////////////////////////////////////////////////////////////
467 //// We need a way to runtime merge compile units into a python "Module" .. this is done with the
468 /// fallowing structors and code.. along with the support of interigate_module
469 ///////////////////////////////////////////////////////////////////////////////
470 struct LibraryDef {
471  typedef void (*ConstantFunction)(PyObject *);
472 
473  PyMethodDef *_methods;
474  ConstantFunction _constants;
475 };
476 ///////////////////////////////////////////////////////////////////////////////
477 
478 #if PY_MAJOR_VERSION >= 3
479 EXPCL_DTOOLCONFIG PyObject *Dtool_PyModuleInitHelper(LibraryDef *defs[], PyModuleDef *module_def);
480 #else
481 EXPCL_DTOOLCONFIG PyObject *Dtool_PyModuleInitHelper(LibraryDef *defs[], const char *modulename);
482 #endif
483 
484 ///////////////////////////////////////////////////////////////////////////////
485 /// HACK.... Be carefull
486 //
487 // Dtool_BorrowThisReference
488 // This function can be used to grab the "THIS" pointer from an object and use it
489 // Required to support fom historical inharatence in the for of "is this instance of"..
490 //
491 ///////////////////////////////////////////////////////////////////////////////
492 EXPCL_DTOOLCONFIG PyObject *Dtool_BorrowThisReference(PyObject *self, PyObject *args);
493 
494 //////////////////////////////////////////////////////////////////////////////////////////////
495 // We do expose a dictionay for dtool classes .. this should be removed at some point..
496 //////////////////////////////////////////////////////////////////////////////////////////////
497 EXPCL_DTOOLCONFIG PyObject *Dtool_AddToDictionary(PyObject *self1, PyObject *args);
498 
499 ///////////////////////////////////////////////////////////////////////////////////
500 
501 EXPCL_DTOOLCONFIG Py_hash_t DTOOL_PyObject_HashPointer(PyObject *obj);
502 
503 /* Compare v to w. Return
504  -1 if v < w or exception (PyErr_Occurred() true in latter case).
505  0 if v == w.
506  1 if v > w.
507  XXX The docs (C API manual) say the return value is undefined in case
508  XXX of error.
509 */
510 
511 EXPCL_DTOOLCONFIG int DTOOL_PyObject_ComparePointers(PyObject *v1, PyObject *v2);
512 EXPCL_DTOOLCONFIG int DTOOL_PyObject_Compare(PyObject *v1, PyObject *v2);
513 
514 EXPCL_DTOOLCONFIG PyObject *DTOOL_PyObject_RichCompare(PyObject *v1, PyObject *v2, int op);
515 
516 EXPCL_DTOOLCONFIG PyObject *
517 make_list_for_item(PyObject *self, const char *num_name,
518  const char *element_name);
519 
520 EXPCL_DTOOLCONFIG PyObject *
521 copy_from_make_copy(PyObject *self);
522 
523 EXPCL_DTOOLCONFIG PyObject *
524 copy_from_copy_constructor(PyObject *self);
525 
526 EXPCL_DTOOLCONFIG PyObject *
527 map_deepcopy_to_copy(PyObject *self, PyObject *args);
528 
529 #if PY_MAJOR_VERSION < 3
530 // In the Python 3 case, it is defined as a macro, at the beginning of this file.
531 EXPCL_DTOOLCONFIG PyObject *
532 PyLongOrInt_FromUnsignedLong(unsigned long value);
533 #endif
534 
535 EXPCL_DTOOLCONFIG extern struct Dtool_PyTypedObject Dtool_DTOOL_SUPER_BASE;
536 EXPCL_DTOOLCONFIG extern void Dtool_PyModuleClassInit_DTOOL_SUPER_BASE(PyObject *module);
537 
538 #endif // HAVE_PYTHON && !CPPPARSER
539 
540 #endif // PY_PANDA_H_
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85