Various fixes for Python 3 versions before Python 3.3

This commit is contained in:
rdb 2015-12-06 17:32:27 +01:00
parent 43370d00ef
commit 287c44ce53
9 changed files with 49 additions and 10 deletions

View File

@ -22,6 +22,10 @@
#include "dcClassParameter.h" #include "dcClassParameter.h"
#include <algorithm> #include <algorithm>
#ifdef HAVE_PYTHON
#include "py_panda.h"
#endif
#ifdef WITHIN_PANDA #ifdef WITHIN_PANDA
#include "pStatTimer.h" #include "pStatTimer.h"

View File

@ -19,6 +19,10 @@
#include "hashGenerator.h" #include "hashGenerator.h"
#include "dcmsgtypes.h" #include "dcmsgtypes.h"
#ifdef HAVE_PYTHON
#include "py_panda.h"
#endif
#ifdef WITHIN_PANDA #ifdef WITHIN_PANDA
#include "pStatTimer.h" #include "pStatTimer.h"
#endif #endif

View File

@ -36,7 +36,7 @@ int main(int argc, char *mb_argv[]) {
size_t len = mbstowcs(NULL, mb_argv[i], 0); size_t len = mbstowcs(NULL, mb_argv[i], 0);
argv[i] = new wchar_t[len + 1]; argv[i] = new wchar_t[len + 1];
mbstowcs(argv[i], mb_argv[i], len); mbstowcs(argv[i], mb_argv[i], len);
argv[i][len] = NULL; argv[i][len] = 0;
} }
// Just for good measure // Just for good measure
argv[argc] = NULL; argv[argc] = NULL;

View File

@ -1,6 +1,5 @@
from pandac.PandaModules import * from pandac.PandaModules import *
from string import lower
class DirectLight(NodePath): class DirectLight(NodePath):
def __init__(self, light, parent): def __init__(self, light, parent):

View File

@ -1317,7 +1317,7 @@ class Enum:
i = start i = start
for item in items: for item in items:
# remove leading/trailing whitespace # remove leading/trailing whitespace
item = string.strip(item) item = item.strip()
# is there anything left? # is there anything left?
if len(item) == 0: if len(item) == 0:
continue continue

View File

@ -4553,13 +4553,17 @@ write_function_instance(ostream &out, FunctionRemap *remap,
expected_params += "str"; expected_params += "str";
} else if (TypeManager::is_wchar_pointer(orig_type)) { } 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) << "PyUnicodeObject *" << param_name << ";\n";
indent(out, indent_level) << "#endif\n";
format_specifiers += "U"; format_specifiers += "U";
parameter_list += ", &" + param_name; parameter_list += ", &" + param_name;
extra_convert extra_convert
<< "#if PY_VERSION_HEX >= 0x03030000\n" << "#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" << "#else"
<< "Py_ssize_t " << param_name << "_len = PyUnicode_GET_SIZE(" << param_name << ");\n" << "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" << "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"; expected_params += "unicode";
} else if (TypeManager::is_wstring(orig_type)) { } 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) << "PyUnicodeObject *" << param_name << ";\n";
indent(out, indent_level) << "#endif\n";
format_specifiers += "U"; format_specifiers += "U";
parameter_list += ", &" + param_name; parameter_list += ", &" + param_name;
extra_convert extra_convert
<< "#if PY_VERSION_HEX >= 0x03030000\n" << "#if PY_VERSION_HEX >= 0x03030000\n"
<< "Py_ssize_t " << param_name << "_len;\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" << param_name << ", &" << param_name << "_len);\n"
<< "#else\n" << "#else\n"
<< "Py_ssize_t " << param_name << "_len = PyUnicode_GET_SIZE(" << param_name << ");\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"; expected_params += "unicode";
} else if (TypeManager::is_const_ptr_to_basic_string_wchar(orig_type)) { } 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) << "PyUnicodeObject *" << param_name << ";\n";
indent(out, indent_level) << "#endif\n";
format_specifiers += "U"; format_specifiers += "U";
parameter_list += ", &" + param_name; parameter_list += ", &" + param_name;
extra_convert extra_convert
<< "#if PY_VERSION_HEX >= 0x03030000\n" << "#if PY_VERSION_HEX >= 0x03030000\n"
<< "Py_ssize_t " << param_name << "_len;\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" << param_name << ", &" << param_name << "_len);\n"
<< "#else\n" << "#else\n"
<< "Py_ssize_t " << param_name << "_len = PyUnicode_GET_SIZE(" << param_name << ");\n" << "Py_ssize_t " << param_name << "_len = PyUnicode_GET_SIZE(" << param_name << ");\n"

