mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-02 01:44:06 -04:00
Compile with Python 3.3
This commit is contained in:
parent
d521615f3d
commit
441666fb79
@ -274,13 +274,25 @@ ns_get_environment_variable(const string &var) const {
|
|||||||
PyObject *obj = PySys_GetObject((char*) "argv"); // borrowed reference
|
PyObject *obj = PySys_GetObject((char*) "argv"); // borrowed reference
|
||||||
if (obj != NULL && PyList_Check(obj)) {
|
if (obj != NULL && PyList_Check(obj)) {
|
||||||
PyObject *item = PyList_GetItem(obj, 0); // borrowed reference
|
PyObject *item = PyList_GetItem(obj, 0); // borrowed reference
|
||||||
// Hmm, could this ever be a Unicode object?
|
if (item != NULL) {
|
||||||
if (item != NULL && PyString_Check(item)) {
|
if (PyUnicode_Check(item)) {
|
||||||
|
Py_ssize_t size = PyUnicode_GetSize(item);
|
||||||
|
wchar_t *data = new wchar_t[size];
|
||||||
|
if (PyUnicode_AsWideChar(item, data, size) != -1) {
|
||||||
|
wstring wstr (data, size);
|
||||||
|
main_dir = Filename::from_os_specific_w(wstr);
|
||||||
|
}
|
||||||
|
delete data;
|
||||||
|
}
|
||||||
|
#if PY_MAJOR_VERSION < 3
|
||||||
|
else if (PyString_Check(item)) {
|
||||||
char *str = PyString_AsString(item);
|
char *str = PyString_AsString(item);
|
||||||
if (str != (char *)NULL) {
|
if (str != (char *)NULL) {
|
||||||
main_dir = Filename::from_os_specific(str);
|
main_dir = Filename::from_os_specific(str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PyGILState_Release(state);
|
PyGILState_Release(state);
|
||||||
|
@ -2005,8 +2005,17 @@ scan_directory() const {
|
|||||||
PyObject *result = PyList_New(contents.size());
|
PyObject *result = PyList_New(contents.size());
|
||||||
for (size_t i = 0; i < contents.size(); ++i) {
|
for (size_t i = 0; i < contents.size(); ++i) {
|
||||||
const string &filename = contents[i];
|
const string &filename = contents[i];
|
||||||
|
#if PY_MAJOR_VERSION >= 3
|
||||||
|
// This function expects UTF-8.
|
||||||
|
PyObject *str = PyUnicode_FromStringAndSize(filename.data(), filename.size());
|
||||||
|
#else
|
||||||
PyObject *str = PyString_FromStringAndSize(filename.data(), filename.size());
|
PyObject *str = PyString_FromStringAndSize(filename.data(), filename.size());
|
||||||
|
#endif
|
||||||
|
#ifdef Py_LIMITED_API
|
||||||
|
PyList_SetItem(result, i, str);
|
||||||
|
#else
|
||||||
PyList_SET_ITEM(result, i, str);
|
PyList_SET_ITEM(result, i, str);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -134,8 +134,17 @@ match_files(const Filename &cwd) const {
|
|||||||
PyObject *result = PyList_New(contents.size());
|
PyObject *result = PyList_New(contents.size());
|
||||||
for (size_t i = 0; i < contents.size(); ++i) {
|
for (size_t i = 0; i < contents.size(); ++i) {
|
||||||
const string &filename = contents[i];
|
const string &filename = contents[i];
|
||||||
|
#if PY_MAJOR_VERSION >= 3
|
||||||
|
// This function expects UTF-8.
|
||||||
|
PyObject *str = PyUnicode_FromStringAndSize(filename.data(), filename.size());
|
||||||
|
#else
|
||||||
PyObject *str = PyString_FromStringAndSize(filename.data(), filename.size());
|
PyObject *str = PyString_FromStringAndSize(filename.data(), filename.size());
|
||||||
|
#endif
|
||||||
|
#ifdef Py_LIMITED_API
|
||||||
|
PyList_SetItem(result, i, str);
|
||||||
|
#else
|
||||||
PyList_SET_ITEM(result, i, str);
|
PyList_SET_ITEM(result, i, str);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user