Remove references to Python.h and py_config.h from Panda headers, to prevent picking up a dependency on Python libraries in third-party modules

This commit is contained in:
rdb 2015-11-28 16:33:03 +01:00
parent e5fac610c8
commit bdf91e206d
23 changed files with 133 additions and 140 deletions

View File

@ -9,6 +9,8 @@
#include "dtoolbase.h"
#undef _POSIX_C_SOURCE
#undef _XOPEN_SOURCE
#include <Python.h>
#if PY_MAJOR_VERSION >= 3
#include <wchar.h>

View File

@ -11,6 +11,7 @@
#include "dtoolbase.h"
#undef _POSIX_C_SOURCE
#undef _XOPEN_SOURCE
#define PY_SSIZE_T_CLEAN 1
#if PYTHON_FRAMEWORK

View File

@ -117,9 +117,10 @@
#endif
#ifdef HAVE_PYTHON
#undef _POSIX_C_SOURCE
#undef _XOPEN_SOURCE
#include "pyconfig.h"
// Instead of including the Python headers, which will implicitly
// add a linker flag to link in Python, we'll just excerpt the
// forward declaration of PyObject.
typedef struct _object PyObject;
#endif
#ifndef HAVE_EIGEN

View File

@ -37,9 +37,10 @@ void InterfaceMakerPython::
write_includes(ostream &out) {
InterfaceMaker::write_includes(out);
out << "#undef _POSIX_C_SOURCE\n"
<< "#undef _XOPEN_SOURCE\n"
<< "#define PY_SSIZE_T_CLEAN 1\n\n"
<< "#if PYTHON_FRAMEWORK\n"
<< " #include \"Python/Python.h\"\n"
<< " #include <Python/Python.h>\n"
<< "#else\n"
<< " #include \"Python.h\"\n"
<< "#endif\n";

View File

@ -79,7 +79,6 @@ upcase_string(const string &str) {
int write_python_table_native(ostream &out) {
out << "\n#include \"dtoolbase.h\"\n"
<< "#include \"interrogate_request.h\"\n\n"
<< "#undef _POSIX_C_SOURCE\n"
<< "#include \"py_panda.h\"\n\n";
int count = 0;

View File

@ -48,6 +48,10 @@
#undef _POSIX_C_SOURCE
#endif
#ifdef _XOPEN_SOURCE
#undef _XOPEN_SOURCE
#endif
#define PY_SSIZE_T_CLEAN 1
#include "Python.h"

View File

@ -236,40 +236,6 @@ get_done_event() const {
return _done_event;
}
#ifdef HAVE_PYTHON
////////////////////////////////////////////////////////////////////
// Function: AsyncTask::set_python_object
// Access: Published
// Description: Specifies an arbitrary Python object that will be
// piggybacked on the task object.
////////////////////////////////////////////////////////////////////
INLINE void AsyncTask::
set_python_object(PyObject *python_object) {
Py_XINCREF(python_object);
Py_XDECREF(_python_object);
_python_object = python_object;
}
#endif // HAVE_PYTHON
#ifdef HAVE_PYTHON
////////////////////////////////////////////////////////////////////
// Function: AsyncTask::get_python_object
// Access: Published
// Description: Returns the Python object that was specified to
// set_python_object(), if any, or None if no object was
// specified.
////////////////////////////////////////////////////////////////////
INLINE PyObject *AsyncTask::
get_python_object() const {
if (_python_object != (PyObject *)NULL) {
Py_XINCREF(_python_object);
return _python_object;
}
Py_INCREF(Py_None);
return Py_None;
}
#endif // HAVE_PYTHON
////////////////////////////////////////////////////////////////////
// Function: AsyncTask::get_dt
// Access: Published

View File

@ -19,6 +19,10 @@
#include "throw_event.h"
#include "eventParameter.h"
#ifdef HAVE_PYTHON
#include "py_panda.h"
#endif
AtomicAdjust::Integer AsyncTask::_next_task_id;
PStatCollector AsyncTask::_show_code_pcollector("App:Show code");
TypeHandle AsyncTask::_type_handle;
@ -400,6 +404,40 @@ set_priority(int priority) {
}
}
#ifdef HAVE_PYTHON
////////////////////////////////////////////////////////////////////
// Function: AsyncTask::set_python_object
// Access: Published
// Description: Specifies an arbitrary Python object that will be
// piggybacked on the task object.
////////////////////////////////////////////////////////////////////
void AsyncTask::
set_python_object(PyObject *python_object) {
Py_XINCREF(python_object);
Py_XDECREF(_python_object);
_python_object = python_object;
}
#endif // HAVE_PYTHON
#ifdef HAVE_PYTHON
////////////////////////////////////////////////////////////////////
// Function: AsyncTask::get_python_object
// Access: Published
// Description: Returns the Python object that was specified to
// set_python_object(), if any, or None if no object was
// specified.
////////////////////////////////////////////////////////////////////
PyObject *AsyncTask::
get_python_object() const {
if (_python_object != (PyObject *)NULL) {
Py_XINCREF(_python_object);
return _python_object;
}
Py_INCREF(Py_None);
return Py_None;
}
#endif // HAVE_PYTHON
////////////////////////////////////////////////////////////////////
// Function: AsyncTask::output
// Access: Published, Virtual

View File

@ -22,14 +22,6 @@
#include "conditionVar.h"
#include "pStatCollector.h"
#ifdef HAVE_PYTHON
#undef HAVE_LONG_LONG // NSPR and Python both define this.
#undef _POSIX_C_SOURCE
#include <Python.h>
#endif // HAVE_PYTHON
class AsyncTaskManager;
class AsyncTaskChain;
@ -104,8 +96,8 @@ PUBLISHED:
INLINE const string &get_done_event() const;
#ifdef HAVE_PYTHON
INLINE void set_python_object(PyObject *python_object);
INLINE PyObject *get_python_object() const;
void set_python_object(PyObject *python_object);
PyObject *get_python_object() const;
#endif // HAVE_PYTHON
INLINE double get_dt() const;

View File

@ -15,10 +15,6 @@
#include "textureCollection.h"
#include "indent.h"
#ifdef HAVE_PYTHON
#include "py_panda.h"
#endif
////////////////////////////////////////////////////////////////////
// Function: TextureCollection::Constructor
// Access: Published

View File

@ -14,4 +14,50 @@
#include "buffered_datagramconnection.h"
#ifdef HAVE_PYTHON
#include "py_panda.h"
#endif
TypeHandle Buffered_DatagramConnection::_type_handle;
////////////////////////////////////////////////////////////////////
// Function name : Buffered_DatagramConnection::SendMessage
// Description : send the message
//
// Return type : bool
// Argument : DataGram &msg
////////////////////////////////////////////////////////////////////
bool Buffered_DatagramConnection::
SendMessage(const Datagram &msg) {
if (IsConnected()) {
//printf(" DO SendMessage %d\n",msg.get_length());
int val = _Writer.AddData(msg.get_data(), msg.get_length(), *this);
if (val >= 0) {
return true;
}
// Raise an exception to give us more information at the python level
nativenet_cat.warning() << "Buffered_DatagramConnection::SendMessage->Error On Write--Out Buffer = " << _Writer.AmountBuffered() << "\n";
#ifdef HAVE_PYTHON
ostringstream s;
#if PY_MAJOR_VERSION >= 3
PyObject *exc_type = PyExc_ConnectionError;
#else
PyObject *exc_type = PyExc_StandardError;
#endif
s << endl << "Error sending message: " << endl;
msg.dump_hex(s);
s << "Message data: " << msg.get_data() << endl;
string message = s.str();
PyErr_SetString(exc_type, message.c_str());
#endif
ClearAll();
}
return false;
}

View File

@ -20,10 +20,6 @@
#include "buffered_datagramwriter.h"
#include "config_nativenet.h"
#ifdef HAVE_PYTHON
#include "py_panda.h"
#endif
////////////////////////////////////////////////////////////////
// there are 3 states
//
@ -85,7 +81,7 @@ PUBLISHED:
inline Buffered_DatagramConnection(int rbufsize, int wbufsize, int write_flush_point) ;
virtual ~Buffered_DatagramConnection(void) ;
// the reason thsi all exists
inline bool SendMessage(const Datagram &msg);
bool SendMessage(const Datagram &msg);
inline bool Flush(void);
inline void Reset(void);
@ -236,45 +232,6 @@ inline Buffered_DatagramConnection::Buffered_DatagramConnection(int rbufsize, in
nativenet_cat.error() << "Buffered_DatagramConnection Constructor rbufsize = " << rbufsize
<< " wbufsize = " << wbufsize << " write_flush_point = " << write_flush_point << "\n";
}
////////////////////////////////////////////////////////////////////
// Function name : Buffered_DatagramConnection::SendMessage
// Description : send the message
//
// Return type : inline bool
// Argument : DataGram &msg
////////////////////////////////////////////////////////////////////
inline bool Buffered_DatagramConnection::SendMessage(const Datagram &msg)
{
if(IsConnected()) {
// printf(" DO SendMessage %d\n",msg.get_length());
int val = 0;
val = _Writer.AddData(msg.get_data(),msg.get_length(),*this);
if(val >= 0)
return true;
// Raise an exception to give us more information at the python level
nativenet_cat.warning() << "Buffered_DatagramConnection::SendMessage->Error On Write--Out Buffer = " << _Writer.AmountBuffered() << "\n";
#ifdef HAVE_PYTHON
ostringstream s;
#if PY_MAJOR_VERSION >= 3
PyObject *exc_type = PyExc_ConnectionError;
#else
PyObject *exc_type = PyExc_StandardError;
#endif
s << endl << "Error sending message: " << endl;
msg.dump_hex(s);
s << "Message data: " << msg.get_data() << endl;
string message = s.str();
PyErr_SetString(exc_type, message.c_str());
#endif
ClearAll();
}
return false;
}
inline bool Buffered_DatagramConnection::SendMessageBufferOnly(Datagram &msg)
{

View File

@ -95,22 +95,7 @@ set_data(void *data) {
dBodySetData(_id, data);
}
#ifdef HAVE_PYTHON
INLINE void OdeBody::
set_data(PyObject *data) {
Py_XDECREF((PyObject*) dBodyGetData(_id));
Py_XINCREF(data);
dBodySetData(_id, data);
}
INLINE PyObject* OdeBody::
get_data() const {
PyObject* data = (PyObject*) dBodyGetData(_id);
Py_XINCREF(data);
return data;
}
#else
#ifndef HAVE_PYTHON
INLINE void* OdeBody::
get_data() const {
return dBodyGetData(_id);
@ -132,7 +117,7 @@ set_rotation(const LMatrix3f &r) {
dMatrix3 mat3 = { r(0, 0), r(0, 1), r(0, 2), 0,
r(1, 0), r(1, 1), r(1, 2), 0,
r(2, 0), r(2, 1), r(2, 2), 0 };
dBodySetRotation(_id, mat3);
}

View File

@ -16,6 +16,10 @@
#include "odeBody.h"
#include "odeJoint.h"
#ifdef HAVE_PYTHON
#include "py_panda.h"
#endif
TypeHandle OdeBody::_type_handle;
OdeBody::
@ -42,6 +46,22 @@ destroy() {
dBodyDestroy(_id);
}
#ifdef HAVE_PYTHON
void OdeBody::
set_data(PyObject *data) {
Py_XDECREF((PyObject*) dBodyGetData(_id));
Py_XINCREF(data);
dBodySetData(_id, data);
}
PyObject* OdeBody::
get_data() const {
PyObject* data = (PyObject*) dBodyGetData(_id);
Py_XINCREF(data);
return data;
}
#endif
OdeJoint OdeBody::
get_joint(int index) const {
nassertr(_id != 0, OdeJoint(0));

View File

@ -22,9 +22,6 @@
#include "ode_includes.h"
#include "odeWorld.h"
#include "odeMass.h"
#ifdef HAVE_PYTHON
#include "Python.h"
#endif
class OdeJoint;
class OdeGeom;
@ -57,7 +54,7 @@ PUBLISHED:
INLINE void set_auto_disable_defaults();
INLINE void set_data(void *data);
#ifdef HAVE_PYTHON
INLINE void set_data(PyObject *data);
void set_data(PyObject *data);
#endif
INLINE void set_position(dReal x, dReal y, dReal z);
@ -77,7 +74,7 @@ PUBLISHED:
INLINE dReal get_auto_disable_time() const;
INLINE int get_auto_disable_flag() const;
#ifdef HAVE_PYTHON
INLINE PyObject* get_data() const;
PyObject* get_data() const;
#else
INLINE void* get_data() const;
#endif

View File

@ -47,13 +47,6 @@
#include "lightReMutex.h"
#include "extension.h"
#ifdef HAVE_PYTHON
#undef _POSIX_C_SOURCE
#include <Python.h>
#endif // HAVE_PYTHON
class NodePathComponent;
class CullTraverser;
class CullTraverserData;

View File

@ -36,7 +36,6 @@
#include "lightMutexHolder.h"
#include "thread.h"
#include "renderAttribRegistry.h"
#include "py_panda.h"
LightReMutex *RenderState::_states_lock = NULL;
RenderState::States *RenderState::_states = NULL;

View File

@ -24,7 +24,6 @@
#include "lightReMutexHolder.h"
#include "lightMutexHolder.h"
#include "thread.h"
#include "py_panda.h"
LightReMutex *TransformState::_states_lock = NULL;
TransformState::States *TransformState::_states = NULL;

View File

@ -16,6 +16,7 @@
#include "pnotify.h"
#ifdef HAVE_PYTHON
#include "py_panda.h"
TypeHandle PythonThread::_type_handle;

View File

@ -20,6 +20,10 @@
#include "conditionVarDebug.h"
#include "conditionVarFullDebug.h"
#ifdef HAVE_PYTHON
#include "py_panda.h"
#endif
Thread *Thread::_main_thread;
Thread *Thread::_external_thread;
TypeHandle Thread::_type_handle;

View File

@ -24,11 +24,6 @@
#include "pnotify.h"
#include "config_pipeline.h"
#ifdef HAVE_PYTHON
#undef _POSIX_C_SOURCE
#include <Python.h>
#endif // HAVE_PYTHON
class Mutex;
class ReMutex;
class MutexDebug;

View File

@ -25,13 +25,6 @@
#include "pvector.h"
#include "contextSwitch.h"
#ifdef HAVE_PYTHON
#undef _POSIX_C_SOURCE
#include <Python.h>
#endif // HAVE_PYTHON
class Thread;
class ThreadSimpleManager;
class MutexSimpleImpl;

View File

@ -21,6 +21,10 @@
#include <Rocket/Debugger.h>
#endif
#ifdef HAVE_PYTHON
#include "py_panda.h"
#endif
TypeHandle RocketRegion::_type_handle;
////////////////////////////////////////////////////////////////////