From f7105a081b381b1788a5e378aacd236b57a91d12 Mon Sep 17 00:00:00 2001 From: David Rose Date: Wed, 29 Oct 2008 00:53:27 +0000 Subject: [PATCH] raise an exception if 'this' is null --- .../interfaceMakerPythonNative.cxx | 47 ++++++++++--------- dtool/src/pystub/pystub.cxx | 2 + 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/dtool/src/interrogate/interfaceMakerPythonNative.cxx b/dtool/src/interrogate/interfaceMakerPythonNative.cxx index 7e3e802ce2..4c1a1ffcbf 100755 --- a/dtool/src/interrogate/interfaceMakerPythonNative.cxx +++ b/dtool/src/interrogate/interfaceMakerPythonNative.cxx @@ -644,9 +644,8 @@ void InterfaceMakerPythonNative::write_ClasseDetails(ostream &out, Object * obj) GetThis << " "<_itype)) { out << "//////////////////\n"; - out << "// A LocalHash(getKey) Function for this type"; + out << "// A LocalHash(getKey) Function for this type\n"; out << "// " <get_key();\n"; @@ -1368,7 +1368,7 @@ write_module_class(ostream &out, Object *obj) { if(bases.size() == 0) { out << "//////////////////\n"; - out << "// A LocalHash(This Pointer) Function for this type"; + out << "// A LocalHash(This Pointer) Function for this type\n"; out << "// " <output(os);\n"; + out << " local_this->output(os);\n"; } else { - out << " local_this->python_repr(os, \"" + out << " local_this->python_repr(os, \"" << classNameFromCppName(ClassName) << "\");\n"; } - out << " std::string ss = os.str();\n"; - out << " return PyString_FromStringAndSize(ss.data(),ss.length());\n"; - out << " };\n"; - out << " return Py_BuildValue(\"\");\n"; + out << " std::string ss = os.str();\n"; + out << " return PyString_FromStringAndSize(ss.data(),ss.length());\n"; out << "}\n"; has_local_repr = true; } @@ -1424,17 +1426,18 @@ write_module_class(ostream &out, Object *obj) { out << "{\n"; out << " "<write(os,0);\n"; - else - out << " local_this->write(os);\n"; - out << " std::string ss = os.str();\n"; - out << " return PyString_FromStringAndSize(ss.data(),ss.length());\n"; + out << " PyErr_SetString(PyExc_AttributeError, \"C++ object is not yet constructed, or already destructed.\");\n"; + out << " return NULL;\n"; out << " };\n"; - out << " return Py_BuildValue(\"\");\n"; + out << " ostringstream os;\n"; + if(need_str == 2) + out << " local_this->write(os,0);\n"; + else + out << " local_this->write(os);\n"; + out << " std::string ss = os.str();\n"; + out << " return PyString_FromStringAndSize(ss.data(),ss.length());\n"; out << "}\n"; has_local_str = true; } diff --git a/dtool/src/pystub/pystub.cxx b/dtool/src/pystub/pystub.cxx index e951ef9d22..f3158139e6 100644 --- a/dtool/src/pystub/pystub.cxx +++ b/dtool/src/pystub/pystub.cxx @@ -121,6 +121,7 @@ extern "C" { EXPCL_DTOOLCONFIG int _Py_RefTotal(...); EXPCL_DTOOLCONFIG extern void *PyExc_AssertionError; + EXPCL_DTOOLCONFIG extern void *PyExc_AttributeError; EXPCL_DTOOLCONFIG extern void *PyExc_RuntimeError; EXPCL_DTOOLCONFIG extern void *PyExc_StopIteration; EXPCL_DTOOLCONFIG extern void *PyExc_TypeError; @@ -237,6 +238,7 @@ int _Py_RefTotal(...) { return 0; }; void *PyExc_AssertionError = (void *)NULL; +void *PyExc_AttributeError = (void *)NULL; void *PyExc_RuntimeError = (void *)NULL; void *PyExc_StopIteration = (void *)NULL; void *PyExc_TypeError = (void *)NULL;