From a9ffb9630b1556583e805e2fc7d850d5a94af434 Mon Sep 17 00:00:00 2001 From: Sam Edwards Date: Wed, 30 May 2018 14:49:41 -0600 Subject: [PATCH] dtool: Generate code using nullptr over NULL/0 --- .../functionWriterPtrFromPython.cxx | 6 +- .../interrogate/functionWriterPtrToPython.cxx | 4 +- dtool/src/interrogate/interfaceMaker.cxx | 9 +- .../src/interrogate/interfaceMakerPython.cxx | 4 +- .../interfaceMakerPythonNative.cxx | 368 +++++++++--------- .../interrogate/interfaceMakerPythonNative.h | 2 +- .../interrogate/interfaceMakerPythonObj.cxx | 26 +- .../interfaceMakerPythonSimple.cxx | 16 +- dtool/src/interrogate/interrogateBuilder.cxx | 4 +- dtool/src/interrogate/interrogate_module.cxx | 22 +- dtool/src/prckeys/makePrcKey.cxx | 2 +- 11 files changed, 230 insertions(+), 233 deletions(-) diff --git a/dtool/src/interrogate/functionWriterPtrFromPython.cxx b/dtool/src/interrogate/functionWriterPtrFromPython.cxx index d39d5f47dd..c27ef1efe5 100644 --- a/dtool/src/interrogate/functionWriterPtrFromPython.cxx +++ b/dtool/src/interrogate/functionWriterPtrFromPython.cxx @@ -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" diff --git a/dtool/src/interrogate/functionWriterPtrToPython.cxx b/dtool/src/interrogate/functionWriterPtrToPython.cxx index 23a8304528..aac2984dbc 100644 --- a/dtool/src/interrogate/functionWriterPtrToPython.cxx +++ b/dtool/src/interrogate/functionWriterPtrToPython.cxx @@ -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" diff --git a/dtool/src/interrogate/interfaceMaker.cxx b/dtool/src/interrogate/interfaceMaker.cxx index 172b8c1375..69ab181286 100644 --- a/dtool/src/interrogate/interfaceMaker.cxx +++ b/dtool/src/interrogate/interfaceMaker.cxx @@ -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 diff --git a/dtool/src/interrogate/interfaceMakerPython.cxx b/dtool/src/interrogate/interfaceMakerPython.cxx index 37125a7e64..31f59c0785 100644 --- a/dtool/src/interrogate/interfaceMakerPython.cxx +++ b/dtool/src/interrogate/interfaceMakerPython.cxx @@ -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"; diff --git a/dtool/src/interrogate/interfaceMakerPythonNative.cxx b/dtool/src/interrogate/interfaceMakerPythonNative.cxx index 13ee124698..5d6c353088 100644 --- a/dtool/src/interrogate/interfaceMakerPythonNative.cxx +++ b/dtool/src/interrogate/interfaceMakerPythonNative.cxx @@ -738,7 +738,7 @@ write_python_instance(ostream &out, int indent_level, const string &return_expr, // will be grabbing the type index (which would obviously crash when // called on a NULL pointer), so we do it here. indent(out, indent_level) - << "if (" << return_expr << " == NULL) {\n"; + << "if (" << return_expr << " == nullptr) {\n"; indent(out, indent_level) << " Py_INCREF(Py_None);\n"; indent(out, indent_level) @@ -751,7 +751,7 @@ write_python_instance(ostream &out, int indent_level, const string &return_expr, indent(out, indent_level) << " ReferenceCount *rc = " << return_expr << "->as_reference_count();\n"; indent(out, indent_level) - << " bool is_refcount = (rc != (ReferenceCount *)NULL);\n"; + << " bool is_refcount = (rc != nullptr);\n"; indent(out, indent_level) << " if (is_refcount) {\n"; indent(out, indent_level) @@ -862,24 +862,24 @@ write_prototypes(ostream &out_code, ostream *out_h) { if (TypeManager::is_reference_count(type)) { out_code << "inline static bool Dtool_ConstCoerce_" << safe_name << "(PyObject *args, CPT(" << class_name << ") &coerced) {\n" - << " nassertr(Dtool_Ptr_" << safe_name << " != NULL, false);\n" - << " nassertr(Dtool_Ptr_" << safe_name << "->_Dtool_ConstCoerce != NULL, false);\n" + << " nassertr(Dtool_Ptr_" << safe_name << " != nullptr, false);\n" + << " nassertr(Dtool_Ptr_" << safe_name << "->_Dtool_ConstCoerce != nullptr, false);\n" << " return ((bool (*)(PyObject *, CPT(" << class_name << ") &))Dtool_Ptr_" << safe_name << "->_Dtool_ConstCoerce)(args, coerced);\n" << "}\n"; if (has_coerce > 1) { out_code << "inline static bool Dtool_Coerce_" << safe_name << "(PyObject *args, PT(" << class_name << ") &coerced) {\n" - << " nassertr(Dtool_Ptr_" << safe_name << " != NULL, false);\n" - << " nassertr(Dtool_Ptr_" << safe_name << "->_Dtool_Coerce != NULL, false);\n" + << " nassertr(Dtool_Ptr_" << safe_name << " != nullptr, false);\n" + << " nassertr(Dtool_Ptr_" << safe_name << "->_Dtool_Coerce != nullptr, false);\n" << " return ((bool (*)(PyObject *, PT(" << class_name << ") &))Dtool_Ptr_" << safe_name << "->_Dtool_Coerce)(args, coerced);\n" << "}\n"; } } else { out_code << "inline static " << class_name << " *Dtool_Coerce_" << safe_name << "(PyObject *args, " << class_name << " &coerced) {\n" - << " nassertr(Dtool_Ptr_" << safe_name << " != NULL, NULL);\n" - << " nassertr(Dtool_Ptr_" << safe_name << "->_Dtool_Coerce != NULL, NULL);\n" + << " nassertr(Dtool_Ptr_" << safe_name << " != nullptr, nullptr);\n" + << " nassertr(Dtool_Ptr_" << safe_name << "->_Dtool_Coerce != nullptr, nullptr);\n" << " return ((" << class_name << " *(*)(PyObject *, " << class_name << " &))Dtool_Ptr_" << safe_name << "->_Dtool_Coerce)(args, coerced);\n" << "}\n"; } @@ -1096,8 +1096,8 @@ write_class_details(ostream &out, Object *obj) { out << "static void *Dtool_UpcastInterface_" << ClassName << "(PyObject *self, Dtool_PyTypedObject *requested_type) {\n"; out << " Dtool_PyTypedObject *type = DtoolInstance_TYPE(self);\n"; out << " if (type != &Dtool_" << ClassName << ") {\n"; - out << " printf(\"" << ClassName << " ** Bad Source Type-- Requesting Conversion from %s to %s\\n\", Py_TYPE(self)->tp_name, requested_type->_PyType.tp_name); fflush(NULL);\n";; - out << " return NULL;\n"; + out << " printf(\"" << ClassName << " ** Bad Source Type-- Requesting Conversion from %s to %s\\n\", Py_TYPE(self)->tp_name, requested_type->_PyType.tp_name); fflush(nullptr);\n";; + out << " return nullptr;\n"; out << " }\n"; out << "\n"; out << " " << cClassName << " *local_this = (" << cClassName << " *)DtoolInstance_VOID_PTR(self);\n"; @@ -1113,12 +1113,12 @@ write_class_details(ostream &out, Object *obj) { } } - out << " return NULL;\n"; + out << " return nullptr;\n"; out << "}\n\n"; out << "static void *Dtool_DowncastInterface_" << ClassName << "(void *from_this, Dtool_PyTypedObject *from_type) {\n"; - out << " if (from_this == NULL || from_type == NULL) {\n"; - out << " return NULL;\n"; + out << " if (from_this == nullptr || from_type == nullptr) {\n"; + out << " return nullptr;\n"; out << " }\n"; out << " if (from_type == Dtool_Ptr_" << ClassName << ") {\n"; out << " return from_this;\n"; @@ -1131,7 +1131,7 @@ write_class_details(ostream &out, Object *obj) { out << " }\n"; } } - out << " return (void *) NULL;\n"; + out << " return nullptr;\n"; out << "}\n\n"; } } @@ -1225,7 +1225,7 @@ write_sub_module(ostream &out, Object *obj) { _external_imports.insert(TypeManager::resolve_type(wrapped_itype._cpptype)); class_ptr = "Dtool_Ptr_" + class_name; - out << " assert(" << class_ptr << " != NULL);\n"; + out << " assert(" << class_ptr << " != nullptr);\n"; } else { class_ptr = "&Dtool_" + class_name; @@ -1462,7 +1462,7 @@ write_module_support(ostream &out, ostream *out_h, InterrogateModuleDef *def) { out << " {\"Dtool_AddToDictionary\", &Dtool_AddToDictionary, METH_VARARGS, \"Used to add items into a tp_dict\"},\n"; } - out << " {NULL, NULL, 0, NULL}\n" << "};\n\n"; + out << " {nullptr, nullptr, 0, nullptr}\n" << "};\n\n"; out << "struct LibraryDef " << def->library_name << "_moddef = {python_simple_funcs};\n"; if (out_h != nullptr) { @@ -1486,10 +1486,10 @@ write_module(ostream &out, ostream *out_h, InterrogateModuleDef *def) { << "static struct PyModuleDef python_native_module = {\n" << " PyModuleDef_HEAD_INIT,\n" << " \"" << def->module_name << "\",\n" - << " NULL,\n" + << " nullptr,\n" << " -1,\n" - << " NULL,\n" - << " NULL, NULL, NULL, NULL\n" + << " nullptr,\n" + << " nullptr, nullptr, nullptr, nullptr\n" << "};\n" << "\n" << "#ifdef _WIN32\n" @@ -1501,7 +1501,7 @@ write_module(ostream &out, ostream *out_h, InterrogateModuleDef *def) { << "#endif\n" << "\n" << "PyObject *PyInit_" << def->module_name << "() {\n" - << " LibraryDef *refs[] = {&" << def->library_name << "_moddef, NULL};\n" + << " LibraryDef *refs[] = {&" << def->library_name << "_moddef, nullptr};\n" << " PyObject *module = Dtool_PyModuleInitHelper(refs, &python_native_module);\n" << " Dtool_" << def->library_name << "_BuildInstants(module);\n" << " return module;\n" @@ -1518,7 +1518,7 @@ write_module(ostream &out, ostream *out_h, InterrogateModuleDef *def) { << "#endif\n" << "\n" << "void init" << def->module_name << "() {\n" - << " LibraryDef *refs[] = {&" << def->library_name << "_moddef, NULL};\n" + << " LibraryDef *refs[] = {&" << def->library_name << "_moddef, nullptr};\n" << " PyObject *module = Dtool_PyModuleInitHelper(refs, \"" << def->module_name << "\");\n" << " Dtool_" << def->library_name << "_BuildInstants(module);\n" << "}\n" @@ -1694,18 +1694,18 @@ write_module_class(ostream &out, Object *obj) { if (obj->_protocol_types & Object::PT_make_copy) { if (!got_copy) { - out << " {\"__copy__\", ©_from_make_copy, METH_NOARGS, NULL},\n"; + out << " {\"__copy__\", ©_from_make_copy, METH_NOARGS, nullptr},\n"; got_copy = true; } } else if (obj->_protocol_types & Object::PT_copy_constructor) { if (!got_copy) { - out << " {\"__copy__\", ©_from_copy_constructor, METH_NOARGS, NULL},\n"; + out << " {\"__copy__\", ©_from_copy_constructor, METH_NOARGS, nullptr},\n"; got_copy = true; } } if (got_copy && !got_deepcopy) { - out << " {\"__deepcopy__\", &map_deepcopy_to_copy, METH_VARARGS, NULL},\n"; + out << " {\"__deepcopy__\", &map_deepcopy_to_copy, METH_VARARGS, nullptr},\n"; } MakeSeqs::iterator msi; @@ -1727,14 +1727,14 @@ write_module_class(ostream &out, Object *obj) { string name1 = methodNameFromCppName(seq_name, export_class_name, false); string name2 = methodNameFromCppName(seq_name, export_class_name, true); out << " {\"" << name1 - << "\", (PyCFunction) &" << make_seq->_name << ", " << flags << ", NULL},\n"; + << "\", (PyCFunction) &" << make_seq->_name << ", " << flags << ", nullptr},\n"; if (name1 != name2) { out << " { \"" << name2 - << "\", (PyCFunction) &" << make_seq->_name << ", " << flags << ", NULL},\n"; + << "\", (PyCFunction) &" << make_seq->_name << ", " << flags << ", nullptr},\n"; } } - out << " {NULL, NULL, 0, NULL}\n" + out << " {nullptr, nullptr, 0, nullptr}\n" << "};\n\n"; int num_derivations = obj->_itype.number_of_derivations(); @@ -1792,9 +1792,9 @@ write_module_class(ostream &out, Object *obj) { out << "// " << ClassName << " slot " << rfi->second._answer_location << " -> " << fname << "\n"; out << "//////////////////\n"; out << "static PyObject *" << def._wrapper_name << "(PyObject *self) {\n"; - out << " " << cClassName << " *local_this = NULL;\n"; + out << " " << cClassName << " *local_this = nullptr;\n"; out << " if (!Dtool_Call_ExtractThisPointer(self, Dtool_" << ClassName << ", (void **)&local_this)) {\n"; - out << " return NULL;\n"; + out << " return nullptr;\n"; out << " }\n\n"; int return_flags = RF_pyobject | RF_err_null; @@ -1812,7 +1812,7 @@ write_module_class(ostream &out, Object *obj) { output_quoted(out, 6, expected_params); out << ");\n"; out << " }\n"; - out << " return NULL;\n"; + out << " return nullptr;\n"; out << "}\n\n"; } break; @@ -1833,19 +1833,19 @@ write_module_class(ostream &out, Object *obj) { out << "// " << ClassName << " slot " << rfi->second._answer_location << " -> " << fname << "\n"; out << "//////////////////\n"; out << "static PyObject *" << def._wrapper_name << "(PyObject *self, PyObject *arg) {\n"; - out << " " << cClassName << " *local_this = NULL;\n"; + out << " " << cClassName << " *local_this = nullptr;\n"; if (rfi->second._wrapper_type != WT_one_param) { // WT_binary_operator means we must return NotImplemented, instead // of raising an exception, if the this pointer doesn't match. // This is for things like __sub__, which Python likes to call on // the wrong-type objects. out << " DTOOL_Call_ExtractThisPointerForType(self, &Dtool_" << ClassName << ", (void **)&local_this);\n"; - out << " if (local_this == NULL) {\n"; + out << " if (local_this == nullptr) {\n"; out << " Py_INCREF(Py_NotImplemented);\n"; out << " return Py_NotImplemented;\n"; } else { out << " if (!Dtool_Call_ExtractThisPointer(self, Dtool_" << ClassName << ", (void **)&local_this)) {\n"; - out << " return NULL;\n"; + out << " return nullptr;\n"; } out << " }\n"; @@ -1862,7 +1862,7 @@ write_module_class(ostream &out, Object *obj) { output_quoted(out, 6, expected_params); out << ");\n"; out << " }\n"; - out << " return NULL;\n"; + out << " return nullptr;\n"; } out << "}\n\n"; } @@ -1876,7 +1876,7 @@ write_module_class(ostream &out, Object *obj) { out << "// " << ClassName << " slot " << rfi->second._answer_location << " -> " << fname << "\n"; out << "//////////////////\n"; out << "static int " << def._wrapper_name << "(PyObject *self, PyObject *arg, PyObject *arg2) {\n"; - out << " " << cClassName << " *local_this = NULL;\n"; + out << " " << cClassName << " *local_this = nullptr;\n"; out << " if (!Dtool_Call_ExtractThisPointer(self, Dtool_" << ClassName << ", (void **)&local_this)) {\n"; out << " return -1;\n"; out << " }\n\n"; @@ -1899,7 +1899,7 @@ write_module_class(ostream &out, Object *obj) { } out << " // Determine whether to call __setattr__ or __delattr__.\n"; - out << " if (arg2 != (PyObject *)NULL) { // __setattr__\n"; + out << " if (arg2 != nullptr) { // __setattr__\n"; if (!setattr_remaps.empty()) { out << " PyObject *args = PyTuple_Pack(2, arg, arg2);\n"; @@ -1956,17 +1956,17 @@ write_module_class(ostream &out, Object *obj) { out << "//////////////////\n"; out << "static PyObject *" << def._wrapper_name << "(PyObject *self, PyObject *arg) {\n"; out << " PyObject *res = PyObject_GenericGetAttr(self, arg);\n"; - out << " if (res != NULL) {\n"; + out << " if (res != nullptr) {\n"; out << " return res;\n"; out << " }\n"; out << " if (_PyErr_OCCURRED() != PyExc_AttributeError) {\n"; - out << " return NULL;\n"; + out << " return nullptr;\n"; out << " }\n"; out << " PyErr_Clear();\n\n"; - out << " " << cClassName << " *local_this = NULL;\n"; + out << " " << cClassName << " *local_this = nullptr;\n"; out << " if (!Dtool_Call_ExtractThisPointer(self, Dtool_" << ClassName << ", (void **)&local_this)) {\n"; - out << " return NULL;\n"; + out << " return nullptr;\n"; out << " }\n\n"; string expected_params; @@ -1975,7 +1975,7 @@ write_module_class(ostream &out, Object *obj) { RF_pyobject | RF_err_null, true); // out << " PyErr_Clear();\n"; - out << " return NULL;\n"; + out << " return nullptr;\n"; out << "}\n\n"; } break; @@ -1988,9 +1988,9 @@ write_module_class(ostream &out, Object *obj) { out << "// " << ClassName << " slot " << rfi->second._answer_location << " -> " << fname << "\n"; out << "//////////////////\n"; out << "static PyObject *" << def._wrapper_name << "(PyObject *self, Py_ssize_t index) {\n"; - out << " " << cClassName << " *local_this = NULL;\n"; + out << " " << cClassName << " *local_this = nullptr;\n"; out << " if (!Dtool_Call_ExtractThisPointer(self, Dtool_" << ClassName << ", (void **)&local_this)) {\n"; - out << " return NULL;\n"; + out << " return nullptr;\n"; out << " }\n\n"; // This is a getitem or setitem of a sequence type. This means we @@ -1999,7 +1999,7 @@ write_module_class(ostream &out, Object *obj) { // assumption that Python makes). out << " if (index < 0 || index >= (Py_ssize_t) local_this->size()) {\n"; out << " PyErr_SetString(PyExc_IndexError, \"" << ClassName << " index out of range\");\n"; - out << " return NULL;\n"; + out << " return nullptr;\n"; out << " }\n"; string expected_params; @@ -2011,7 +2011,7 @@ write_module_class(ostream &out, Object *obj) { output_quoted(out, 6, expected_params); out << ");\n"; out << " }\n"; - out << " return NULL;\n"; + out << " return nullptr;\n"; out << "}\n\n"; } break; @@ -2024,7 +2024,7 @@ write_module_class(ostream &out, Object *obj) { out << "// " << ClassName << " slot " << rfi->second._answer_location << " -> " << fname << "\n"; out << "//////////////////\n"; out << "static int " << def._wrapper_name << "(PyObject *self, Py_ssize_t index, PyObject *arg) {\n"; - out << " " << cClassName << " *local_this = NULL;\n"; + out << " " << cClassName << " *local_this = nullptr;\n"; out << " if (!Dtool_Call_ExtractThisPointer(self, Dtool_" << ClassName << ", (void **)&local_this)) {\n"; out << " return -1;\n"; out << " }\n\n"; @@ -2052,7 +2052,7 @@ write_module_class(ostream &out, Object *obj) { } string expected_params; - out << " if (arg != (PyObject *)NULL) { // __setitem__\n"; + out << " if (arg != nullptr) { // __setitem__\n"; write_function_forset(out, setitem_remaps, 2, 2, expected_params, 4, true, true, AT_single_arg, RF_int, false, true, "index"); out << " } else { // __delitem__\n"; @@ -2078,7 +2078,7 @@ write_module_class(ostream &out, Object *obj) { out << "// " << ClassName << " slot " << rfi->second._answer_location << " -> " << fname << "\n"; out << "//////////////////\n"; out << "static Py_ssize_t " << def._wrapper_name << "(PyObject *self) {\n"; - out << " " << cClassName << " *local_this = NULL;\n"; + out << " " << cClassName << " *local_this = nullptr;\n"; out << " if (!Dtool_Call_ExtractThisPointer(self, Dtool_" << ClassName << ", (void **)&local_this)) {\n"; out << " return -1;\n"; out << " }\n\n"; @@ -2098,7 +2098,7 @@ write_module_class(ostream &out, Object *obj) { out << "// " << ClassName << " slot " << rfi->second._answer_location << " -> " << fname << "\n"; out << "//////////////////\n"; out << "static int " << def._wrapper_name << "(PyObject *self, PyObject *arg, PyObject *arg2) {\n"; - out << " " << cClassName << " *local_this = NULL;\n"; + out << " " << cClassName << " *local_this = nullptr;\n"; out << " if (!Dtool_Call_ExtractThisPointer(self, Dtool_" << ClassName << ", (void **)&local_this)) {\n"; out << " return -1;\n"; out << " }\n\n"; @@ -2121,7 +2121,7 @@ write_module_class(ostream &out, Object *obj) { } string expected_params; - out << " if (arg2 != (PyObject *)NULL) { // __setitem__\n"; + out << " if (arg2 != nullptr) { // __setitem__\n"; out << " PyObject *args = PyTuple_Pack(2, arg, arg2);\n"; write_function_forset(out, setitem_remaps, 2, 2, expected_params, 4, true, true, AT_varargs, RF_int | RF_decref_args, false); @@ -2155,7 +2155,7 @@ write_module_class(ostream &out, Object *obj) { const char *container = ""; if (remap->_has_this) { - out << " " << cClassName << " *local_this = NULL;\n"; + out << " " << cClassName << " *local_this = nullptr;\n"; out << " if (!Dtool_Call_ExtractThisPointer(self, Dtool_" << ClassName << ", (void **)&local_this)) {\n"; out << " return -1;\n"; out << " }\n\n"; @@ -2183,7 +2183,7 @@ write_module_class(ostream &out, Object *obj) { out << "// " << ClassName << " slot " << rfi->second._answer_location << " -> " << fname << "\n"; out << "//////////////////\n"; out << "static int " << def._wrapper_name << "(PyObject *self, Py_buffer *buffer, int flags) {\n"; - out << " " << cClassName << " *local_this = NULL;\n"; + out << " " << cClassName << " *local_this = nullptr;\n"; out << " if (!Dtool_Call_ExtractThisPointer(self, Dtool_" << ClassName << ", (void **)&local_this)) {\n"; out << " return -1;\n"; out << " }\n\n"; @@ -2252,7 +2252,7 @@ write_module_class(ostream &out, Object *obj) { out << "// " << ClassName << " slot " << rfi->second._answer_location << " -> " << fname << "\n"; out << "//////////////////\n"; out << "static void " << def._wrapper_name << "(PyObject *self, Py_buffer *buffer) {\n"; - out << " " << cClassName << " *local_this = NULL;\n"; + out << " " << cClassName << " *local_this = nullptr;\n"; out << " if (!Dtool_Call_ExtractThisPointer(self, Dtool_" << ClassName << ", (void **)&local_this)) {\n"; out << " return;\n"; out << " }\n\n"; @@ -2336,9 +2336,9 @@ write_module_class(ostream &out, Object *obj) { out << "// " << ClassName << " slot " << rfi->second._answer_location << " -> " << fname << "\n"; out << "//////////////////\n"; out << "static PyObject *" << def._wrapper_name << "(PyObject *self, PyObject *arg, PyObject *arg2) {\n"; - out << " " << cClassName << " *local_this = NULL;\n"; + out << " " << cClassName << " *local_this = nullptr;\n"; out << " DTOOL_Call_ExtractThisPointerForType(self, &Dtool_" << ClassName << ", (void **)&local_this);\n"; - out << " if (local_this == NULL) {\n"; + out << " if (local_this == nullptr) {\n"; // WT_ternary_operator means we must return NotImplemented, instead // of raising an exception, if the this pointer doesn't match. This // is for things like __pow__, which Python likes to call on the @@ -2364,7 +2364,7 @@ write_module_class(ostream &out, Object *obj) { string expected_params; - out << " if (arg2 != (PyObject *)NULL && arg2 != Py_None) {\n"; + out << " if (arg2 != nullptr && arg2 != Py_None) {\n"; out << " PyObject *args = PyTuple_Pack(2, arg, arg2);\n"; write_function_forset(out, two_param_remaps, 2, 2, expected_params, 4, true, true, AT_varargs, RF_pyobject | RF_err_null | RF_decref_args, true); @@ -2379,7 +2379,7 @@ write_module_class(ostream &out, Object *obj) { output_quoted(out, 6, expected_params); out << ");\n"; out << " }\n"; - out << " return NULL;\n"; + out << " return nullptr;\n"; out << "}\n\n"; } break; @@ -2399,9 +2399,9 @@ write_module_class(ostream &out, Object *obj) { const char *container = ""; if (remap->_has_this) { - out << " " << cClassName << " *local_this = NULL;\n"; + out << " " << cClassName << " *local_this = nullptr;\n"; out << " DTOOL_Call_ExtractThisPointerForType(self, &Dtool_" << ClassName << ", (void **) &local_this);\n"; - out << " if (local_this == NULL) {\n"; + out << " if (local_this == nullptr) {\n"; out << " return 0;\n"; out << " }\n\n"; container = "local_this"; @@ -2424,7 +2424,7 @@ write_module_class(ostream &out, Object *obj) { out << "// " << ClassName << " slot " << rfi->second._answer_location << " -> " << fname << "\n"; out << "//////////////////\n"; out << "static int " << def._wrapper_name << "(PyObject *self, PyObject *arg) {\n"; - out << " " << cClassName << " *local_this = NULL;\n"; + out << " " << cClassName << " *local_this = nullptr;\n"; out << " if (!Dtool_Call_ExtractThisPointer(self, Dtool_" << ClassName << ", (void **)&local_this)) {\n"; out << " return -1;\n"; out << " }\n\n"; @@ -2451,7 +2451,7 @@ write_module_class(ostream &out, Object *obj) { out << "// " << ClassName << " slot " << rfi->second._answer_location << " -> " << fname << "\n"; out << "//////////////////\n"; out << "static Py_hash_t " << def._wrapper_name << "(PyObject *self) {\n"; - out << " " << cClassName << " *local_this = NULL;\n"; + out << " " << cClassName << " *local_this = nullptr;\n"; out << " if (!Dtool_Call_ExtractThisPointer(self, Dtool_" << ClassName << ", (void **)&local_this)) {\n"; out << " return -1;\n"; out << " }\n\n"; @@ -2489,9 +2489,9 @@ write_module_class(ostream &out, Object *obj) { out << "// " << ClassName << "\n"; out << "//////////////////\n"; out << "static PyObject *Dtool_Repr_" << ClassName << "(PyObject *self) {\n"; - out << " " << cClassName << " *local_this = NULL;\n"; + out << " " << cClassName << " *local_this = nullptr;\n"; out << " if (!Dtool_Call_ExtractThisPointer(self, Dtool_" << ClassName << ", (void **)&local_this)) {\n"; - out << " return NULL;\n"; + out << " return nullptr;\n"; out << " }\n\n"; out << " ostringstream os;\n"; if (need_repr == 3) { @@ -2519,9 +2519,9 @@ write_module_class(ostream &out, Object *obj) { out << "// " << ClassName << "\n"; out << "//////////////////\n"; out << "static PyObject *Dtool_Str_" << ClassName << "(PyObject *self) {\n"; - out << " " << cClassName << " *local_this = NULL;\n"; + out << " " << cClassName << " *local_this = nullptr;\n"; out << " if (!Dtool_Call_ExtractThisPointer(self, Dtool_" << ClassName << ", (void **)&local_this)) {\n"; - out << " return NULL;\n"; + out << " return nullptr;\n"; out << " }\n\n"; out << " ostringstream os;\n"; if (need_str == 2) { @@ -2542,9 +2542,9 @@ write_module_class(ostream &out, Object *obj) { out << "// " << ClassName << "\n"; out << "//////////////////\n"; out << "static PyObject *Dtool_RichCompare_" << ClassName << "(PyObject *self, PyObject *arg, int op) {\n"; - out << " " << cClassName << " *local_this = NULL;\n"; + out << " " << cClassName << " *local_this = nullptr;\n"; out << " if (!Dtool_Call_ExtractThisPointer(self, Dtool_" << ClassName << ", (void **)&local_this)) {\n"; - out << " return NULL;\n"; + out << " return nullptr;\n"; out << " }\n\n"; out << " switch (op) {\n"; @@ -2607,7 +2607,7 @@ write_module_class(ostream &out, Object *obj) { out << " if (PyErr_ExceptionMatches(PyExc_TypeError)) {\n"; out << " PyErr_Clear();\n"; out << " } else {\n"; - out << " return (PyObject *)NULL;\n"; + out << " return nullptr;\n"; out << " }\n"; out << " }\n"; out << " switch (op) {\n"; @@ -2654,7 +2654,7 @@ write_module_class(ostream &out, Object *obj) { // string name2 = methodNameFromCppName(ielem.get_name(), "", true); string getter = "&Dtool_" + ClassName + "_" + ielem.get_name() + "_Getter"; - string setter = "NULL"; + string setter = "nullptr"; if (!ielem.is_sequence() && !ielem.is_mapping() && !property->_setter_remaps.empty()) { setter = "&Dtool_" + ClassName + "_" + ielem.get_name() + "_Setter"; } @@ -2666,11 +2666,11 @@ write_module_class(ostream &out, Object *obj) { output_quoted(out, 4, ielem.get_comment()); out << ",\n "; } else { - out << ", NULL, "; + out << ", nullptr, "; } // Extra void* argument; we don't make use of it. - out << "NULL},\n"; + out << "nullptr},\n"; /*if (name1 != name2 && name1 != "__dict__") { // Add alternative spelling. @@ -2682,7 +2682,7 @@ write_module_class(ostream &out, Object *obj) { } if (num_getset != 0) { - out << " {NULL},\n"; + out << " {nullptr},\n"; out << "};\n\n"; } } @@ -2722,7 +2722,7 @@ write_module_class(ostream &out, Object *obj) { write_function_slot(out, 2, slots, "nb_coerce"); out << "#endif\n"; write_function_slot(out, 2, slots, "nb_int"); - out << " 0, // nb_long\n"; // removed in Python 3 + out << " nullptr, // nb_long\n"; // removed in Python 3 write_function_slot(out, 2, slots, "nb_float"); out << "#if PY_MAJOR_VERSION < 3\n"; write_function_slot(out, 2, slots, "nb_oct"); @@ -2769,9 +2769,9 @@ write_module_class(ostream &out, Object *obj) { write_function_slot(out, 2, slots, "sq_concat"); write_function_slot(out, 2, slots, "sq_repeat"); write_function_slot(out, 2, slots, "sq_item"); - out << " 0, // sq_slice\n"; // removed in Python 3 + out << " nullptr, // sq_slice\n"; // removed in Python 3 write_function_slot(out, 2, slots, "sq_ass_item"); - out << " 0, // sq_ass_slice\n"; // removed in Python 3 + out << " nullptr, // sq_ass_slice\n"; // removed in Python 3 write_function_slot(out, 2, slots, "sq_contains"); write_function_slot(out, 2, slots, "sq_inplace_concat"); @@ -2821,7 +2821,7 @@ write_module_class(ostream &out, Object *obj) { // Output the actual PyTypeObject definition. out << "struct Dtool_PyTypedObject Dtool_" << ClassName << " = {\n"; out << " {\n"; - out << " PyVarObject_HEAD_INIT(NULL, 0)\n"; + out << " PyVarObject_HEAD_INIT(nullptr, 0)\n"; // const char *tp_name; out << " \"" << _def->module_name << "." << export_class_name << "\",\n"; // Py_ssize_t tp_basicsize; @@ -2843,16 +2843,16 @@ write_module_class(ostream &out, Object *obj) { if (have_async) { out << " &Dtool_AsyncMethods_" << ClassName << ",\n"; } else { - out << " 0, // tp_as_async\n"; + out << " nullptr, // tp_as_async\n"; } out << "#elif PY_MAJOR_VERSION >= 3\n"; - out << " 0, // tp_reserved\n"; + out << " nullptr, // tp_reserved\n"; out << "#else\n"; if (has_hash_compare) { write_function_slot(out, 4, slots, "tp_compare", "&DTOOL_PyObject_ComparePointers"); } else { - out << " 0, // tp_compare\n"; + out << " nullptr, // tp_compare\n"; } out << "#endif\n"; @@ -2869,20 +2869,20 @@ write_module_class(ostream &out, Object *obj) { if (has_parent_class || (obj->_protocol_types & Object::PT_sequence) != 0) { out << " &Dtool_SequenceMethods_" << ClassName << ",\n"; } else { - out << " 0, // tp_as_sequence\n"; + out << " nullptr, // tp_as_sequence\n"; } // PyMappingMethods *tp_as_mapping; if (has_parent_class || (obj->_protocol_types & Object::PT_mapping) != 0) { out << " &Dtool_MappingMethods_" << ClassName << ",\n"; } else { - out << " 0, // tp_as_mapping\n"; + out << " nullptr, // tp_as_mapping\n"; } // hashfunc tp_hash; if (has_hash_compare) { write_function_slot(out, 4, slots, "tp_hash", "&DTOOL_PyObject_HashPointer"); } else { - out << " 0, // tp_hash\n"; + out << " nullptr, // tp_hash\n"; } // ternaryfunc tp_call; @@ -2906,7 +2906,7 @@ write_module_class(ostream &out, Object *obj) { if (has_parent_class || has_local_getbuffer) { out << " &Dtool_BufferProcs_" << ClassName << ",\n"; } else { - out << " 0, // tp_as_buffer\n"; + out << " nullptr, // tp_as_buffer\n"; } string gcflag; @@ -2934,15 +2934,15 @@ write_module_class(ostream &out, Object *obj) { out << ",\n"; out << "#endif\n"; } else { - out << " 0, // tp_doc\n"; + out << " nullptr, // tp_doc\n"; } // traverseproc tp_traverse; - out << " 0, // tp_traverse\n"; + out << " nullptr, // tp_traverse\n"; //write_function_slot(out, 4, slots, "tp_traverse"); // inquiry tp_clear; - out << " 0, // tp_clear\n"; + out << " nullptr, // tp_clear\n"; //write_function_slot(out, 4, slots, "tp_clear"); // richcmpfunc tp_richcompare; @@ -2953,10 +2953,10 @@ write_module_class(ostream &out, Object *obj) { out << "#if PY_MAJOR_VERSION >= 3\n"; out << " &DTOOL_PyObject_RichCompare,\n"; out << "#else\n"; - out << " 0, // tp_richcompare\n"; + out << " nullptr, // tp_richcompare\n"; out << "#endif\n"; } else { - out << " 0, // tp_richcompare\n"; + out << " nullptr, // tp_richcompare\n"; } // Py_ssize_t tp_weaklistoffset; @@ -2970,19 +2970,19 @@ write_module_class(ostream &out, Object *obj) { // struct PyMethodDef *tp_methods; out << " Dtool_Methods_" << ClassName << ",\n"; // struct PyMemberDef *tp_members; - out << " 0, // tp_members\n"; + out << " nullptr, // tp_members\n"; // struct PyGetSetDef *tp_getset; if (num_getset > 0) { out << " Dtool_Properties_" << ClassName << ",\n"; } else { - out << " 0, // tp_getset\n"; + out << " nullptr, // tp_getset\n"; } // struct _typeobject *tp_base; - out << " 0, // tp_base\n"; + out << " nullptr, // tp_base\n"; // PyObject *tp_dict; - out << " 0, // tp_dict\n"; + out << " nullptr, // tp_dict\n"; // descrgetfunc tp_descr_get; write_function_slot(out, 4, slots, "tp_descr_get"); // descrsetfunc tp_descr_set; @@ -3002,26 +3002,26 @@ write_module_class(ostream &out, Object *obj) { out << " PyObject_Del,\n"; } // inquiry tp_is_gc; - out << " 0, // tp_is_gc\n"; + out << " nullptr, // tp_is_gc\n"; // PyObject *tp_bases; - out << " 0, // tp_bases\n"; + out << " nullptr, // tp_bases\n"; // PyObject *tp_mro; - out << " 0, // tp_mro\n"; + out << " nullptr, // tp_mro\n"; // PyObject *tp_cache; - out << " 0, // tp_cache\n"; + out << " nullptr, // tp_cache\n"; // PyObject *tp_subclasses; - out << " 0, // tp_subclasses\n"; + out << " nullptr, // tp_subclasses\n"; // PyObject *tp_weaklist; - out << " 0, // tp_weaklist\n"; + out << " nullptr, // tp_weaklist\n"; // destructor tp_del; - out << " 0, // tp_del\n"; + out << " nullptr, // tp_del\n"; // unsigned int tp_version_tag out << "#if PY_VERSION_HEX >= 0x02060000\n"; out << " 0, // tp_version_tag\n"; out << "#endif\n"; // destructor tp_finalize out << "#if PY_VERSION_HEX >= 0x03040000\n"; - out << " 0, // tp_finalize\n"; + out << " nullptr, // tp_finalize\n"; out << "#endif\n"; out << " },\n"; @@ -3039,15 +3039,15 @@ write_module_class(ostream &out, Object *obj) { if (has_coerce > 1) { out << " (CoerceFunction)Dtool_Coerce_" << ClassName << ",\n"; } else { - out << " (CoerceFunction)0,\n"; + out << " nullptr,\n"; } } else { - out << " (CoerceFunction)0,\n"; + out << " nullptr,\n"; out << " (CoerceFunction)Dtool_Coerce_" << ClassName << ",\n"; } } else { - out << " (CoerceFunction)0,\n"; - out << " (CoerceFunction)0,\n"; + out << " nullptr,\n"; + out << " nullptr,\n"; } out << "};\n\n"; @@ -3067,14 +3067,14 @@ write_module_class(ostream &out, Object *obj) { if (isExportThisRun(*bi)) { baseargs += ", (PyTypeObject *)&Dtool_" + safe_name; - out << " Dtool_PyModuleClassInit_" << safe_name << "(NULL);\n"; + out << " Dtool_PyModuleClassInit_" << safe_name << "(nullptr);\n"; } else { baseargs += ", (PyTypeObject *)Dtool_Ptr_" + safe_name; - out << " assert(Dtool_Ptr_" << safe_name << " != NULL);\n" - << " assert(Dtool_Ptr_" << safe_name << "->_Dtool_ModuleClassInit != NULL);\n" - << " Dtool_Ptr_" << safe_name << "->_Dtool_ModuleClassInit(NULL);\n"; + out << " assert(Dtool_Ptr_" << safe_name << " != nullptr);\n" + << " assert(Dtool_Ptr_" << safe_name << "->_Dtool_ModuleClassInit != nullptr);\n" + << " Dtool_Ptr_" << safe_name << "->_Dtool_ModuleClassInit(nullptr);\n"; } } @@ -3131,7 +3131,7 @@ write_module_class(ostream &out, Object *obj) { std::string ClassName1 = make_safe_name(nested_obj->_itype.get_scoped_name()); std::string ClassName2 = make_safe_name(nested_obj->_itype.get_name()); out << " // Nested Object " << ClassName1 << ";\n"; - out << " Dtool_PyModuleClassInit_" << ClassName1 << "(NULL);\n"; + out << " Dtool_PyModuleClassInit_" << ClassName1 << "(nullptr);\n"; string name1 = classNameFromCppName(ClassName2, false); string name2 = classNameFromCppName(ClassName2, true); out << " PyDict_SetItemString(dict, \"" << name1 << "\", (PyObject *)&Dtool_" << ClassName1 << ");\n"; @@ -3221,7 +3221,7 @@ write_module_class(ostream &out, Object *obj) { // string name2 = methodNameFromCppName(ielem.get_name(), "", true); string getter = "&Dtool_" + ClassName + "_" + ielem.get_name() + "_Getter"; - string setter = "NULL"; + string setter = "nullptr"; if (!ielem.is_sequence() && !ielem.is_mapping() && !property->_setter_remaps.empty()) { setter = "&Dtool_" + ClassName + "_" + ielem.get_name() + "_Setter"; } @@ -3233,11 +3233,11 @@ write_module_class(ostream &out, Object *obj) { output_quoted(out, 4, ielem.get_comment()); out << ",\n "; } else { - out << ", NULL, "; + out << ", nullptr, "; } // Extra void* argument; we don't make use of it. - out << "NULL};\n"; + out << "nullptr};\n"; out << " PyDict_SetItemString(dict, \"" << name1 << "\", Dtool_NewStaticProperty(&Dtool_" << ClassName << "._PyType, &def_" << name1 << "));\n"; /* Alternative spelling: @@ -3441,7 +3441,7 @@ write_function_for_top(ostream &out, InterfaceMaker::Object *obj, InterfaceMaker output_quoted(out, 2, comment.str()); out << ";\n"; out << "#else\n"; - out << "static const char *" << func->_name << "_comment = NULL;\n"; + out << "static const char *" << func->_name << "_comment = nullptr;\n"; out << "#endif\n\n"; } @@ -3514,7 +3514,7 @@ write_function_for_name(ostream &out, Object *obj, // string class_name = remap->_cpptype->get_simple_name(); // Extract pointer from 'self' parameter. - out << " " << cClassName << " *local_this = NULL;\n"; + out << " " << cClassName << " *local_this = nullptr;\n"; if (all_nonconst) { // All remaps are non-const. Also check that this object isn't const. @@ -3538,7 +3538,7 @@ write_function_for_name(ostream &out, Object *obj, if (args_type == AT_keyword_args && !has_keywords) { // We don't actually take keyword arguments. Make sure we didn't get any. - out << " if (kwds != NULL && PyDict_Size(kwds) > 0) {\n"; + out << " if (kwds != nullptr && PyDict_Size(kwds) > 0) {\n"; out << "#ifdef NDEBUG\n"; error_raise_return(out, 4, return_flags, "TypeError", "function takes no keyword arguments"); out << "#else\n"; @@ -3564,7 +3564,7 @@ write_function_for_name(ostream &out, Object *obj, switch (args_type) { case AT_keyword_args: indent(out, 2) << "int parameter_count = (int)PyTuple_Size(args);\n"; - indent(out, 2) << "if (kwds != NULL) {\n"; + indent(out, 2) << "if (kwds != nullptr) {\n"; indent(out, 2) << " parameter_count += (int)PyDict_Size(kwds);\n"; indent(out, 2) << "}\n"; break; @@ -3623,7 +3623,7 @@ write_function_for_name(ostream &out, Object *obj, if (strip_keyword_args) { // None of the remaps take any keyword arguments, so let's check that // we take none. This saves some checks later on. - indent(out, 4) << "if (kwds == NULL || PyDict_GET_SIZE(kwds) == 0) {\n"; + indent(out, 4) << "if (kwds == nullptr || PyDict_GET_SIZE(kwds) == 0) {\n"; if (min_args == 1 && min_args == 1) { indent(out, 4) << " PyObject *arg = PyTuple_GET_ITEM(args, 0);\n"; write_function_forset(out, mii->second, min_args, max_args, expected_params, 6, @@ -3710,7 +3710,7 @@ write_function_for_name(ostream &out, Object *obj, case AT_keyword_args: out << " if (!Dtool_CheckNoArgs(args, kwds)) {\n"; out << " int parameter_count = (int)PyTuple_Size(args);\n"; - out << " if (kwds != NULL) {\n"; + out << " if (kwds != nullptr) {\n"; out << " parameter_count += (int)PyDict_Size(kwds);\n"; out << " }\n"; break; @@ -3742,7 +3742,7 @@ write_function_for_name(ostream &out, Object *obj, // Check this to be sure, as we handle the case of only 1 keyword arg in // write_function_forset (not using ParseTupleAndKeywords). out << " int parameter_count = (int)PyTuple_Size(args);\n" - " if (kwds != NULL) {\n" + " if (kwds != nullptr) {\n" " parameter_count += (int)PyDict_Size(kwds);\n" " }\n" " if (parameter_count != 1) {\n" @@ -4737,7 +4737,7 @@ write_function_instance(ostream &out, FunctionRemap *remap, extra_convert << "#if PY_VERSION_HEX >= 0x03030000\n" - << "wchar_t *" << param_name << "_str = PyUnicode_AsWideCharString(" << param_name << ", NULL);\n" + << "wchar_t *" << param_name << "_str = PyUnicode_AsWideCharString(" << param_name << ", nullptr);\n" << "#else" << "Py_ssize_t " << param_name << "_len = PyUnicode_GET_SIZE(" << param_name << ");\n" << "wchar_t *" << param_name << "_str = (wchar_t *)alloca(sizeof(wchar_t) * (" + param_name + "_len + 1));\n" @@ -4827,7 +4827,7 @@ write_function_instance(ostream &out, FunctionRemap *remap, << default_value->_str.size() << ";\n"; } } else { - indent(out, indent_level) << "const char *" << param_name << "_str = NULL;\n"; + indent(out, indent_level) << "const char *" << param_name << "_str = nullptr;\n"; indent(out, indent_level) << "Py_ssize_t " << param_name << "_len;\n"; } @@ -4839,11 +4839,11 @@ write_function_instance(ostream &out, FunctionRemap *remap, out << "#else\n"; // NB. PyString_AsStringAndSize also accepts a PyUnicode. indent(out, indent_level) << "if (PyString_AsStringAndSize(arg, (char **)&" << param_name << "_str, &" << param_name << "_len) == -1) {\n"; - indent(out, indent_level + 2) << param_name << "_str = NULL;\n"; + indent(out, indent_level + 2) << param_name << "_str = nullptr;\n"; indent(out, indent_level) << "}\n"; out << "#endif\n"; - extra_param_check << " && " << param_name << "_str != NULL"; + extra_param_check << " && " << param_name << "_str != nullptr"; } else { format_specifiers += "s#"; parameter_list += ", &" + param_name @@ -4862,7 +4862,7 @@ write_function_instance(ostream &out, FunctionRemap *remap, only_pyobjects = false; } else if (TypeManager::is_vector_unsigned_char(type)) { - indent(out, indent_level) << "unsigned char *" << param_name << "_str = NULL;\n"; + indent(out, indent_level) << "unsigned char *" << param_name << "_str = nullptr;\n"; indent(out, indent_level) << "Py_ssize_t " << param_name << "_len;\n"; if (args_type == AT_single_arg) { @@ -5409,7 +5409,7 @@ write_function_instance(ostream &out, FunctionRemap *remap, } else { indent(out, indent_level) << "PyObject *" << param_name; if (is_optional) { - out << " = NULL"; + out << " = nullptr"; } out << ";\n"; format_specifiers += "O"; @@ -5481,16 +5481,16 @@ write_function_instance(ostream &out, FunctionRemap *remap, if (is_optional && maybe_none) { extra_convert << default_expr << ";\n" - << "if (" << param_name << " != NULL && " << param_name << " != Py_None) {\n" + << "if (" << param_name << " != nullptr && " << param_name << " != Py_None) {\n" << " " << param_name << "_this"; } else if (is_optional) { extra_convert << default_expr << ";\n" - << "if (" << param_name << " != NULL) {\n" + << "if (" << param_name << " != nullptr) {\n" << " " << param_name << "_this"; } else if (maybe_none) { extra_convert - << " = NULL;\n" + << " = nullptr;\n" << "if (" << param_name << " != Py_None) {\n" << " " << param_name << "_this"; } @@ -5502,7 +5502,7 @@ write_function_instance(ostream &out, FunctionRemap *remap, extra_convert << "}\n"; } - coerce_call = "(" + param_name + "_this != NULL)"; + coerce_call = "(" + param_name + "_this != nullptr)"; pexpr_string = param_name + "_this"; } @@ -5510,9 +5510,9 @@ write_function_instance(ostream &out, FunctionRemap *remap, if (report_errors) { // We were asked to report any errors. Let's do it. if (is_optional && maybe_none) { - extra_convert << "if (" << param_name << " != NULL && " << param_name << " != Py_None && !" << coerce_call << ") {\n"; + extra_convert << "if (" << param_name << " != nullptr && " << param_name << " != Py_None && !" << coerce_call << ") {\n"; } else if (is_optional) { - extra_convert << "if (" << param_name << " != NULL && !" << coerce_call << ") {\n"; + extra_convert << "if (" << param_name << " != nullptr && !" << coerce_call << ") {\n"; } else if (maybe_none) { extra_convert << "if (" << param_name << " != Py_None && !" << coerce_call << ") {\n"; } else { @@ -5538,10 +5538,10 @@ write_function_instance(ostream &out, FunctionRemap *remap, extra_convert << "}\n"; } else if (is_optional && maybe_none) { - extra_param_check << " && (" << param_name << " == NULL || " << param_name << " == Py_None || " << coerce_call << ")"; + extra_param_check << " && (" << param_name << " == nullptr || " << param_name << " == Py_None || " << coerce_call << ")"; } else if (is_optional) { - extra_param_check << " && (" << param_name << " == NULL || " << coerce_call << ")"; + extra_param_check << " && (" << param_name << " == nullptr || " << coerce_call << ")"; } else if (maybe_none) { extra_param_check << " && (" << param_name << " == Py_None || " << coerce_call << ")"; @@ -5555,16 +5555,16 @@ write_function_instance(ostream &out, FunctionRemap *remap, if (is_optional && maybe_none) { extra_convert << default_expr << ";\n" - << "if (" << param_name << " != NULL && " << param_name << " != Py_None) {\n" + << "if (" << param_name << " != nullptr && " << param_name << " != Py_None) {\n" << " " << param_name << "_this"; } else if (is_optional) { extra_convert << default_expr << ";\n" - << "if (" << param_name << " != NULL) {\n" + << "if (" << param_name << " != nullptr) {\n" << " " << param_name << "_this"; } else if (maybe_none) { extra_convert - << " = NULL;\n" + << " = nullptr;\n" << "if (" << param_name << " != Py_None) {\n" << " " << param_name << "_this"; } @@ -5572,7 +5572,7 @@ write_function_instance(ostream &out, FunctionRemap *remap, // This function does the same thing in this case and is slightly // simpler. But maybe we should just reorganize these functions // entirely? - extra_convert << " = NULL;\n"; + extra_convert << " = nullptr;\n"; int indent_level = (is_optional || maybe_none) ? 2 : 0; indent(extra_convert, indent_level) << "DtoolInstance_GetPointer(" << param_name @@ -5591,15 +5591,15 @@ write_function_instance(ostream &out, FunctionRemap *remap, if (is_optional && maybe_none) { extra_convert << "}\n"; - extra_param_check << " && (" << param_name << " == NULL || " << param_name << " == Py_None || " << param_name << "_this != NULL)"; + extra_param_check << " && (" << param_name << " == nullptr || " << param_name << " == Py_None || " << param_name << "_this != nullptr)"; } else if (is_optional) { extra_convert << "}\n"; - extra_param_check << " && (" << param_name << " == NULL || " << param_name << "_this != NULL)"; + extra_param_check << " && (" << param_name << " == nullptr || " << param_name << "_this != nullptr)"; } else if (maybe_none) { extra_convert << "}\n"; - extra_param_check << " && (" << param_name << " == Py_None || " << param_name << "_this != NULL)"; + extra_param_check << " && (" << param_name << " == Py_None || " << param_name << "_this != nullptr)"; } else { - extra_param_check << " && " << param_name << "_this != NULL"; + extra_param_check << " && " << param_name << "_this != nullptr"; } pexpr_string = param_name + "_this"; @@ -5659,7 +5659,7 @@ write_function_instance(ostream &out, FunctionRemap *remap, // We have to use the more expensive PyArg_ParseTupleAndKeywords. clear_error = true; indent(out, indent_level) - << "static const char *keyword_list[] = {" << keyword_list << ", NULL};\n"; + << "static const char *keyword_list[] = {" << keyword_list << ", nullptr};\n"; indent(out, indent_level) << "if (PyArg_ParseTupleAndKeywords(args, kwds, \"" << format_specifiers << ":" << method_name @@ -5683,7 +5683,7 @@ write_function_instance(ostream &out, FunctionRemap *remap, } else { clear_error = true; indent(out, indent_level) - << "if ((kwds == NULL || PyDict_Size(kwds) == 0) && PyArg_UnpackTuple(args, \"" + << "if ((kwds == nullptr || PyDict_Size(kwds) == 0) && PyArg_UnpackTuple(args, \"" << methodNameFromCppName(remap, "", false) << "\", " << min_num_args << ", " << max_num_args << parameter_list << ")) {\n"; @@ -5692,7 +5692,7 @@ write_function_instance(ostream &out, FunctionRemap *remap, } else { clear_error = true; indent(out, indent_level) - << "if ((kwds == NULL || PyDict_Size(kwds) == 0) && PyArg_ParseTuple(args, \"" + << "if ((kwds == nullptr || PyDict_Size(kwds) == 0) && PyArg_ParseTuple(args, \"" << format_specifiers << ":" << method_name << "\"" << parameter_list << ")) {\n"; } @@ -5789,14 +5789,14 @@ write_function_instance(ostream &out, FunctionRemap *remap, << "PyObject *self = Dtool_new_" << make_safe_name(itype.get_scoped_name()) << "(&" << CLASS_PREFIX << make_safe_name(itype.get_scoped_name()) - << "._PyType, NULL, NULL);\n"; + << "._PyType, nullptr, nullptr);\n"; extra_cleanup << "PyObject_Del(self);\n"; } else { // XXX rdb: this isn't needed, is it, because tp_new already initializes // the instance? indent(out, indent_level) - << "DTool_PyInit_Finalize(self, NULL, &" + << "DTool_PyInit_Finalize(self, nullptr, &" << CLASS_PREFIX << make_safe_name(itype.get_scoped_name()) << ", false, false);\n"; } @@ -5889,7 +5889,7 @@ write_function_instance(ostream &out, FunctionRemap *remap, if (manage_return) { // If a constructor returns NULL, that means allocation failed. if (remap->_return_type->return_value_needs_management()) { - indent(out, indent_level) << "if (return_value == NULL) {\n"; + indent(out, indent_level) << "if (return_value == nullptr) {\n"; if ((return_flags & ~RF_pyobject) == RF_err_null) { // PyErr_NoMemory returns NULL, so allow tail call elimination. indent(out, indent_level) << " return PyErr_NoMemory();\n"; @@ -5990,7 +5990,7 @@ write_function_instance(ostream &out, FunctionRemap *remap, indent(out, indent_level) << " // TypeError raised; continue to next overload type.\n"; indent(out, indent_level) - << "} else if (exception != (PyObject *)NULL) {\n"; + << "} else if (exception != nullptr) {\n"; } if (manage_return) { @@ -6091,8 +6091,8 @@ write_function_instance(ostream &out, FunctionRemap *remap, indent(out, indent_level) << "return Py_None;\n"; } else if (return_flags & RF_preserve_null) { - indent(out, indent_level) << "if (" << return_expr << " == NULL) {\n"; - indent(out, indent_level) << " return NULL;\n"; + indent(out, indent_level) << "if (" << return_expr << " == nullptr) {\n"; + indent(out, indent_level) << " return nullptr;\n"; indent(out, indent_level) << "} else {\n"; pack_return_value(out, indent_level + 2, remap, return_expr, return_flags); indent(out, indent_level) << "}\n"; @@ -6204,7 +6204,7 @@ error_return(ostream &out, int indent_level, int return_flags) { indent(out, indent_level) << "return Py_NotImplemented;\n"; } else if (return_flags & RF_err_null) { - indent(out, indent_level) << "return NULL;\n"; + indent(out, indent_level) << "return nullptr;\n"; } else if (return_flags & RF_err_false) { indent(out, indent_level) << "return false;\n"; @@ -6304,7 +6304,7 @@ pack_return_value(ostream &out, int indent_level, FunctionRemap *remap, indent(out, indent_level); type->output_instance(out, "return_ptr", &parser); out << " = " << return_expr << ";\n"; - indent(out, indent_level) << "return_value.cheat() = NULL;\n"; + indent(out, indent_level) << "return_value.cheat() = nullptr;\n"; return_expr = "return_ptr"; } @@ -6363,9 +6363,9 @@ write_make_seq(ostream &out, Object *obj, const std::string &ClassName, if (make_seq->_length_getter->_has_this) { out << - " " << cClassName << " *local_this = NULL;\n" + " " << cClassName << " *local_this = nullptr;\n" " if (!Dtool_Call_ExtractThisPointer(self, Dtool_" << ClassName << ", (void **)&local_this)) {\n" - " return NULL;\n" + " return nullptr;\n" " }\n" " Py_ssize_t count = (Py_ssize_t)" << remap->get_call_str("local_this", pexprs) << ";\n"; } else { @@ -6391,7 +6391,7 @@ write_make_seq(ostream &out, Object *obj, const std::string &ClassName, switch (elem_getter->_args_type) { case AT_keyword_args: out << " PyTuple_SET_ITEM(&args, 0, index);\n" - " PyObject *value = " << elem_getter->_name << "(self, (PyObject *)&args, NULL);\n"; + " PyObject *value = " << elem_getter->_name << "(self, (PyObject *)&args, nullptr);\n"; break; case AT_varargs: @@ -6404,7 +6404,7 @@ write_make_seq(ostream &out, Object *obj, const std::string &ClassName, break; default: - out << " PyObject *value = " << elem_getter->_name << "(self, NULL);\n"; + out << " PyObject *value = " << elem_getter->_name << "(self, nullptr);\n"; break; } @@ -6421,7 +6421,7 @@ write_make_seq(ostream &out, Object *obj, const std::string &ClassName, out << " if (Dtool_CheckErrorOccurred()) {\n" " Py_DECREF(tuple);\n" - " return NULL;\n" + " return nullptr;\n" " }\n" " return tuple;\n" "}\n" @@ -6454,7 +6454,7 @@ write_getset(ostream &out, Object *obj, Property *property) { "static Py_ssize_t Dtool_" + ClassName + "_" + ielem.get_name() + "_Len(PyObject *self) {\n"; if (property->_length_function->_has_this) { out << - " " << cClassName << " *local_this = NULL;\n" + " " << cClassName << " *local_this = nullptr;\n" " if (!Dtool_Call_ExtractThisPointer(self, Dtool_" << ClassName << ", (void **)&local_this)) {\n" " return -1;\n" " }\n" @@ -6479,9 +6479,9 @@ write_getset(ostream &out, Object *obj, Property *property) { if (property->_has_this) { out << - " " << cClassName << " *local_this = NULL;\n" + " " << cClassName << " *local_this = nullptr;\n" " if (!Dtool_Call_ExtractThisPointer(self, Dtool_" << ClassName << ", (void **)&local_this)) {\n" - " return NULL;\n" + " return nullptr;\n" " }\n"; } @@ -6490,7 +6490,7 @@ write_getset(ostream &out, Object *obj, Property *property) { out << " if (index < 0 || index >= (Py_ssize_t)" << len_remap->get_call_str("local_this", pexprs) << ") {\n"; out << " PyErr_SetString(PyExc_IndexError, \"" << ClassName << "." << ielem.get_name() << "[] index out of range\");\n"; - out << " return NULL;\n"; + out << " return nullptr;\n"; out << " }\n"; /*if (property->_has_function != NULL) { @@ -6531,7 +6531,7 @@ write_getset(ostream &out, Object *obj, Property *property) { if (!property->_setter_remaps.empty()) { out << "static int Dtool_" + ClassName + "_" + ielem.get_name() + "_Sequence_Setitem(PyObject *self, Py_ssize_t index, PyObject *arg) {\n"; if (property->_has_this) { - out << " " << cClassName << " *local_this = NULL;\n"; + out << " " << cClassName << " *local_this = nullptr;\n"; out << " if (!Dtool_Call_ExtractThisPointer_NonConst(self, Dtool_" << ClassName << ", (void **)&local_this, \"" << classNameFromCppName(cClassName, false) << "." << ielem.get_name() << "\")) {\n"; out << " return -1;\n"; @@ -6544,7 +6544,7 @@ write_getset(ostream &out, Object *obj, Property *property) { out << " return -1;\n"; out << " }\n"; - out << " if (arg == (PyObject *)NULL) {\n"; + out << " if (arg == nullptr) {\n"; if (property->_deleter != nullptr) { if (property->_deleter->_has_this) { out << " local_this->" << property->_deleter->_ifunc.get_name() << "(index);\n"; @@ -6603,10 +6603,10 @@ write_getset(ostream &out, Object *obj, Property *property) { if (property->_inserter != nullptr) { out << "static PyObject *Dtool_" + ClassName + "_" + ielem.get_name() + "_Sequence_insert(PyObject *self, size_t index, PyObject *arg) {\n"; if (property->_has_this) { - out << " " << cClassName << " *local_this = NULL;\n"; + out << " " << cClassName << " *local_this = nullptr;\n"; out << " if (!Dtool_Call_ExtractThisPointer_NonConst(self, Dtool_" << ClassName << ", (void **)&local_this, \"" << classNameFromCppName(cClassName, false) << "." << ielem.get_name() << "\")) {\n"; - out << " return NULL;\n"; + out << " return nullptr;\n"; out << " }\n\n"; } @@ -6624,7 +6624,7 @@ write_getset(ostream &out, Object *obj, Property *property) { output_quoted(out, 6, expected_params); out << ");\n"; out << " }\n"; - out << " return NULL;\n"; + out << " return nullptr;\n"; out << "}\n\n"; } } @@ -6653,9 +6653,9 @@ write_getset(ostream &out, Object *obj, Property *property) { if (property->_has_this) { out << - " " << cClassName << " *local_this = NULL;\n" + " " << cClassName << " *local_this = nullptr;\n" " if (!Dtool_Call_ExtractThisPointer(self, Dtool_" << ClassName << ", (void **)&local_this)) {\n" - " return NULL;\n" + " return nullptr;\n" " }\n"; } @@ -6696,7 +6696,7 @@ write_getset(ostream &out, Object *obj, Property *property) { output_quoted(out, 6, expected_params); out << ");\n" " }\n" - " return NULL;\n" + " return nullptr;\n" "}\n\n"; // Write out a setitem if this is not a read-only property. @@ -6709,14 +6709,14 @@ write_getset(ostream &out, Object *obj, Property *property) { if (property->_has_this) { out << - " " << cClassName << " *local_this = NULL;\n" + " " << cClassName << " *local_this = nullptr;\n" " if (!Dtool_Call_ExtractThisPointer_NonConst(self, Dtool_" << ClassName << ", (void **)&local_this, \"" << classNameFromCppName(cClassName, false) << "." << ielem.get_name() << "\")) {\n" " return -1;\n" " }\n\n"; } - out << " if (value == (PyObject *)NULL) {\n"; + out << " if (value == nullptr) {\n"; if (property->_deleter != nullptr) { out << " PyObject *arg = key;\n"; @@ -6789,9 +6789,9 @@ write_getset(ostream &out, Object *obj, Property *property) { if (property->_has_this) { out << - " " << cClassName << " *local_this = NULL;\n" + " " << cClassName << " *local_this = nullptr;\n" " if (!Dtool_Call_ExtractThisPointer(self, Dtool_" << ClassName << ", (void **)&local_this)) {\n" - " return NULL;\n" + " return nullptr;\n" " }\n"; } @@ -6800,7 +6800,7 @@ write_getset(ostream &out, Object *obj, Property *property) { out << " if (index < 0 || index >= (Py_ssize_t)" << len_remap->get_call_str("local_this", pexprs) << ") {\n"; out << " PyErr_SetString(PyExc_IndexError, \"" << ClassName << "." << ielem.get_name() << "[] index out of range\");\n"; - out << " return NULL;\n"; + out << " return nullptr;\n"; out << " }\n"; } @@ -6838,14 +6838,14 @@ write_getset(ostream &out, Object *obj, Property *property) { if (ielem.is_mapping()) { out << "static PyObject *Dtool_" + ClassName + "_" + ielem.get_name() + "_Getter(PyObject *self, void *) {\n"; if (property->_has_this) { - out << " nassertr(self != NULL, NULL);\n"; + out << " nassertr(self != nullptr, nullptr);\n"; } if (property->_setter_remaps.empty()) { out << " Dtool_MappingWrapper *wrap = Dtool_NewMappingWrapper(self, \"" << ClassName << "." << ielem.get_name() << "\");\n"; } else { out << " Dtool_MappingWrapper *wrap = Dtool_NewMutableMappingWrapper(self, \"" << ClassName << "." << ielem.get_name() << "\");\n"; } - out << " if (wrap != NULL) {\n" + out << " if (wrap != nullptr) {\n" " wrap->_getitem_func = &Dtool_" << ClassName << "_" << ielem.get_name() << "_Mapping_Getitem;\n"; if (!property->_setter_remaps.empty()) { out << " if (!DtoolInstance_IS_CONST(self)) {\n"; @@ -6865,18 +6865,18 @@ write_getset(ostream &out, Object *obj, Property *property) { } else if (ielem.is_sequence()) { out << "static PyObject *Dtool_" + ClassName + "_" + ielem.get_name() + "_Getter(PyObject *self, void *) {\n"; if (property->_has_this) { - out << " nassertr(self != NULL, NULL);\n"; + out << " nassertr(self != nullptr, nullptr);\n"; } if (property->_setter_remaps.empty()) { out << " Dtool_SequenceWrapper *wrap = Dtool_NewSequenceWrapper(self, \"" << ClassName << "." << ielem.get_name() << "\");\n" - " if (wrap != NULL) {\n" + " if (wrap != nullptr) {\n" " wrap->_len_func = &Dtool_" << ClassName << "_" << ielem.get_name() << "_Len;\n" " wrap->_getitem_func = &Dtool_" << ClassName << "_" << ielem.get_name() << "_Sequence_Getitem;\n"; } else { out << " Dtool_MutableSequenceWrapper *wrap = Dtool_NewMutableSequenceWrapper(self, \"" << ClassName << "." << ielem.get_name() << "\");\n" - " if (wrap != NULL) {\n" + " if (wrap != nullptr) {\n" " wrap->_len_func = &Dtool_" << ClassName << "_" << ielem.get_name() << "_Len;\n" " wrap->_getitem_func = &Dtool_" << ClassName << "_" << ielem.get_name() << "_Sequence_Getitem;\n"; if (!property->_setter_remaps.empty()) { @@ -6899,14 +6899,14 @@ write_getset(ostream &out, Object *obj, Property *property) { if (remap->_has_this) { if (remap->_const_method) { - out << " const " << cClassName << " *local_this = NULL;\n"; + out << " const " << cClassName << " *local_this = nullptr;\n"; out << " if (!Dtool_Call_ExtractThisPointer(self, Dtool_" << ClassName << ", (void **)&local_this)) {\n"; } else { - out << " " << cClassName << " *local_this = NULL;\n"; + out << " " << cClassName << " *local_this = nullptr;\n"; out << " if (!Dtool_Call_ExtractThisPointer_NonConst(self, Dtool_" << ClassName << ", (void **)&local_this, \"" << classNameFromCppName(cClassName, false) << "." << ielem.get_name() << "\")) {\n"; } - out << " return NULL;\n"; + out << " return nullptr;\n"; out << " }\n\n"; } @@ -6934,14 +6934,14 @@ write_getset(ostream &out, Object *obj, Property *property) { if (!property->_setter_remaps.empty()) { out << "static int Dtool_" + ClassName + "_" + ielem.get_name() + "_Setter(PyObject *self, PyObject *arg, void *) {\n"; if (remap->_has_this) { - out << " " << cClassName << " *local_this = NULL;\n"; + out << " " << cClassName << " *local_this = nullptr;\n"; out << " if (!Dtool_Call_ExtractThisPointer_NonConst(self, Dtool_" << ClassName << ", (void **)&local_this, \"" << classNameFromCppName(cClassName, false) << "." << ielem.get_name() << "\")) {\n"; out << " return -1;\n"; out << " }\n\n"; } - out << " if (arg == (PyObject *)NULL) {\n"; + out << " if (arg == nullptr) {\n"; if (property->_deleter != nullptr && remap->_has_this) { out << " local_this->" << property->_deleter->_ifunc.get_name() << "();\n" << " return 0;\n"; diff --git a/dtool/src/interrogate/interfaceMakerPythonNative.h b/dtool/src/interrogate/interfaceMakerPythonNative.h index 2c0195fdbf..72421f307a 100644 --- a/dtool/src/interrogate/interfaceMakerPythonNative.h +++ b/dtool/src/interrogate/interfaceMakerPythonNative.h @@ -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); diff --git a/dtool/src/interrogate/interfaceMakerPythonObj.cxx b/dtool/src/interrogate/interfaceMakerPythonObj.cxx index 1f76f0cb3b..3f11acb855 100644 --- a/dtool/src/interrogate/interfaceMakerPythonObj.cxx +++ b/dtool/src/interrogate/interfaceMakerPythonObj.cxx @@ -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"; } diff --git a/dtool/src/interrogate/interfaceMakerPythonSimple.cxx b/dtool/src/interrogate/interfaceMakerPythonSimple.cxx index b7b5925a8c..8ee9552250 100644 --- a/dtool/src/interrogate/interfaceMakerPythonSimple.cxx +++ b/dtool/src/interrogate/interfaceMakerPythonSimple.cxx @@ -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"; } diff --git a/dtool/src/interrogate/interrogateBuilder.cxx b/dtool/src/interrogate/interrogateBuilder.cxx index 73ef42fcd0..1e3fdacaa7 100644 --- a/dtool/src/interrogate/interrogateBuilder.cxx +++ b/dtool/src/interrogate/interrogateBuilder.cxx @@ -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"; } diff --git a/dtool/src/interrogate/interrogate_module.cxx b/dtool/src/interrogate/interrogate_module.cxx index dfe8f3a1b5..0fe4534890 100644 --- a/dtool/src/interrogate/interrogate_module.cxx +++ b/dtool/src/interrogate/interrogate_module.cxx @@ -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" diff --git a/dtool/src/prckeys/makePrcKey.cxx b/dtool/src/prckeys/makePrcKey.cxx index f3ffe9fb44..48b8f62d9c 100644 --- a/dtool/src/prckeys/makePrcKey.cxx +++ b/dtool/src/prckeys/makePrcKey.cxx @@ -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"; } };