diff --git a/direct/src/directbase/ppython.cxx b/direct/src/directbase/ppython.cxx index 65f1272c8a..d29a2c8831 100644 --- a/direct/src/directbase/ppython.cxx +++ b/direct/src/directbase/ppython.cxx @@ -9,6 +9,8 @@ #include "dtoolbase.h" +#undef _POSIX_C_SOURCE +#undef _XOPEN_SOURCE #include #if PY_MAJOR_VERSION >= 3 #include diff --git a/dtool/metalibs/dtoolconfig/pydtool.cxx b/dtool/metalibs/dtoolconfig/pydtool.cxx index 377037a295..d43ca96f9a 100644 --- a/dtool/metalibs/dtoolconfig/pydtool.cxx +++ b/dtool/metalibs/dtoolconfig/pydtool.cxx @@ -11,6 +11,7 @@ #include "dtoolbase.h" #undef _POSIX_C_SOURCE +#undef _XOPEN_SOURCE #define PY_SSIZE_T_CLEAN 1 #if PYTHON_FRAMEWORK diff --git a/dtool/src/dtoolbase/dtoolbase.h b/dtool/src/dtoolbase/dtoolbase.h index 75bad76d5b..7af39a2e28 100644 --- a/dtool/src/dtoolbase/dtoolbase.h +++ b/dtool/src/dtoolbase/dtoolbase.h @@ -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 diff --git a/dtool/src/interrogate/interfaceMakerPython.cxx b/dtool/src/interrogate/interfaceMakerPython.cxx index a9f8227dce..59a272a7e6 100644 --- a/dtool/src/interrogate/interfaceMakerPython.cxx +++ b/dtool/src/interrogate/interfaceMakerPython.cxx @@ -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 \n" << "#else\n" << " #include \"Python.h\"\n" << "#endif\n"; diff --git a/dtool/src/interrogate/interrogate_module.cxx b/dtool/src/interrogate/interrogate_module.cxx index 8f5b39591e..ecf8d27ad2 100644 --- a/dtool/src/interrogate/interrogate_module.cxx +++ b/dtool/src/interrogate/interrogate_module.cxx @@ -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; diff --git a/dtool/src/interrogatedb/py_panda.h b/dtool/src/interrogatedb/py_panda.h index 0534fb87b5..59b66ca05a 100644 --- a/dtool/src/interrogatedb/py_panda.h +++ b/dtool/src/interrogatedb/py_panda.h @@ -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" diff --git a/panda/src/event/asyncTask.I b/panda/src/event/asyncTask.I index b5807c7b02..cc1d52fe78 100644 --- a/panda/src/event/asyncTask.I +++ b/panda/src/event/asyncTask.I @@ -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 diff --git a/panda/src/event/asyncTask.cxx b/panda/src/event/asyncTask.cxx index 9a70627866..3d10445475 100644 --- a/panda/src/event/asyncTask.cxx +++ b/panda/src/event/asyncTask.cxx @@ -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 diff --git a/panda/src/event/asyncTask.h b/panda/src/event/asyncTask.h index b3ee95776f..838a1cba4f 100644 --- a/panda/src/event/asyncTask.h +++ b/panda/src/event/asyncTask.h @@ -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 - -#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; diff --git a/panda/src/gobj/textureCollection.cxx b/panda/src/gobj/textureCollection.cxx index 40e8651edb..9a87c6260c 100644 --- a/panda/src/gobj/textureCollection.cxx +++ b/panda/src/gobj/textureCollection.cxx @@ -15,10 +15,6 @@ #include "textureCollection.h" #include "indent.h" -#ifdef HAVE_PYTHON -#include "py_panda.h" -#endif - //////////////////////////////////////////////////////////////////// // Function: TextureCollection::Constructor // Access: Published diff --git a/panda/src/nativenet/buffered_datagramconnection.cxx b/panda/src/nativenet/buffered_datagramconnection.cxx index 357bc7ba68..e81e518d4a 100644 --- a/panda/src/nativenet/buffered_datagramconnection.cxx +++ b/panda/src/nativenet/buffered_datagramconnection.cxx @@ -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; +} diff --git a/panda/src/nativenet/buffered_datagramconnection.h b/panda/src/nativenet/buffered_datagramconnection.h index 2ea996d7e5..fb438d5cbb 100644 --- a/panda/src/nativenet/buffered_datagramconnection.h +++ b/panda/src/nativenet/buffered_datagramconnection.h @@ -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) { diff --git a/panda/src/ode/odeBody.I b/panda/src/ode/odeBody.I index 7d4d784532..1ae24323d7 100644 --- a/panda/src/ode/odeBody.I +++ b/panda/src/ode/odeBody.I @@ -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); } diff --git a/panda/src/ode/odeBody.cxx b/panda/src/ode/odeBody.cxx index 377ffe152a..9de0334fb9 100644 --- a/panda/src/ode/odeBody.cxx +++ b/panda/src/ode/odeBody.cxx @@ -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)); diff --git a/panda/src/ode/odeBody.h b/panda/src/ode/odeBody.h index 7a6fa3ffd7..6f10130896 100644 --- a/panda/src/ode/odeBody.h +++ b/panda/src/ode/odeBody.h @@ -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 diff --git a/panda/src/pgraph/pandaNode.h b/panda/src/pgraph/pandaNode.h index dda7244acb..6bfaa18bc2 100644 --- a/panda/src/pgraph/pandaNode.h +++ b/panda/src/pgraph/pandaNode.h @@ -47,13 +47,6 @@ #include "lightReMutex.h" #include "extension.h" -#ifdef HAVE_PYTHON - -#undef _POSIX_C_SOURCE -#include - -#endif // HAVE_PYTHON - class NodePathComponent; class CullTraverser; class CullTraverserData; diff --git a/panda/src/pgraph/renderState.cxx b/panda/src/pgraph/renderState.cxx index fd385668df..578154a5a8 100644 --- a/panda/src/pgraph/renderState.cxx +++ b/panda/src/pgraph/renderState.cxx @@ -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; diff --git a/panda/src/pgraph/transformState.cxx b/panda/src/pgraph/transformState.cxx index 7daf7c0a40..88d5092b77 100644 --- a/panda/src/pgraph/transformState.cxx +++ b/panda/src/pgraph/transformState.cxx @@ -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; diff --git a/panda/src/pipeline/pythonThread.cxx b/panda/src/pipeline/pythonThread.cxx index c1ef41e344..7f3528c14e 100644 --- a/panda/src/pipeline/pythonThread.cxx +++ b/panda/src/pipeline/pythonThread.cxx @@ -16,6 +16,7 @@ #include "pnotify.h" #ifdef HAVE_PYTHON +#include "py_panda.h" TypeHandle PythonThread::_type_handle; diff --git a/panda/src/pipeline/thread.cxx b/panda/src/pipeline/thread.cxx index 8d1d3a9a7d..b1fd43d65f 100644 --- a/panda/src/pipeline/thread.cxx +++ b/panda/src/pipeline/thread.cxx @@ -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; diff --git a/panda/src/pipeline/thread.h b/panda/src/pipeline/thread.h index 530912d05c..f46978f6a5 100644 --- a/panda/src/pipeline/thread.h +++ b/panda/src/pipeline/thread.h @@ -24,11 +24,6 @@ #include "pnotify.h" #include "config_pipeline.h" -#ifdef HAVE_PYTHON -#undef _POSIX_C_SOURCE -#include -#endif // HAVE_PYTHON - class Mutex; class ReMutex; class MutexDebug; diff --git a/panda/src/pipeline/threadSimpleImpl.h b/panda/src/pipeline/threadSimpleImpl.h index 5d7f5e0f13..83ba2ec911 100644 --- a/panda/src/pipeline/threadSimpleImpl.h +++ b/panda/src/pipeline/threadSimpleImpl.h @@ -25,13 +25,6 @@ #include "pvector.h" #include "contextSwitch.h" -#ifdef HAVE_PYTHON - -#undef _POSIX_C_SOURCE -#include - -#endif // HAVE_PYTHON - class Thread; class ThreadSimpleManager; class MutexSimpleImpl; diff --git a/panda/src/rocket/rocketRegion.cxx b/panda/src/rocket/rocketRegion.cxx index 6f6bac761e..8709c4c36e 100644 --- a/panda/src/rocket/rocketRegion.cxx +++ b/panda/src/rocket/rocketRegion.cxx @@ -21,6 +21,10 @@ #include #endif +#ifdef HAVE_PYTHON +#include "py_panda.h" +#endif + TypeHandle RocketRegion::_type_handle; ////////////////////////////////////////////////////////////////////