mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-01 09:23:03 -04:00
Compile with Python 3.3
This commit is contained in:
parent
d521615f3d
commit
441666fb79
@ -274,12 +274,24 @@ ns_get_environment_variable(const string &var) const {
|
||||
PyObject *obj = PySys_GetObject((char*) "argv"); // borrowed reference
|
||||
if (obj != NULL && PyList_Check(obj)) {
|
||||
PyObject *item = PyList_GetItem(obj, 0); // borrowed reference
|
||||
// Hmm, could this ever be a Unicode object?
|
||||
if (item != NULL && PyString_Check(item)) {
|
||||
char *str = PyString_AsString(item);
|
||||
if (str != (char *)NULL) {
|
||||
main_dir = Filename::from_os_specific(str);
|
||||
if (item != NULL) {
|
||||
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);
|
||||
if (str != (char *)NULL) {
|
||||
main_dir = Filename::from_os_specific(str);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2005,8 +2005,17 @@ scan_directory() const {
|
||||
PyObject *result = PyList_New(contents.size());
|
||||
for (size_t i = 0; i < contents.size(); ++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());
|
||||
#endif
|
||||
#ifdef Py_LIMITED_API
|
||||
PyList_SetItem(result, i, str);
|
||||
#else
|
||||
PyList_SET_ITEM(result, i, str);
|
||||
#endif
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -134,8 +134,17 @@ match_files(const Filename &cwd) const {
|
||||
PyObject *result = PyList_New(contents.size());
|
||||
for (size_t i = 0; i < contents.size(); ++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());
|
||||
#endif
|
||||
#ifdef Py_LIMITED_API
|
||||
PyList_SetItem(result, i, str);
|
||||
#else
|
||||
PyList_SET_ITEM(result, i, str);
|
||||
#endif
|
||||
}
|
||||
|
||||
return result;
|
||||
|
Loading…
x
Reference in New Issue
Block a user