diff --git a/direct/src/dcparser/dcClass.cxx b/direct/src/dcparser/dcClass.cxx index cd9a3856b3..c3e37f6421 100644 --- a/direct/src/dcparser/dcClass.cxx +++ b/direct/src/dcparser/dcClass.cxx @@ -22,6 +22,10 @@ #include "dcClassParameter.h" #include +#ifdef HAVE_PYTHON +#include "py_panda.h" +#endif + #ifdef WITHIN_PANDA #include "pStatTimer.h" @@ -80,7 +84,7 @@ DCClass(DCFile *dc_file, const string &name, bool is_struct, bool bogus_class) : { _number = -1; _constructor = NULL; - + #ifdef HAVE_PYTHON _class_def = NULL; _owner_class_def = NULL; @@ -1003,7 +1007,7 @@ client_format_generate_CMU(PyObject *distobj, DOID_TYPE do_id, string field_name = PyString_AsString(py_field_name); #endif Py_XDECREF(py_field_name); - + DCField *field = get_field_by_name(field_name); if (field == (DCField *)NULL) { ostringstream strm; diff --git a/direct/src/dcparser/dcField.cxx b/direct/src/dcparser/dcField.cxx index 7946b62aa1..59701a6df2 100644 --- a/direct/src/dcparser/dcField.cxx +++ b/direct/src/dcparser/dcField.cxx @@ -19,6 +19,10 @@ #include "hashGenerator.h" #include "dcmsgtypes.h" +#ifdef HAVE_PYTHON +#include "py_panda.h" +#endif + #ifdef WITHIN_PANDA #include "pStatTimer.h" #endif diff --git a/direct/src/directbase/ppython.cxx b/direct/src/directbase/ppython.cxx index 4d673d96b6..65f1272c8a 100644 --- a/direct/src/directbase/ppython.cxx +++ b/direct/src/directbase/ppython.cxx @@ -36,7 +36,7 @@ int main(int argc, char *mb_argv[]) { size_t len = mbstowcs(NULL, mb_argv[i], 0); argv[i] = new wchar_t[len + 1]; mbstowcs(argv[i], mb_argv[i], len); - argv[i][len] = NULL; + argv[i][len] = 0; } // Just for good measure argv[argc] = NULL; diff --git a/direct/src/directtools/DirectLights.py b/direct/src/directtools/DirectLights.py index 5e5a5eb5e2..89e3e5c0f2 100644 --- a/direct/src/directtools/DirectLights.py +++ b/direct/src/directtools/DirectLights.py @@ -1,6 +1,5 @@ from pandac.PandaModules import * -from string import lower class DirectLight(NodePath): def __init__(self, light, parent): diff --git a/direct/src/showbase/PythonUtil.py b/direct/src/showbase/PythonUtil.py index ffe6869094..4038259806 100644 --- a/direct/src/showbase/PythonUtil.py +++ b/direct/src/showbase/PythonUtil.py @@ -1317,7 +1317,7 @@ class Enum: i = start for item in items: # remove leading/trailing whitespace - item = string.strip(item) + item = item.strip() # is there anything left? if len(item) == 0: continue diff --git a/dtool/src/interrogate/interfaceMakerPythonNative.cxx b/dtool/src/interrogate/interfaceMakerPythonNative.cxx index 9a54861dcb..1c42584114 100644 --- a/dtool/src/interrogate/interfaceMakerPythonNative.cxx +++ b/dtool/src/interrogate/interfaceMakerPythonNative.cxx @@ -4553,13 +4553,17 @@ write_function_instance(ostream &out, FunctionRemap *remap, expected_params += "str"; } else if (TypeManager::is_wchar_pointer(orig_type)) { + indent(out, indent_level) << "#if PY_VERSION_HEX >= 0x03020000\n"; + indent(out, indent_level) << "PyObject *" << param_name << ";\n"; + indent(out, indent_level) << "#else\n"; indent(out, indent_level) << "PyUnicodeObject *" << param_name << ";\n"; + indent(out, indent_level) << "#endif\n"; format_specifiers += "U"; parameter_list += ", &" + param_name; extra_convert << "#if PY_VERSION_HEX >= 0x03030000\n" - << "wchar_t *" << param_name << "_str = PyUnicode_AsWideCharString((PyObject *)" << param_name << ", NULL);\n" + << "wchar_t *" << param_name << "_str = PyUnicode_AsWideCharString(" << param_name << ", NULL);\n" << "#else" << "Py_ssize_t " << param_name << "_len = PyUnicode_GET_SIZE(" << param_name << ");\n" << "wchar_t *" << param_name << "_str = (wchar_t *)alloca(sizeof(wchar_t) * (" + param_name + "_len + 1));\n" @@ -4577,14 +4581,18 @@ write_function_instance(ostream &out, FunctionRemap *remap, expected_params += "unicode"; } else if (TypeManager::is_wstring(orig_type)) { + indent(out, indent_level) << "#if PY_VERSION_HEX >= 0x03020000\n"; + indent(out, indent_level) << "PyObject *" << param_name << ";\n"; + indent(out, indent_level) << "#else\n"; indent(out, indent_level) << "PyUnicodeObject *" << param_name << ";\n"; + indent(out, indent_level) << "#endif\n"; format_specifiers += "U"; parameter_list += ", &" + param_name; extra_convert << "#if PY_VERSION_HEX >= 0x03030000\n" << "Py_ssize_t " << param_name << "_len;\n" - << "wchar_t *" << param_name << "_str = PyUnicode_AsWideCharString((PyObject *)" + << "wchar_t *" << param_name << "_str = PyUnicode_AsWideCharString(" << param_name << ", &" << param_name << "_len);\n" << "#else\n" << "Py_ssize_t " << param_name << "_len = PyUnicode_GET_SIZE(" << param_name << ");\n" @@ -4603,14 +4611,18 @@ write_function_instance(ostream &out, FunctionRemap *remap, expected_params += "unicode"; } else if (TypeManager::is_const_ptr_to_basic_string_wchar(orig_type)) { + indent(out, indent_level) << "#if PY_VERSION_HEX >= 0x03020000\n"; + indent(out, indent_level) << "PyObject *" << param_name << ";\n"; + indent(out, indent_level) << "#else\n"; indent(out, indent_level) << "PyUnicodeObject *" << param_name << ";\n"; + indent(out, indent_level) << "#endif\n"; format_specifiers += "U"; parameter_list += ", &" + param_name; extra_convert << "#if PY_VERSION_HEX >= 0x03030000\n" << "Py_ssize_t " << param_name << "_len;\n" - << "wchar_t *" << param_name << "_str = PyUnicode_AsWideCharString((PyObject *)" + << "wchar_t *" << param_name << "_str = PyUnicode_AsWideCharString(" << param_name << ", &" << param_name << "_len);\n" << "#else\n" << "Py_ssize_t " << param_name << "_len = PyUnicode_GET_SIZE(" << param_name << ");\n" diff --git a/dtool/src/interrogatedb/py_panda.h b/dtool/src/interrogatedb/py_panda.h index 2755e46ebe..3545561a03 100644 --- a/dtool/src/interrogatedb/py_panda.h +++ b/dtool/src/interrogatedb/py_panda.h @@ -135,6 +135,12 @@ typedef long Py_hash_t; // Python 3 versions before 3.3.3 defined this incorrectly. #undef _PyErr_OCCURRED #define _PyErr_OCCURRED() (PyThreadState_GET()->curexc_type) + +// Python versions before 3.3 did not define this. +#if PY_VERSION_HEX < 0x03030000 +#define PyUnicode_AsUTF8 _PyUnicode_AsString +#define PyUnicode_AsUTF8AndSize _PyUnicode_AsStringAndSize +#endif #endif using namespace std; diff --git a/dtool/src/pystub/pystub.cxx b/dtool/src/pystub/pystub.cxx index 2c0dd9303b..399af3ef3a 100644 --- a/dtool/src/pystub/pystub.cxx +++ b/dtool/src/pystub/pystub.cxx @@ -144,10 +144,14 @@ extern "C" { EXPCL_PYSTUB int PyType_GenericAlloc(...); EXPCL_PYSTUB int PyType_IsSubtype(...); EXPCL_PYSTUB int PyType_Ready(...); + EXPCL_PYSTUB int PyUnicodeUCS2_FromFormat(...); + EXPCL_PYSTUB int PyUnicodeUCS2_FromString(...); EXPCL_PYSTUB int PyUnicodeUCS2_FromStringAndSize(...); EXPCL_PYSTUB int PyUnicodeUCS2_FromWideChar(...); EXPCL_PYSTUB int PyUnicodeUCS2_AsWideChar(...); EXPCL_PYSTUB int PyUnicodeUCS2_GetSize(...); + EXPCL_PYSTUB int PyUnicodeUCS4_FromFormat(...); + EXPCL_PYSTUB int PyUnicodeUCS4_FromString(...); EXPCL_PYSTUB int PyUnicodeUCS4_FromStringAndSize(...); EXPCL_PYSTUB int PyUnicodeUCS4_FromWideChar(...); EXPCL_PYSTUB int PyUnicodeUCS4_AsWideChar(...); @@ -175,6 +179,8 @@ extern "C" { EXPCL_PYSTUB int _PyObject_CallMethod_SizeT(...); EXPCL_PYSTUB int _PyObject_DebugFree(...); EXPCL_PYSTUB int _PyObject_Del(...); + EXPCL_PYSTUB int _PyUnicode_AsString(...); + EXPCL_PYSTUB int _PyUnicode_AsStringAndSize(...); EXPCL_PYSTUB int _Py_BuildValue_SizeT(...); EXPCL_PYSTUB int _Py_Dealloc(...); EXPCL_PYSTUB int _Py_NegativeRefcount(...); @@ -190,6 +196,7 @@ extern "C" { EXPCL_PYSTUB extern void *PyExc_Exception; EXPCL_PYSTUB extern void *PyExc_FutureWarning; EXPCL_PYSTUB extern void *PyExc_IndexError; + EXPCL_PYSTUB extern void *PyExc_OSError; EXPCL_PYSTUB extern void *PyExc_RuntimeError; EXPCL_PYSTUB extern void *PyExc_StandardError; EXPCL_PYSTUB extern void *PyExc_StopIteration; @@ -334,10 +341,14 @@ int PyTuple_Type(...) { return 0; }; int PyType_GenericAlloc(...) { return 0; }; int PyType_IsSubtype(...) { return 0; } int PyType_Ready(...) { return 0; }; +int PyUnicodeUCS2_FromFormat(...) { return 0; } +int PyUnicodeUCS2_FromString(...) { return 0; } int PyUnicodeUCS2_FromStringAndSize(...) { return 0; } int PyUnicodeUCS2_FromWideChar(...) { return 0; } int PyUnicodeUCS2_AsWideChar(...) { return 0; } int PyUnicodeUCS2_GetSize(...) { return 0; } +int PyUnicodeUCS4_FromFormat(...) { return 0; } +int PyUnicodeUCS4_FromString(...) { return 0; } int PyUnicodeUCS4_FromStringAndSize(...) { return 0; } int PyUnicodeUCS4_FromWideChar(...) { return 0; } int PyUnicodeUCS4_AsWideChar(...) { return 0; } @@ -365,6 +376,8 @@ int _PyObject_CallFunction_SizeT(...) { return 0; }; int _PyObject_CallMethod_SizeT(...) { return 0; }; int _PyObject_DebugFree(...) { return 0; }; int _PyObject_Del(...) { return 0; }; +int _PyUnicode_AsString(...) { return 0; }; +int _PyUnicode_AsStringAndSize(...) { return 0; }; int _Py_BuildValue_SizeT(...) { return 0; }; int _Py_Dealloc(...) { return 0; }; int _Py_NegativeRefcount(...) { return 0; }; @@ -385,6 +398,7 @@ void *PyExc_ConnectionError = (void *)NULL; void *PyExc_Exception = (void *)NULL; void *PyExc_FutureWarning = (void *)NULL; void *PyExc_IndexError = (void *)NULL; +void *PyExc_OSError = (void *)NULL; void *PyExc_RuntimeError = (void *)NULL; void *PyExc_StandardError = (void *)NULL; void *PyExc_StopIteration = (void *)NULL; diff --git a/panda/src/nativenet/buffered_datagramconnection.h b/panda/src/nativenet/buffered_datagramconnection.h index 2ea996d7e5..d9eea75f0e 100644 --- a/panda/src/nativenet/buffered_datagramconnection.h +++ b/panda/src/nativenet/buffered_datagramconnection.h @@ -256,10 +256,10 @@ inline bool Buffered_DatagramConnection::SendMessage(const Datagram &msg) #ifdef HAVE_PYTHON ostringstream s; -#if PY_MAJOR_VERSION >= 3 +#if PY_VERSION_HEX >= 0x03030000 PyObject *exc_type = PyExc_ConnectionError; #else - PyObject *exc_type = PyExc_StandardError; + PyObject *exc_type = PyExc_OSError; #endif s << endl << "Error sending message: " << endl;