Skip to content

Commit 287c44c

Browse files
committed
Various fixes for Python 3 versions before Python 3.3
1 parent 43370d0 commit 287c44c

File tree

9 files changed

+49
-10
lines changed

9 files changed

+49
-10
lines changed

direct/src/dcparser/dcClass.cxx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
#include "dcClassParameter.h"
2323
#include <algorithm>
2424

25+
#ifdef HAVE_PYTHON
26+
#include "py_panda.h"
27+
#endif
28+
2529
#ifdef WITHIN_PANDA
2630
#include "pStatTimer.h"
2731

@@ -80,7 +84,7 @@ DCClass(DCFile *dc_file, const string &name, bool is_struct, bool bogus_class) :
8084
{
8185
_number = -1;
8286
_constructor = NULL;
83-
87+
8488
#ifdef HAVE_PYTHON
8589
_class_def = NULL;
8690
_owner_class_def = NULL;
@@ -1003,7 +1007,7 @@ client_format_generate_CMU(PyObject *distobj, DOID_TYPE do_id,
10031007
string field_name = PyString_AsString(py_field_name);
10041008
#endif
10051009
Py_XDECREF(py_field_name);
1006-
1010+
10071011
DCField *field = get_field_by_name(field_name);
10081012
if (field == (DCField *)NULL) {
10091013
ostringstream strm;

direct/src/dcparser/dcField.cxx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
#include "hashGenerator.h"
2020
#include "dcmsgtypes.h"
2121

22+
#ifdef HAVE_PYTHON
23+
#include "py_panda.h"
24+
#endif
25+
2226
#ifdef WITHIN_PANDA
2327
#include "pStatTimer.h"
2428
#endif

direct/src/directbase/ppython.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ int main(int argc, char *mb_argv[]) {
3636
size_t len = mbstowcs(NULL, mb_argv[i], 0);
3737
argv[i] = new wchar_t[len + 1];
3838
mbstowcs(argv[i], mb_argv[i], len);
39-
argv[i][len] = NULL;
39+
argv[i][len] = 0;
4040
}
4141
// Just for good measure
4242
argv[argc] = NULL;

direct/src/directtools/DirectLights.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11

22
from pandac.PandaModules import *
3-
from string import lower
43

54
class DirectLight(NodePath):
65
def __init__(self, light, parent):

direct/src/showbase/PythonUtil.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1317,7 +1317,7 @@ def __init__(self, items, start=0):
13171317
i = start
13181318
for item in items:
13191319
# remove leading/trailing whitespace
1320-
item = string.strip(item)
1320+
item = item.strip()
13211321
# is there anything left?
13221322
if len(item) == 0:
13231323
continue

dtool/src/interrogate/interfaceMakerPythonNative.cxx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4553,13 +4553,17 @@ write_function_instance(ostream &out, FunctionRemap *remap,
45534553
expected_params += "str";
45544554

45554555
} else if (TypeManager::is_wchar_pointer(orig_type)) {
4556+
indent(out, indent_level) << "#if PY_VERSION_HEX >= 0x03020000\n";
4557+
indent(out, indent_level) << "PyObject *" << param_name << ";\n";
4558+
indent(out, indent_level) << "#else\n";
45564559
indent(out, indent_level) << "PyUnicodeObject *" << param_name << ";\n";
4560+
indent(out, indent_level) << "#endif\n";
45574561
format_specifiers += "U";
45584562
parameter_list += ", &" + param_name;
45594563

45604564
extra_convert
45614565
<< "#if PY_VERSION_HEX >= 0x03030000\n"
4562-
<< "wchar_t *" << param_name << "_str = PyUnicode_AsWideCharString((PyObject *)" << param_name << ", NULL);\n"
4566+
<< "wchar_t *" << param_name << "_str = PyUnicode_AsWideCharString(" << param_name << ", NULL);\n"
45634567
<< "#else"
45644568
<< "Py_ssize_t " << param_name << "_len = PyUnicode_GET_SIZE(" << param_name << ");\n"
45654569
<< "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,
45774581
expected_params += "unicode";
45784582

45794583
} else if (TypeManager::is_wstring(orig_type)) {
4584+
indent(out, indent_level) << "#if PY_VERSION_HEX >= 0x03020000\n";
4585+
indent(out, indent_level) << "PyObject *" << param_name << ";\n";
4586+
indent(out, indent_level) << "#else\n";
45804587
indent(out, indent_level) << "PyUnicodeObject *" << param_name << ";\n";
4588+
indent(out, indent_level) << "#endif\n";
45814589
format_specifiers += "U";
45824590
parameter_list += ", &" + param_name;
45834591

45844592
extra_convert
45854593
<< "#if PY_VERSION_HEX >= 0x03030000\n"
45864594
<< "Py_ssize_t " << param_name << "_len;\n"
4587-
<< "wchar_t *" << param_name << "_str = PyUnicode_AsWideCharString((PyObject *)"
4595+
<< "wchar_t *" << param_name << "_str = PyUnicode_AsWideCharString("
45884596
<< param_name << ", &" << param_name << "_len);\n"
45894597
<< "#else\n"
45904598
<< "Py_ssize_t " << param_name << "_len = PyUnicode_GET_SIZE(" << param_name << ");\n"
@@ -4603,14 +4611,18 @@ write_function_instance(ostream &out, FunctionRemap *remap,
46034611
expected_params += "unicode";
46044612

46054613
} else if (TypeManager::is_const_ptr_to_basic_string_wchar(orig_type)) {
4614+
indent(out, indent_level) << "#if PY_VERSION_HEX >= 0x03020000\n";
4615+
indent(out, indent_level) << "PyObject *" << param_name << ";\n";
4616+
indent(out, indent_level) << "#else\n";
46064617
indent(out, indent_level) << "PyUnicodeObject *" << param_name << ";\n";
4618+
indent(out, indent_level) << "#endif\n";
46074619
format_specifiers += "U";
46084620
parameter_list += ", &" + param_name;
46094621

46104622
extra_convert
46114623
<< "#if PY_VERSION_HEX >= 0x03030000\n"
46124624
<< "Py_ssize_t " << param_name << "_len;\n"
4613-
<< "wchar_t *" << param_name << "_str = PyUnicode_AsWideCharString((PyObject *)"
4625+
<< "wchar_t *" << param_name << "_str = PyUnicode_AsWideCharString("
46144626
<< param_name << ", &" << param_name << "_len);\n"
46154627
<< "#else\n"
46164628
<< "Py_ssize_t " << param_name << "_len = PyUnicode_GET_SIZE(" << param_name << ");\n"

dtool/src/interrogatedb/py_panda.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ typedef long Py_hash_t;
135135
// Python 3 versions before 3.3.3 defined this incorrectly.
136136
#undef _PyErr_OCCURRED
137137
#define _PyErr_OCCURRED() (PyThreadState_GET()->curexc_type)
138+
139+
// Python versions before 3.3 did not define this.
140+
#if PY_VERSION_HEX < 0x03030000
141+
#define PyUnicode_AsUTF8 _PyUnicode_AsString
142+
#define PyUnicode_AsUTF8AndSize _PyUnicode_AsStringAndSize
143+
#endif
138144
#endif
139145

140146
using namespace std;

dtool/src/pystub/pystub.cxx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,14 @@ extern "C" {
144144
EXPCL_PYSTUB int PyType_GenericAlloc(...);
145145
EXPCL_PYSTUB int PyType_IsSubtype(...);
146146
EXPCL_PYSTUB int PyType_Ready(...);
147+
EXPCL_PYSTUB int PyUnicodeUCS2_FromFormat(...);
148+
EXPCL_PYSTUB int PyUnicodeUCS2_FromString(...);
147149
EXPCL_PYSTUB int PyUnicodeUCS2_FromStringAndSize(...);
148150
EXPCL_PYSTUB int PyUnicodeUCS2_FromWideChar(...);
149151
EXPCL_PYSTUB int PyUnicodeUCS2_AsWideChar(...);
150152
EXPCL_PYSTUB int PyUnicodeUCS2_GetSize(...);
153+
EXPCL_PYSTUB int PyUnicodeUCS4_FromFormat(...);
154+
EXPCL_PYSTUB int PyUnicodeUCS4_FromString(...);
151155
EXPCL_PYSTUB int PyUnicodeUCS4_FromStringAndSize(...);
152156
EXPCL_PYSTUB int PyUnicodeUCS4_FromWideChar(...);
153157
EXPCL_PYSTUB int PyUnicodeUCS4_AsWideChar(...);
@@ -175,6 +179,8 @@ extern "C" {
175179
EXPCL_PYSTUB int _PyObject_CallMethod_SizeT(...);
176180
EXPCL_PYSTUB int _PyObject_DebugFree(...);
177181
EXPCL_PYSTUB int _PyObject_Del(...);
182+
EXPCL_PYSTUB int _PyUnicode_AsString(...);
183+
EXPCL_PYSTUB int _PyUnicode_AsStringAndSize(...);
178184
EXPCL_PYSTUB int _Py_BuildValue_SizeT(...);
179185
EXPCL_PYSTUB int _Py_Dealloc(...);
180186
EXPCL_PYSTUB int _Py_NegativeRefcount(...);
@@ -190,6 +196,7 @@ extern "C" {
190196
EXPCL_PYSTUB extern void *PyExc_Exception;
191197
EXPCL_PYSTUB extern void *PyExc_FutureWarning;
192198
EXPCL_PYSTUB extern void *PyExc_IndexError;
199+
EXPCL_PYSTUB extern void *PyExc_OSError;
193200
EXPCL_PYSTUB extern void *PyExc_RuntimeError;
194201
EXPCL_PYSTUB extern void *PyExc_StandardError;
195202
EXPCL_PYSTUB extern void *PyExc_StopIteration;
@@ -334,10 +341,14 @@ int PyTuple_Type(...) { return 0; };
334341
int PyType_GenericAlloc(...) { return 0; };
335342
int PyType_IsSubtype(...) { return 0; }
336343
int PyType_Ready(...) { return 0; };
344+
int PyUnicodeUCS2_FromFormat(...) { return 0; }
345+
int PyUnicodeUCS2_FromString(...) { return 0; }
337346
int PyUnicodeUCS2_FromStringAndSize(...) { return 0; }
338347
int PyUnicodeUCS2_FromWideChar(...) { return 0; }
339348
int PyUnicodeUCS2_AsWideChar(...) { return 0; }
340349
int PyUnicodeUCS2_GetSize(...) { return 0; }
350+
int PyUnicodeUCS4_FromFormat(...) { return 0; }
351+
int PyUnicodeUCS4_FromString(...) { return 0; }
341352
int PyUnicodeUCS4_FromStringAndSize(...) { return 0; }
342353
int PyUnicodeUCS4_FromWideChar(...) { return 0; }
343354
int PyUnicodeUCS4_AsWideChar(...) { return 0; }
@@ -365,6 +376,8 @@ int _PyObject_CallFunction_SizeT(...) { return 0; };
365376
int _PyObject_CallMethod_SizeT(...) { return 0; };
366377
int _PyObject_DebugFree(...) { return 0; };
367378
int _PyObject_Del(...) { return 0; };
379+
int _PyUnicode_AsString(...) { return 0; };
380+
int _PyUnicode_AsStringAndSize(...) { return 0; };
368381
int _Py_BuildValue_SizeT(...) { return 0; };
369382
int _Py_Dealloc(...) { return 0; };
370383
int _Py_NegativeRefcount(...) { return 0; };
@@ -385,6 +398,7 @@ void *PyExc_ConnectionError = (void *)NULL;
385398
void *PyExc_Exception = (void *)NULL;
386399
void *PyExc_FutureWarning = (void *)NULL;
387400
void *PyExc_IndexError = (void *)NULL;
401+
void *PyExc_OSError = (void *)NULL;
388402
void *PyExc_RuntimeError = (void *)NULL;
389403
void *PyExc_StandardError = (void *)NULL;
390404
void *PyExc_StopIteration = (void *)NULL;

panda/src/nativenet/buffered_datagramconnection.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,10 @@ inline bool Buffered_DatagramConnection::SendMessage(const Datagram &msg)
256256
#ifdef HAVE_PYTHON
257257
ostringstream s;
258258

259-
#if PY_MAJOR_VERSION >= 3
259+
#if PY_VERSION_HEX >= 0x03030000
260260
PyObject *exc_type = PyExc_ConnectionError;
261261
#else
262-
PyObject *exc_type = PyExc_StandardError;
262+
PyObject *exc_type = PyExc_OSError;
263263
#endif
264264

265265
s << endl << "Error sending message: " << endl;

0 commit comments

Comments
 (0)