mirror of
https://github.com/panda3d/panda3d.git
synced 2025-09-30 16:58:40 -04:00
dtool: Generate code using nullptr over NULL/0
This commit is contained in:
parent
e2b4353800
commit
a9ffb9630b
@ -64,13 +64,13 @@ write_code(ostream &out) {
|
||||
<< _name << "(PyObject *obj, ";
|
||||
ppointer->output_instance(out, "addr", &parser);
|
||||
out << ") {\n"
|
||||
<< " if (obj != (PyObject *)NULL && PyInstance_Check(obj)) {\n"
|
||||
<< " if (obj != nullptr && PyInstance_Check(obj)) {\n"
|
||||
// << " PyClassObject *in_class = ((PyInstanceObject
|
||||
// *)obj)->in_class;\n"
|
||||
<< " PyObject *in_dict = ((PyInstanceObject *)obj)->in_dict;\n"
|
||||
<< " if (in_dict != (PyObject *)NULL && PyDict_Check(in_dict)) {\n"
|
||||
<< " if (in_dict != nullptr && PyDict_Check(in_dict)) {\n"
|
||||
<< " PyObject *thisobj = PyDict_GetItemString(in_dict, \"this\");\n"
|
||||
<< " if (thisobj != (PyObject *)NULL && PyLong_Check(thisobj)) {\n"
|
||||
<< " if (thisobj != nullptr && PyLong_Check(thisobj)) {\n"
|
||||
<< " (*addr) = ("
|
||||
<< _pointer_type->get_local_name(&parser) << ")PyLong_AsVoidPtr(thisobj);\n"
|
||||
<< " return 1;\n"
|
||||
|
@ -62,8 +62,8 @@ write_code(ostream &out) {
|
||||
out << ", int caller_manages) {\n"
|
||||
<< " PyObject *" << classobj_func << "();\n"
|
||||
<< " PyObject *classobj = " << classobj_func << "();\n"
|
||||
<< " PyInstanceObject *instance = (PyInstanceObject *)PyInstance_New(classobj, (PyObject *)NULL, (PyObject *)NULL);\n"
|
||||
<< " if (instance != (PyInstanceObject *)NULL) {\n"
|
||||
<< " PyInstanceObject *instance = (PyInstanceObject *)PyInstance_New(classobj, nullptr, nullptr);\n"
|
||||
<< " if (instance != nullptr) {\n"
|
||||
<< " PyObject *thisptr = PyLong_FromVoidPtr((void*)addr);\n"
|
||||
<< " PyDict_SetItemString(instance->in_dict, \"this\", thisptr);\n"
|
||||
<< " }\n"
|
||||
|
@ -755,8 +755,7 @@ manage_return_value(ostream &out, int indent_level,
|
||||
out << " = " << return_expr << ";\n";
|
||||
|
||||
indent(out, indent_level)
|
||||
<< "if (" << return_expr << " != ("
|
||||
<< remap->_return_type->get_new_type()->get_local_name(&parser) << ")NULL) {\n";
|
||||
<< "if (" << return_expr << " != nullptr) {\n";
|
||||
indent(out, indent_level + 2)
|
||||
<< "(" << return_expr << ")->ref();\n";
|
||||
indent(out, indent_level)
|
||||
@ -813,8 +812,7 @@ output_ref(ostream &out, int indent_level, FunctionRemap *remap,
|
||||
// attempt to ref it.
|
||||
|
||||
indent(out, indent_level)
|
||||
<< "if (" << varname << " != ("
|
||||
<< remap->_return_type->get_new_type()->get_local_name(&parser) << ")NULL) {\n";
|
||||
<< "if (" << varname << " != nullptr) {\n";
|
||||
indent(out, indent_level + 2)
|
||||
<< varname << "->ref();\n";
|
||||
indent(out, indent_level)
|
||||
@ -847,8 +845,7 @@ output_unref(ostream &out, int indent_level, FunctionRemap *remap,
|
||||
// attempt to ref it.
|
||||
|
||||
indent(out, indent_level)
|
||||
<< "if (" << varname << " != ("
|
||||
<< remap->_return_type->get_new_type()->get_local_name(&parser) << ")NULL) {\n";
|
||||
<< "if (" << varname << " != nullptr) {\n";
|
||||
|
||||
if (TypeManager::is_pointer_to_base(remap->_return_type->get_temporary_type())) {
|
||||
// We're sure the reference count won't reach zero since we have it
|
||||
|
@ -57,13 +57,13 @@ test_assert(ostream &out, int indent_level) const {
|
||||
indent(out, indent_level + 2)
|
||||
<< "notify->clear_assert_failed();\n";
|
||||
indent(out, indent_level + 2)
|
||||
<< "return (PyObject *)NULL;\n";
|
||||
<< "return nullptr;\n";
|
||||
indent(out, indent_level)
|
||||
<< "}\n";
|
||||
indent(out, indent_level)
|
||||
<< "if (PyErr_Occurred()) {\n";
|
||||
indent(out, indent_level + 2)
|
||||
<< "return (PyObject *)NULL;\n";
|
||||
<< "return nullptr;\n";
|
||||
indent(out, indent_level)
|
||||
<< "}\n";
|
||||
out << "#endif\n";
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -132,7 +132,7 @@ private:
|
||||
static bool get_slotted_function_def(Object *obj, Function *func, FunctionRemap *remap, SlottedFunctionDef &def);
|
||||
static void write_function_slot(ostream &out, int indent_level,
|
||||
const SlottedFunctions &slots,
|
||||
const string &slot, const string &def = "0");
|
||||
const string &slot, const string &def = "nullptr");
|
||||
|
||||
void write_prototype_for_name(ostream &out, Function *func, const std::string &name);
|
||||
void write_prototype_for(ostream &out, Function *func);
|
||||
|
@ -102,17 +102,17 @@ write_module(ostream &out,ostream *out_h, InterrogateModuleDef *def) {
|
||||
<< ", METH_VARARGS },\n";
|
||||
}
|
||||
}
|
||||
out << " { NULL, NULL }\n"
|
||||
out << " { nullptr, nullptr }\n"
|
||||
<< "};\n\n"
|
||||
|
||||
<< "#if PY_MAJOR_VERSION >= 3\n"
|
||||
<< "static struct PyModuleDef python_obj_module = {\n"
|
||||
<< " PyModuleDef_HEAD_INIT,\n"
|
||||
<< " \"" << def->library_name << "\",\n"
|
||||
<< " NULL,\n"
|
||||
<< " nullptr,\n"
|
||||
<< " -1,\n"
|
||||
<< " python_obj_funcs,\n"
|
||||
<< " NULL, NULL, NULL, NULL\n"
|
||||
<< " nullptr, nullptr, nullptr, nullptr\n"
|
||||
<< "};\n\n"
|
||||
|
||||
<< "#define INIT_FUNC PyObject *PyInit_" << def->library_name << "\n"
|
||||
@ -185,7 +185,7 @@ write_class_wrapper(ostream &out, InterfaceMaker::Object *object) {
|
||||
<< " */\n"
|
||||
<< "PyObject *\n"
|
||||
<< name << "() {\n"
|
||||
<< " static PyObject *wrapper = (PyObject *)NULL;\n"
|
||||
<< " static PyObject *wrapper = nullptr;\n"
|
||||
<< " static PyMethodDef methods[] = {\n";
|
||||
|
||||
int methods_size = 0;
|
||||
@ -216,7 +216,7 @@ write_class_wrapper(ostream &out, InterfaceMaker::Object *object) {
|
||||
|
||||
out << " };\n"
|
||||
<< " static const int class_methods_size = " << class_methods_size << ";\n\n"
|
||||
<< " if (wrapper == (PyObject *)NULL) {\n"
|
||||
<< " if (wrapper == nullptr) {\n"
|
||||
<< " int i;\n"
|
||||
<< " PyObject *bases = PyTuple_New(0);\n"
|
||||
<< " PyObject *dict = PyDict_New();\n"
|
||||
@ -228,13 +228,13 @@ write_class_wrapper(ostream &out, InterfaceMaker::Object *object) {
|
||||
<< " wrapper = PyClass_New(bases, dict, name);\n"
|
||||
<< " for (i = 0; i < methods_size; ++i) {\n"
|
||||
<< " PyObject *function, *method;\n"
|
||||
<< " function = PyCFunction_New(&methods[i], (PyObject *)NULL);\n"
|
||||
<< " method = PyMethod_New(function, (PyObject *)NULL, wrapper);\n"
|
||||
<< " function = PyCFunction_New(&methods[i], nullptr);\n"
|
||||
<< " method = PyMethod_New(function, nullptr, wrapper);\n"
|
||||
<< " PyDict_SetItemString(dict, methods[i].ml_name, method);\n"
|
||||
<< " }\n"
|
||||
<< " for (i = 0; i < class_methods_size; ++i) {\n"
|
||||
<< " PyObject *function;\n"
|
||||
<< " function = PyCFunction_New(&class_methods[i], (PyObject *)NULL);\n"
|
||||
<< " function = PyCFunction_New(&class_methods[i], nullptr);\n"
|
||||
<< " PyDict_SetItemString(dict, class_methods[i].ml_name, function);\n"
|
||||
<< " }\n"
|
||||
<< " }\n"
|
||||
@ -287,7 +287,7 @@ write_function_for(ostream &out, InterfaceMaker::Function *func) {
|
||||
// different overloaded C++ function signatures.
|
||||
|
||||
out << " PyErr_SetString(PyExc_TypeError, \"" << expected_params << "\");\n"
|
||||
<< " return (PyObject *)NULL;\n";
|
||||
<< " return nullptr;\n";
|
||||
|
||||
out << "}\n\n";
|
||||
}
|
||||
@ -366,7 +366,7 @@ write_function_instance(ostream &out, int indent_level,
|
||||
format_specifiers += "O";
|
||||
parameter_list += ", &" + param_name;
|
||||
extra_convert += " PyObject *" + param_name + "_long = PyNumber_Long(" + param_name + ");";
|
||||
extra_param_check += "|| (" + param_name + "_long == NULL)";
|
||||
extra_param_check += "|| (" + param_name + "_long == nullptr)";
|
||||
pexpr_string = "PyLong_AsUnsignedLongLong(" + param_name + "_long)";
|
||||
extra_cleanup += " Py_XDECREF(" + param_name + "_long);";
|
||||
expected_params += "long";
|
||||
@ -376,7 +376,7 @@ write_function_instance(ostream &out, int indent_level,
|
||||
format_specifiers += "O";
|
||||
parameter_list += ", &" + param_name;
|
||||
extra_convert += " PyObject *" + param_name + "_long = PyNumber_Long(" + param_name + ");";
|
||||
extra_param_check += "|| (" + param_name + "_long == NULL)";
|
||||
extra_param_check += "|| (" + param_name + "_long == nullptr)";
|
||||
pexpr_string = "PyLong_AsLongLong(" + param_name + "_long)";
|
||||
extra_cleanup += " Py_XDECREF(" + param_name + "_long);";
|
||||
expected_params += "long";
|
||||
@ -386,7 +386,7 @@ write_function_instance(ostream &out, int indent_level,
|
||||
format_specifiers += "O";
|
||||
parameter_list += ", &" + param_name;
|
||||
extra_convert += " PyObject *" + param_name + "_uint = PyNumber_Long(" + param_name + ");";
|
||||
extra_param_check += "|| (" + param_name + "_uint == NULL)";
|
||||
extra_param_check += "|| (" + param_name + "_uint == nullptr)";
|
||||
pexpr_string = "(unsigned int)PyLong_AsUnsignedLong(" + param_name + "_uint)";
|
||||
extra_cleanup += " Py_XDECREF(" + param_name + "_uint);";
|
||||
expected_params += "unsigned int";
|
||||
@ -452,7 +452,7 @@ write_function_instance(ostream &out, int indent_level,
|
||||
indent(out, indent_level + 6)
|
||||
<< "PyErr_SetString(PyExc_TypeError, \"Invalid parameters.\");\n";
|
||||
indent(out, indent_level + 6)
|
||||
<< "return (PyObject *)NULL;\n";
|
||||
<< "return nullptr;\n";
|
||||
indent(out, indent_level + 4)
|
||||
<< "}\n";
|
||||
}
|
||||
|
@ -89,17 +89,17 @@ write_module(ostream &out,ostream *out_h, InterrogateModuleDef *def) {
|
||||
<< remap->_wrapper_name << ", METH_VARARGS },\n";
|
||||
}
|
||||
}
|
||||
out << " { NULL, NULL }\n"
|
||||
out << " { nullptr, nullptr }\n"
|
||||
<< "};\n\n"
|
||||
|
||||
<< "#if PY_MAJOR_VERSION >= 3\n"
|
||||
<< "static struct PyModuleDef python_simple_module = {\n"
|
||||
<< " PyModuleDef_HEAD_INIT,\n"
|
||||
<< " \"" << def->library_name << "\",\n"
|
||||
<< " NULL,\n"
|
||||
<< " nullptr,\n"
|
||||
<< " -1,\n"
|
||||
<< " python_simple_funcs,\n"
|
||||
<< " NULL, NULL, NULL, NULL\n"
|
||||
<< " nullptr, nullptr, nullptr, nullptr\n"
|
||||
<< "};\n\n"
|
||||
|
||||
<< "#define INIT_FUNC PyObject *PyInit_" << def->library_name << "\n"
|
||||
@ -285,7 +285,7 @@ void InterfaceMakerPythonSimple::write_function_instance(ostream &out, Interface
|
||||
format_specifiers += "O";
|
||||
parameter_list += ", &" + param_name;
|
||||
extra_convert += " PyObject *" + param_name + "_long = PyNumber_Long(" + param_name + ");";
|
||||
extra_param_check += "|| (" + param_name + "_long == NULL)";
|
||||
extra_param_check += "|| (" + param_name + "_long == nullptr)";
|
||||
pexpr_string = "PyLong_AsUnsignedLongLong(" + param_name + "_long)";
|
||||
extra_cleanup += " Py_XDECREF(" + param_name + "_long);";
|
||||
|
||||
@ -294,7 +294,7 @@ void InterfaceMakerPythonSimple::write_function_instance(ostream &out, Interface
|
||||
format_specifiers += "O";
|
||||
parameter_list += ", &" + param_name;
|
||||
extra_convert += " PyObject *" + param_name + "_long = PyNumber_Long(" + param_name + ");";
|
||||
extra_param_check += "|| (" + param_name + "_long == NULL)";
|
||||
extra_param_check += "|| (" + param_name + "_long == nullptr)";
|
||||
pexpr_string = "PyLong_AsLongLong(" + param_name + "_long)";
|
||||
extra_cleanup += " Py_XDECREF(" + param_name + "_long);";
|
||||
|
||||
@ -303,7 +303,7 @@ void InterfaceMakerPythonSimple::write_function_instance(ostream &out, Interface
|
||||
format_specifiers += "O";
|
||||
parameter_list += ", &" + param_name;
|
||||
extra_convert += " PyObject *" + param_name + "_uint = PyNumber_Long(" + param_name + ");";
|
||||
extra_param_check += "|| (" + param_name + "_uint == NULL)";
|
||||
extra_param_check += "|| (" + param_name + "_uint == nullptr)";
|
||||
pexpr_string = "(unsigned int)PyLong_AsUnsignedLong(" + param_name + "_uint)";
|
||||
extra_cleanup += " Py_XDECREF(" + param_name + "_uint);";
|
||||
|
||||
@ -361,7 +361,7 @@ void InterfaceMakerPythonSimple::write_function_instance(ostream &out, Interface
|
||||
out << " " << extra_cleanup << "\n";
|
||||
}
|
||||
out << " PyErr_SetString(PyExc_TypeError, \"Invalid parameters.\");\n"
|
||||
<< " return (PyObject *)NULL;\n"
|
||||
<< " return nullptr;\n"
|
||||
<< " }\n";
|
||||
}
|
||||
|
||||
@ -422,7 +422,7 @@ void InterfaceMakerPythonSimple::write_function_instance(ostream &out, Interface
|
||||
|
||||
out << " }\n";
|
||||
|
||||
out << " return (PyObject *)NULL;\n";
|
||||
out << " return nullptr;\n";
|
||||
out << "}\n\n";
|
||||
}
|
||||
|
||||
|
@ -522,7 +522,7 @@ write_code(ostream &out_code,ostream * out_include, InterrogateModuleDef *def) {
|
||||
out_code << " _in_unique_names,\n"
|
||||
<< " " << num_wrappers << ", /* num_unique_names */\n";
|
||||
} else {
|
||||
out_code << " (InterrogateUniqueNameDef *)0, /* unique_names */\n"
|
||||
out_code << " nullptr, /* unique_names */\n"
|
||||
<< " 0, /* num_unique_names */\n";
|
||||
}
|
||||
|
||||
@ -530,7 +530,7 @@ write_code(ostream &out_code,ostream * out_include, InterrogateModuleDef *def) {
|
||||
out_code << " _in_fptrs,\n"
|
||||
<< " " << num_wrappers << ", /* num_fptrs */\n";
|
||||
} else {
|
||||
out_code << " (void **)0, /* fptrs */\n"
|
||||
out_code << " nullptr, /* fptrs */\n"
|
||||
<< " 0, /* num_fptrs */\n";
|
||||
}
|
||||
|
||||
|
@ -316,10 +316,10 @@ int write_python_table_native(ostream &out) {
|
||||
<< "static struct PyModuleDef py_" << library_name << "_module = {\n"
|
||||
<< " PyModuleDef_HEAD_INIT,\n"
|
||||
<< " \"" << library_name << "\",\n"
|
||||
<< " NULL,\n"
|
||||
<< " nullptr,\n"
|
||||
<< " -1,\n"
|
||||
<< " NULL,\n"
|
||||
<< " NULL, NULL, NULL, NULL\n"
|
||||
<< " nullptr,\n"
|
||||
<< " nullptr, nullptr, nullptr, nullptr\n"
|
||||
<< "};\n"
|
||||
<< "\n"
|
||||
<< "PyObject *PyInit_" << library_name << "() {\n";
|
||||
@ -346,10 +346,10 @@ int write_python_table_native(ostream &out) {
|
||||
out << "&" << *ii << "_moddef, ";
|
||||
}
|
||||
|
||||
out << "NULL};\n"
|
||||
out << "nullptr};\n"
|
||||
<< "\n"
|
||||
<< " PyObject *module = Dtool_PyModuleInitHelper(defs, &py_" << library_name << "_module);\n"
|
||||
<< " if (module != NULL) {\n";
|
||||
<< " if (module != nullptr) {\n";
|
||||
|
||||
for (ii = libraries.begin(); ii != libraries.end(); ii++) {
|
||||
out << " Dtool_" << *ii << "_BuildInstants(module);\n";
|
||||
@ -393,10 +393,10 @@ int write_python_table_native(ostream &out) {
|
||||
out << "&" << *ii << "_moddef, ";
|
||||
}
|
||||
|
||||
out << "NULL};\n"
|
||||
out << "nullptr};\n"
|
||||
<< "\n"
|
||||
<< " PyObject *module = Dtool_PyModuleInitHelper(defs, \"" << module_name << "\");\n"
|
||||
<< " if (module != NULL) {\n";
|
||||
<< " if (module != nullptr) {\n";
|
||||
|
||||
for (ii = libraries.begin(); ii != libraries.end(); ii++) {
|
||||
out << " Dtool_" << *ii << "_BuildInstants(module);\n";
|
||||
@ -410,7 +410,7 @@ int write_python_table_native(ostream &out) {
|
||||
<< " PyErr_SetString(PyExc_ImportError, \"" << module_name << " was "
|
||||
<< "compiled for Python \" PY_VERSION \", which is incompatible "
|
||||
<< "with Python 3\");\n"
|
||||
<< " return (PyObject *)NULL;\n"
|
||||
<< " return nullptr;\n"
|
||||
<< "}\n"
|
||||
<< "#endif\n"
|
||||
<< "#endif\n"
|
||||
@ -497,17 +497,17 @@ int write_python_table(ostream &out) {
|
||||
library_name = module_name;
|
||||
}
|
||||
|
||||
out << " { NULL, NULL }\n"
|
||||
out << " { nullptr, nullptr }\n"
|
||||
<< "};\n\n"
|
||||
|
||||
<< "#if PY_MAJOR_VERSION >= 3\n"
|
||||
<< "static struct PyModuleDef python_module = {\n"
|
||||
<< " PyModuleDef_HEAD_INIT,\n"
|
||||
<< " \"" << library_name << "\",\n"
|
||||
<< " NULL,\n"
|
||||
<< " nullptr,\n"
|
||||
<< " -1,\n"
|
||||
<< " python_methods,\n"
|
||||
<< " NULL, NULL, NULL, NULL\n"
|
||||
<< " nullptr, nullptr, nullptr, nullptr\n"
|
||||
<< "};\n\n"
|
||||
|
||||
<< "#define INIT_FUNC PyObject *PyInit_" << library_name << "\n"
|
||||
|
@ -188,7 +188,7 @@ write_public_keys(Filename outfile) {
|
||||
out << " { prc_pubkey" << i << "_data, prc_pubkey" << i
|
||||
<< "_length, " << generated_time << " },\n";
|
||||
} else {
|
||||
out << " { NULL, 0, 0 },\n";
|
||||
out << " { nullptr, 0, 0 },\n";
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user