Panda3D
Loading...
Searching...
No Matches
dtool_super_base.cxx
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file dtool_super_base.cxx
10 * @author drose
11 * @date 2005-07-04
12 */
13
14#include "py_panda.h"
15
16#ifdef HAVE_PYTHON
17
18static PyMemberDef standard_type_members[] = {
19 {(char *)"this", (sizeof(void*) == sizeof(int)) ? T_UINT : T_ULONGLONG, offsetof(Dtool_PyInstDef, _ptr_to_object), READONLY, (char *)"C++ 'this' pointer, if any"},
20 {(char *)"this_ownership", T_BOOL, offsetof(Dtool_PyInstDef, _memory_rules), READONLY, (char *)"C++ 'this' ownership rules"},
21 {(char *)"this_const", T_BOOL, offsetof(Dtool_PyInstDef, _is_const), READONLY, (char *)"C++ 'this' const flag"},
22// {(char *)"this_signature", T_INT, offsetof(Dtool_PyInstDef, _signature),
23// READONLY, (char *)"A type check signature"},
24 {(char *)"this_metatype", T_OBJECT, offsetof(Dtool_PyInstDef, _My_Type), READONLY, (char *)"The dtool meta object"},
25 {nullptr} /* Sentinel */
26};
27
28static PyObject *GetSuperBase(PyObject *self) {
29 Dtool_PyTypedObject *super_base = Dtool_GetSuperBase();
30 Py_XINCREF((PyTypeObject *)super_base); // order is important .. this is used for static functions
31 return (PyObject *)super_base;
32};
33
34static void Dtool_PyModuleClassInit_DTOOL_SUPER_BASE(PyObject *module) {
35 if (module != nullptr) {
36 Dtool_PyTypedObject *super_base = Dtool_GetSuperBase();
37 Py_INCREF((PyTypeObject *)&super_base);
38 PyModule_AddObject(module, "DTOOL_SUPER_BASE", (PyObject *)&super_base);
39 }
40}
41
42static void *Dtool_DowncastInterface_DTOOL_SUPER_BASE(void *from_this, Dtool_PyTypedObject *from_type) {
43 return nullptr;
44}
45
46static void *Dtool_UpcastInterface_DTOOL_SUPER_BASE(PyObject *self, Dtool_PyTypedObject *requested_type) {
47 return nullptr;
48}
49
50static int Dtool_Init_DTOOL_SUPER_BASE(PyObject *self, PyObject *args, PyObject *kwds) {
51 assert(self != nullptr);
52 PyErr_Format(PyExc_TypeError, "cannot init constant class %s", Py_TYPE(self)->tp_name);
53 return -1;
54}
55
56static void Dtool_FreeInstance_DTOOL_SUPER_BASE(PyObject *self) {
57 Py_TYPE(self)->tp_free(self);
58}
59
60/**
61 * Returns a pointer to the DTOOL_SUPER_BASE class that is the base class of
62 * all Panda types. This pointer is shared by all modules.
63 */
64Dtool_PyTypedObject *Dtool_GetSuperBase() {
65 Dtool_TypeMap *type_map = Dtool_GetGlobalTypeMap();
66 auto it = type_map->find("DTOOL_SUPER_BASE");
67 if (it != type_map->end()) {
68 return it->second;
69 }
70
71 static PyMethodDef methods[] = {
72 { "DtoolGetSuperBase", (PyCFunction)&GetSuperBase, METH_NOARGS, "Will Return SUPERbase Class"},
73 { nullptr, nullptr, 0, nullptr }
74 };
75
76 static Dtool_PyTypedObject super_base_type = {
77 {
78 PyVarObject_HEAD_INIT(nullptr, 0)
79 "dtoolconfig.DTOOL_SUPER_BASE",
80 sizeof(Dtool_PyInstDef),
81 0, // tp_itemsize
82 &Dtool_FreeInstance_DTOOL_SUPER_BASE,
83 0, // tp_vectorcall_offset
84 nullptr, // tp_getattr
85 nullptr, // tp_setattr
86#if PY_MAJOR_VERSION >= 3
87 nullptr, // tp_compare
88#else
90#endif
91 nullptr, // tp_repr
92 nullptr, // tp_as_number
93 nullptr, // tp_as_sequence
94 nullptr, // tp_as_mapping
96 nullptr, // tp_call
97 nullptr, // tp_str
98 PyObject_GenericGetAttr,
99 PyObject_GenericSetAttr,
100 nullptr, // tp_as_buffer
101 (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_CHECKTYPES),
102 nullptr, // tp_doc
103 nullptr, // tp_traverse
104 nullptr, // tp_clear
105#if PY_MAJOR_VERSION >= 3
107#else
108 nullptr, // tp_richcompare
109#endif
110 0, // tp_weaklistoffset
111 nullptr, // tp_iter
112 nullptr, // tp_iternext
113 methods,
114 standard_type_members,
115 nullptr, // tp_getset
116 nullptr, // tp_base
117 nullptr, // tp_dict
118 nullptr, // tp_descr_get
119 nullptr, // tp_descr_set
120 0, // tp_dictoffset
121 Dtool_Init_DTOOL_SUPER_BASE,
122 PyType_GenericAlloc,
123 nullptr, // tp_new
124 PyObject_Del,
125 nullptr, // tp_is_gc
126 nullptr, // tp_bases
127 nullptr, // tp_mro
128 nullptr, // tp_cache
129 nullptr, // tp_subclasses
130 nullptr, // tp_weaklist
131 nullptr, // tp_del
132 0, // tp_version_tag,
133#if PY_VERSION_HEX >= 0x03040000
134 nullptr, // tp_finalize
135#endif
136#if PY_VERSION_HEX >= 0x03080000
137 nullptr, // tp_vectorcall
138#endif
139 },
140 TypeHandle::none(),
141 Dtool_PyModuleClassInit_DTOOL_SUPER_BASE,
142 Dtool_UpcastInterface_DTOOL_SUPER_BASE,
143 Dtool_DowncastInterface_DTOOL_SUPER_BASE,
144 nullptr,
145 nullptr,
146 };
147
148 super_base_type._PyType.tp_dict = PyDict_New();
149 PyDict_SetItemString(super_base_type._PyType.tp_dict, "DtoolClassDict", super_base_type._PyType.tp_dict);
150
151 if (PyType_Ready((PyTypeObject *)&super_base_type) < 0) {
152 PyErr_SetString(PyExc_TypeError, "PyType_Ready(Dtool_DTOOL_SUPER_BASE)");
153 return nullptr;
154 }
155 Py_INCREF((PyTypeObject *)&super_base_type);
156
157 PyDict_SetItemString(super_base_type._PyType.tp_dict, "DtoolGetSuperBase", PyCFunction_New(&methods[0], (PyObject *)&super_base_type));
158
159 (*type_map)["DTOOL_SUPER_BASE"] = &super_base_type;
160 return &super_base_type;
161}
162
163#endif // HAVE_PYTHON
int DtoolInstance_ComparePointers(PyObject *v1, PyObject *v2)
Python 2-style comparison function that compares objects by pointer.
Definition py_panda.I:75
PyObject * DtoolInstance_RichComparePointers(PyObject *v1, PyObject *v2, int op)
Rich comparison function that compares objects by pointer.
Definition py_panda.I:88
Py_hash_t DtoolInstance_HashPointer(PyObject *self)
Function to create a hash from a wrapped Python object.
Definition py_panda.I:65