Skip to content

Commit 26de766

Browse files
committed
Split off some py_panda.h functions to py_support.h
Slim down py_panda.h to just the things that extension modules might also need, whereas py_support.h may contain things internal to interrogate. Right now py_panda.h is shared with the Panda3D codebase so the smaller it is, the better
1 parent 14d16e4 commit 26de766

File tree

8 files changed

+954
-911
lines changed

8 files changed

+954
-911
lines changed

src/interrogate/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,16 @@ set(INTERROGATE_SOURCES
5454
set(INTERROGATE_PREAMBLE_PYTHON_NATIVE_HEADERS
5555
../interrogatedb/py_panda.h
5656
../interrogatedb/py_panda.I
57+
../interrogatedb/py_support.h
58+
../interrogatedb/py_support.I
5759
../interrogatedb/py_compat.h
5860
../interrogatedb/py_wrappers.h
5961
../interrogatedb/extension.h
6062
)
6163

6264
set(INTERROGATE_PREAMBLE_PYTHON_NATIVE_SOURCES
6365
../interrogatedb/py_panda.cxx
66+
../interrogatedb/py_support.cxx
6467
../interrogatedb/py_compat.cxx
6568
../interrogatedb/py_wrappers.cxx
6669
../interrogatedb/dtool_super_base.cxx
@@ -81,9 +84,6 @@ foreach(_file ${INTERROGATE_PREAMBLE_PYTHON_NATIVE_SOURCES})
8184
list(APPEND _preamble_sources "${_file}")
8285
endforeach(_file)
8386

84-
message(WARN "${_preamble_headers}")
85-
message(WARN "${_preamble_sources}")
86-
8787
add_custom_command(
8888
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/interrogate_preamble_python_native.h
8989
COMMAND ${CMAKE_COMMAND}

src/interrogatedb/py_panda.I

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -59,63 +59,6 @@ DtoolInstance_GetPointer(PyObject *self, T *&into, Dtool_PyTypedObject &target_c
5959
return false;
6060
}
6161

62-
/**
63-
* Function to create a hash from a wrapped Python object.
64-
*/
65-
INLINE Py_hash_t DtoolInstance_HashPointer(PyObject *self) {
66-
if (self != nullptr && DtoolInstance_Check(self)) {
67-
return (Py_hash_t)(intptr_t)DtoolInstance_VOID_PTR(self);
68-
}
69-
return -1;
70-
}
71-
72-
/**
73-
* Python 2-style comparison function that compares objects by pointer.
74-
*/
75-
INLINE int DtoolInstance_ComparePointers(PyObject *v1, PyObject *v2) {
76-
void *v1_this = DtoolInstance_Check(v1) ? DtoolInstance_VOID_PTR(v1) : nullptr;
77-
void *v2_this = DtoolInstance_Check(v2) ? DtoolInstance_VOID_PTR(v2) : nullptr;
78-
if (v1_this != nullptr && v2_this != nullptr) {
79-
return (v1_this > v2_this) - (v1_this < v2_this);
80-
} else {
81-
return (v1 > v2) - (v1 < v2);
82-
}
83-
}
84-
85-
/**
86-
* Rich comparison function that compares objects by pointer.
87-
*/
88-
INLINE PyObject *DtoolInstance_RichComparePointers(PyObject *v1, PyObject *v2, int op) {
89-
int cmpval = DtoolInstance_ComparePointers(v1, v2);
90-
Py_RETURN_RICHCOMPARE(cmpval, 0, op);
91-
}
92-
93-
/**
94-
* Utility function for assigning a PyObject pointer while managing refcounts.
95-
*/
96-
ALWAYS_INLINE void
97-
Dtool_Assign_PyObject(PyObject *&ptr, PyObject *value) {
98-
PyObject *prev_value = ptr;
99-
if (prev_value != value) {
100-
ptr = Py_XNewRef(value);
101-
Py_XDECREF(prev_value);
102-
}
103-
}
104-
105-
/**
106-
* Converts the enum value to a C long.
107-
*/
108-
INLINE long Dtool_EnumValue_AsLong(PyObject *value) {
109-
PyObject *val = PyObject_GetAttrString(value, "value");
110-
if (val != nullptr) {
111-
long as_long = PyLongOrInt_AS_LONG(val);
112-
Py_DECREF(val);
113-
return as_long;
114-
} else {
115-
return -1;
116-
}
117-
}
118-
11962
/**
12063
* These functions wrap a pointer for a class that defines get_type_handle().
12164
*/
@@ -167,23 +110,6 @@ DTool_PyInit_Finalize(PyObject *self, void *local_this, Dtool_PyTypedObject *typ
167110
return 0;
168111
}
169112

170-
/**
171-
* Checks that the tuple is empty.
172-
*/
173-
ALWAYS_INLINE bool
174-
Dtool_CheckNoArgs(PyObject *args) {
175-
return PyTuple_GET_SIZE(args) == 0;
176-
}
177-
178-
/**
179-
* Checks that the tuple is empty, and that the dict is empty or NULL.
180-
*/
181-
ALWAYS_INLINE bool
182-
Dtool_CheckNoArgs(PyObject *args, PyObject *kwds) {
183-
return PyTuple_GET_SIZE(args) == 0 &&
184-
(kwds == nullptr || PyDict_GET_SIZE(kwds) == 0);
185-
}
186-
187113
/**
188114
* The following functions wrap an arbitrary C++ value into a PyObject.
189115
*/

0 commit comments

Comments
 (0)