View File

@ -135,6 +135,12 @@ typedef long Py_hash_t;
// Python 3 versions before 3.3.3 defined this incorrectly. // Python 3 versions before 3.3.3 defined this incorrectly.
#undef _PyErr_OCCURRED #undef _PyErr_OCCURRED
#define _PyErr_OCCURRED() (PyThreadState_GET()->curexc_type) #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 #endif
using namespace std; using namespace std;

View File

@ -144,10 +144,14 @@ extern "C" {
EXPCL_PYSTUB int PyType_GenericAlloc(...); EXPCL_PYSTUB int PyType_GenericAlloc(...);
EXPCL_PYSTUB int PyType_IsSubtype(...); EXPCL_PYSTUB int PyType_IsSubtype(...);
EXPCL_PYSTUB int PyType_Ready(...); EXPCL_PYSTUB int PyType_Ready(...);
EXPCL_PYSTUB int PyUnicodeUCS2_FromFormat(...);
EXPCL_PYSTUB int PyUnicodeUCS2_FromString(...);
EXPCL_PYSTUB int PyUnicodeUCS2_FromStringAndSize(...); EXPCL_PYSTUB int PyUnicodeUCS2_FromStringAndSize(...);
EXPCL_PYSTUB int PyUnicodeUCS2_FromWideChar(...); EXPCL_PYSTUB int PyUnicodeUCS2_FromWideChar(...);
EXPCL_PYSTUB int PyUnicodeUCS2_AsWideChar(...); EXPCL_PYSTUB int PyUnicodeUCS2_AsWideChar(...);
EXPCL_PYSTUB int PyUnicodeUCS2_GetSize(...); EXPCL_PYSTUB int PyUnicodeUCS2_GetSize(...);
EXPCL_PYSTUB int PyUnicodeUCS4_FromFormat(...);
EXPCL_PYSTUB int PyUnicodeUCS4_FromString(...);
EXPCL_PYSTUB int PyUnicodeUCS4_FromStringAndSize(...); EXPCL_PYSTUB int PyUnicodeUCS4_FromStringAndSize(...);
EXPCL_PYSTUB int PyUnicodeUCS4_FromWideChar(...); EXPCL_PYSTUB int PyUnicodeUCS4_FromWideChar(...);
EXPCL_PYSTUB int PyUnicodeUCS4_AsWideChar(...); EXPCL_PYSTUB int PyUnicodeUCS4_AsWideChar(...);
@ -175,6 +179,8 @@ extern "C" {
EXPCL_PYSTUB int _PyObject_CallMethod_SizeT(...); EXPCL_PYSTUB int _PyObject_CallMethod_SizeT(...);
EXPCL_PYSTUB int _PyObject_DebugFree(...); EXPCL_PYSTUB int _PyObject_DebugFree(...);
EXPCL_PYSTUB int _PyObject_Del(...); 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_BuildValue_SizeT(...);
EXPCL_PYSTUB int _Py_Dealloc(...); EXPCL_PYSTUB int _Py_Dealloc(...);
EXPCL_PYSTUB int _Py_NegativeRefcount(...); EXPCL_PYSTUB int _Py_NegativeRefcount(...);
@ -190,6 +196,7 @@ extern "C" {
EXPCL_PYSTUB extern void *PyExc_Exception; EXPCL_PYSTUB extern void *PyExc_Exception;
EXPCL_PYSTUB extern void *PyExc_FutureWarning; EXPCL_PYSTUB extern void *PyExc_FutureWarning;
EXPCL_PYSTUB extern void *PyExc_IndexError; EXPCL_PYSTUB extern void *PyExc_IndexError;
EXPCL_PYSTUB extern void *PyExc_OSError;
EXPCL_PYSTUB extern void *PyExc_RuntimeError; EXPCL_PYSTUB extern void *PyExc_RuntimeError;
EXPCL_PYSTUB extern void *PyExc_StandardError; EXPCL_PYSTUB extern void *PyExc_StandardError;
EXPCL_PYSTUB extern void *PyExc_StopIteration; EXPCL_PYSTUB extern void *PyExc_StopIteration;
@ -334,10 +341,14 @@ int PyTuple_Type(...) { return 0; };
int PyType_GenericAlloc(...) { return 0; }; int PyType_GenericAlloc(...) { return 0; };
int PyType_IsSubtype(...) { return 0; } int PyType_IsSubtype(...) { return 0; }
int PyType_Ready(...) { return 0; }; int PyType_Ready(...) { return 0; };
int PyUnicodeUCS2_FromFormat(...) { return 0; }
int PyUnicodeUCS2_FromString(...) { return 0; }
int PyUnicodeUCS2_FromStringAndSize(...) { return 0; } int PyUnicodeUCS2_FromStringAndSize(...) { return 0; }
int PyUnicodeUCS2_FromWideChar(...) { return 0; } int PyUnicodeUCS2_FromWideChar(...) { return 0; }
int PyUnicodeUCS2_AsWideChar(...) { return 0; } int PyUnicodeUCS2_AsWideChar(...) { return 0; }
int PyUnicodeUCS2_GetSize(...) { return 0; } int PyUnicodeUCS2_GetSize(...) { return 0; }
int PyUnicodeUCS4_FromFormat(...) { return 0; }
int PyUnicodeUCS4_FromString(...) { return 0; }
int PyUnicodeUCS4_FromStringAndSize(...) { return 0; } int PyUnicodeUCS4_FromStringAndSize(...) { return 0; }
int PyUnicodeUCS4_FromWideChar(...) { return 0; } int PyUnicodeUCS4_FromWideChar(...) { return 0; }
int PyUnicodeUCS4_AsWideChar(...) { 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_CallMethod_SizeT(...) { return 0; };
int _PyObject_DebugFree(...) { return 0; }; int _PyObject_DebugFree(...) { return 0; };
int _PyObject_Del(...) { 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_BuildValue_SizeT(...) { return 0; };
int _Py_Dealloc(...) { return 0; }; int _Py_Dealloc(...) { return 0; };
int _Py_NegativeRefcount(...) { return 0; }; int _Py_NegativeRefcount(...) { return 0; };
@ -385,6 +398,7 @@ void *PyExc_ConnectionError = (void *)NULL;
void *PyExc_Exception = (void *)NULL; void *PyExc_Exception = (void *)NULL;
void *PyExc_FutureWarning = (void *)NULL; void *PyExc_FutureWarning = (void *)NULL;
void *PyExc_IndexError = (void *)NULL; void *PyExc_IndexError = (void *)NULL;
void *PyExc_OSError = (void *)NULL;
void *PyExc_RuntimeError = (void *)NULL; void *PyExc_RuntimeError = (void *)NULL;
void *PyExc_StandardError = (void *)NULL; void *PyExc_StandardError = (void *)NULL;
void *PyExc_StopIteration = (void *)NULL; void *PyExc_StopIteration = (void *)NULL;

View File

@ -256,10 +256,10 @@ inline bool Buffered_DatagramConnection::SendMessage(const Datagram &msg)
#ifdef HAVE_PYTHON #ifdef HAVE_PYTHON
ostringstream s; ostringstream s;
#if PY_MAJOR_VERSION >= 3 #if PY_VERSION_HEX >= 0x03030000
PyObject *exc_type = PyExc_ConnectionError; PyObject *exc_type = PyExc_ConnectionError;
#else #else
PyObject *exc_type = PyExc_StandardError; PyObject *exc_type = PyExc_OSError;
#endif #endif
s << endl << "Error sending message: " << endl; s << endl << "Error sending message: " << endl;