mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -04:00
Fixes for Python 3.2
This commit is contained in:
parent
6bb5fdc5e0
commit
40cddd6280
@ -68,7 +68,7 @@ class panda3d_import_manager:
|
|||||||
target = dir
|
target = dir
|
||||||
break
|
break
|
||||||
if target == None:
|
if target == None:
|
||||||
raise ImportError, "Cannot find %s" % (filename)
|
raise ImportError("Cannot find %s" % (filename))
|
||||||
target = cls.os.path.abspath(target)
|
target = cls.os.path.abspath(target)
|
||||||
|
|
||||||
# And add that directory to the system library path.
|
# And add that directory to the system library path.
|
||||||
@ -110,8 +110,10 @@ class panda3d_import_manager:
|
|||||||
# Try to import it normally first.
|
# Try to import it normally first.
|
||||||
try:
|
try:
|
||||||
return __import__(name)
|
return __import__(name)
|
||||||
except ImportError, err:
|
except ImportError:
|
||||||
if str(err) != "No module named " + name:
|
_, err, _ = cls.sys.exc_info()
|
||||||
|
if str(err) != "No module named " + name and \
|
||||||
|
str(err) != "No module named '%s'" % name:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
# Hm, importing normally didn't work. Let's try imp.load_dynamic.
|
# Hm, importing normally didn't work. Let's try imp.load_dynamic.
|
||||||
@ -130,7 +132,7 @@ class panda3d_import_manager:
|
|||||||
break
|
break
|
||||||
if target == None:
|
if target == None:
|
||||||
message = "DLL loader cannot find %s." % name
|
message = "DLL loader cannot find %s." % name
|
||||||
raise ImportError, message
|
raise ImportError(message)
|
||||||
target = cls.os.path.abspath(target)
|
target = cls.os.path.abspath(target)
|
||||||
|
|
||||||
# Now import the file explicitly.
|
# Now import the file explicitly.
|
||||||
@ -173,7 +175,7 @@ class panda3d_submodule(type(sys)):
|
|||||||
return value
|
return value
|
||||||
|
|
||||||
# Not found? Raise the error that Python would normally raise.
|
# Not found? Raise the error that Python would normally raise.
|
||||||
raise AttributeError, "'module' object has no attribute '%s'" % name
|
raise AttributeError("'module' object has no attribute '%s'" % name)
|
||||||
|
|
||||||
class panda3d_multisubmodule(type(sys)):
|
class panda3d_multisubmodule(type(sys)):
|
||||||
""" Represents a submodule of 'panda3d' that represents multiple
|
""" Represents a submodule of 'panda3d' that represents multiple
|
||||||
@ -192,10 +194,11 @@ class panda3d_multisubmodule(type(sys)):
|
|||||||
for lib in self.__libraries__:
|
for lib in self.__libraries__:
|
||||||
try:
|
try:
|
||||||
self.__manager__.libimport(lib)
|
self.__manager__.libimport(lib)
|
||||||
except ImportError, msg:
|
except ImportError:
|
||||||
|
_, msg, _ = self.__manager__.sys.exc_info()
|
||||||
err.append(str(msg).rstrip('.'))
|
err.append(str(msg).rstrip('.'))
|
||||||
if len(err) > 0:
|
if len(err) > 0:
|
||||||
raise ImportError, ', '.join(err)
|
raise ImportError(', '.join(err))
|
||||||
|
|
||||||
def __getattr__(self, name):
|
def __getattr__(self, name):
|
||||||
if name == "__all__":
|
if name == "__all__":
|
||||||
@ -217,7 +220,7 @@ class panda3d_multisubmodule(type(sys)):
|
|||||||
return value
|
return value
|
||||||
|
|
||||||
# Not found? Raise the error that Python would normally raise.
|
# Not found? Raise the error that Python would normally raise.
|
||||||
raise AttributeError, "'module' object has no attribute '%s'" % name
|
raise AttributeError("'module' object has no attribute '%s'" % name)
|
||||||
|
|
||||||
class panda3d_module(type(sys)):
|
class panda3d_module(type(sys)):
|
||||||
""" Represents the main 'panda3d' module. """
|
""" Represents the main 'panda3d' module. """
|
||||||
@ -232,10 +235,11 @@ class panda3d_module(type(sys)):
|
|||||||
for module in self.modules:
|
for module in self.modules:
|
||||||
try:
|
try:
|
||||||
self.__manager__.sys.modules["panda3d.%s" % module].__load__()
|
self.__manager__.sys.modules["panda3d.%s" % module].__load__()
|
||||||
except ImportError, msg:
|
except ImportError:
|
||||||
|
_, msg, _ = self.__manager__.sys.exc_info()
|
||||||
err.append(str(msg).rstrip('.'))
|
err.append(str(msg).rstrip('.'))
|
||||||
if len(err) > 0:
|
if len(err) > 0:
|
||||||
raise ImportError, ', '.join(err)
|
raise ImportError(', '.join(err))
|
||||||
|
|
||||||
|
|
||||||
def __getattr__(self, name):
|
def __getattr__(self, name):
|
||||||
@ -250,7 +254,7 @@ class panda3d_module(type(sys)):
|
|||||||
return value
|
return value
|
||||||
|
|
||||||
# Not found? Raise the error that Python would normally raise.
|
# Not found? Raise the error that Python would normally raise.
|
||||||
raise AttributeError, "'module' object has no attribute '%s'" % name
|
raise AttributeError("'module' object has no attribute '%s'" % name)
|
||||||
|
|
||||||
# Create the fake module objects and insert them into sys.modules.
|
# Create the fake module objects and insert them into sys.modules.
|
||||||
this = panda3d_module("panda3d")
|
this = panda3d_module("panda3d")
|
||||||
|
@ -109,30 +109,42 @@ int write_python_table_native(ostream &out) {
|
|||||||
|
|
||||||
pset<std::string >::iterator ii;
|
pset<std::string >::iterator ii;
|
||||||
for(ii = Libraries.begin(); ii != Libraries.end(); ii++) {
|
for(ii = Libraries.begin(); ii != Libraries.end(); ii++) {
|
||||||
printf("Referencing Library %s\n",(*ii).c_str());
|
printf("Referencing Library %s\n",(*ii).c_str());
|
||||||
out << "extern LibraryDef "<< *ii << "_moddef ;\n";
|
out << "extern LibraryDef "<< *ii << "_moddef;\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
out << "#ifdef _WIN32\n"
|
out << "\n"
|
||||||
<< "extern \"C\" __declspec(dllexport) void init" << library_name << "();\n"
|
<< "#if PY_MAJOR_VERSION >= 3\n"
|
||||||
|
<< "#define INIT_FUNC PyObject *PyInit_" << library_name << "\n"
|
||||||
<< "#else\n"
|
<< "#else\n"
|
||||||
<< "extern \"C\" void init" << library_name << "();\n"
|
<< "#define INIT_FUNC void init" << library_name << "\n"
|
||||||
<< "#endif\n\n"
|
<< "#endif\n\n"
|
||||||
<< "void init" << library_name << "() \n{\n";
|
|
||||||
|
<< "#ifdef _WIN32\n"
|
||||||
|
<< "extern \"C\" __declspec(dllexport) INIT_FUNC();\n"
|
||||||
|
<< "#else\n"
|
||||||
|
<< "extern \"C\" INIT_FUNC();\n"
|
||||||
|
<< "#endif\n\n"
|
||||||
|
|
||||||
|
<< "INIT_FUNC() {\n";
|
||||||
|
|
||||||
if (track_interpreter) {
|
if (track_interpreter) {
|
||||||
out << " in_interpreter = 1;\n";
|
out << " in_interpreter = 1;\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
out << " LibraryDef *defs[] = {";
|
out << " LibraryDef *defs[] = {";
|
||||||
for(ii = Libraries.begin(); ii != Libraries.end(); ii++)
|
for(ii = Libraries.begin(); ii != Libraries.end(); ii++) {
|
||||||
out << "&"<< *ii << "_moddef,";
|
out << "&"<< *ii << "_moddef, ";
|
||||||
|
}
|
||||||
|
|
||||||
out << " NULL };\n ";
|
out << "NULL};\n\n";
|
||||||
|
|
||||||
|
out << "#if PY_MAJOR_VERSION >= 3\n";
|
||||||
out << " Dtool_PyModuleInitHelper( defs, \"" << library_name << "\");\n";
|
out << " return Dtool_PyModuleInitHelper(defs, \"" << library_name << "\");\n";
|
||||||
out << "\n\n\n}\n";
|
out << "#else\n";
|
||||||
|
out << " Dtool_PyModuleInitHelper(defs, \"" << library_name << "\");\n";
|
||||||
|
out << "#endif\n";
|
||||||
|
out << "}\n";
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
@ -51,6 +51,11 @@ PythonTask(PyObject *function, const string &name) :
|
|||||||
// Ensure that the Python threading system is initialized and ready
|
// Ensure that the Python threading system is initialized and ready
|
||||||
// to go.
|
// to go.
|
||||||
#ifdef WITH_THREAD // This symbol defined within Python.h
|
#ifdef WITH_THREAD // This symbol defined within Python.h
|
||||||
|
|
||||||
|
#if PY_VERSION_HEX >= 0x03020000
|
||||||
|
Py_Initialize();
|
||||||
|
#endif
|
||||||
|
|
||||||
PyEval_InitThreads();
|
PyEval_InitThreads();
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
@ -70,6 +70,11 @@ Thread(const string &name, const string &sync_name) :
|
|||||||
// Ensure that the Python threading system is initialized and ready
|
// Ensure that the Python threading system is initialized and ready
|
||||||
// to go.
|
// to go.
|
||||||
#ifdef WITH_THREAD // This symbol defined within Python.h
|
#ifdef WITH_THREAD // This symbol defined within Python.h
|
||||||
|
|
||||||
|
#if PY_VERSION_HEX >= 0x03020000
|
||||||
|
Py_Initialize();
|
||||||
|
#endif
|
||||||
|
|
||||||
PyEval_InitThreads();
|
PyEval_InitThreads();
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
@ -523,6 +523,11 @@ init_pointers() {
|
|||||||
#ifdef HAVE_PYTHON
|
#ifdef HAVE_PYTHON
|
||||||
// Ensure that the Python threading system is initialized and ready
|
// Ensure that the Python threading system is initialized and ready
|
||||||
// to go.
|
// to go.
|
||||||
|
|
||||||
|
#if PY_VERSION_HEX >= 0x03020000
|
||||||
|
Py_Initialize();
|
||||||
|
#endif
|
||||||
|
|
||||||
PyEval_InitThreads();
|
PyEval_InitThreads();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,11 @@ PythonCallbackObject(PyObject *function) {
|
|||||||
// Ensure that the Python threading system is initialized and ready
|
// Ensure that the Python threading system is initialized and ready
|
||||||
// to go.
|
// to go.
|
||||||
#ifdef WITH_THREAD // This symbol defined within Python.h
|
#ifdef WITH_THREAD // This symbol defined within Python.h
|
||||||
|
|
||||||
|
#if PY_VERSION_HEX >= 0x03020000
|
||||||
|
Py_Initialize();
|
||||||
|
#endif
|
||||||
|
|
||||||
PyEval_InitThreads();
|
PyEval_InitThreads();
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user