Skip to content

Commit fbcde3f

Browse files
authored
chore: enable clang-tidy check modernize-use-nullptr (#3881)
* Enable clang-tidy check modernize-use-nullptr * Sort clang-tidy * Sorted again
1 parent 30716c6 commit fbcde3f

File tree

6 files changed

+14
-13
lines changed

6 files changed

+14
-13
lines changed

.clang-tidy

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ modernize-replace-random-shuffle,
2525
modernize-shrink-to-fit,
2626
modernize-use-auto,
2727
modernize-use-bool-literals,
28+
modernize-use-default-member-init,
2829
modernize-use-equals-default,
2930
modernize-use-equals-delete,
30-
modernize-use-default-member-init,
31-
modernize-use-noexcept,
3231
modernize-use-emplace,
32+
modernize-use-noexcept,
33+
modernize-use-nullptr,
3334
modernize-use-override,
3435
modernize-use-using,
3536
*performance*,

include/pybind11/numpy.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ struct npy_api {
263263
static npy_api lookup() {
264264
module_ m = module_::import("numpy.core.multiarray");
265265
auto c = m.attr("_ARRAY_API");
266-
void **api_ptr = (void **) PyCapsule_GetPointer(c.ptr(), NULL);
266+
void **api_ptr = (void **) PyCapsule_GetPointer(c.ptr(), nullptr);
267267
npy_api api;
268268
#define DECL_NPY_API(Func) api.Func##_ = (decltype(api.Func##_)) api_ptr[API_##Func];
269269
DECL_NPY_API(PyArray_GetNDArrayCFeatureVersion);
@@ -1549,7 +1549,7 @@ class common_iterator {
15491549
void *data() const { return p_ptr; }
15501550

15511551
private:
1552-
char *p_ptr{0};
1552+
char *p_ptr{nullptr};
15531553
container_type m_strides;
15541554
};
15551555

include/pybind11/pybind11.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2489,7 +2489,7 @@ class exception : public object {
24892489
exception(handle scope, const char *name, handle base = PyExc_Exception) {
24902490
std::string full_name
24912491
= scope.attr("__name__").cast<std::string>() + std::string(".") + name;
2492-
m_ptr = PyErr_NewException(const_cast<char *>(full_name.c_str()), base.ptr(), NULL);
2492+
m_ptr = PyErr_NewException(const_cast<char *>(full_name.c_str()), base.ptr(), nullptr);
24932493
if (hasattr(scope, "__dict__") && scope.attr("__dict__").contains(name)) {
24942494
pybind11_fail("Error during initialization: multiple incompatible "
24952495
"definitions with name \""

include/pybind11/pytypes.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -600,21 +600,21 @@ inline handle get_function(handle value) {
600600
inline PyObject *dict_getitemstring(PyObject *v, const char *key) {
601601
PyObject *kv = nullptr, *rv = nullptr;
602602
kv = PyUnicode_FromString(key);
603-
if (kv == NULL) {
603+
if (kv == nullptr) {
604604
throw error_already_set();
605605
}
606606

607607
rv = PyDict_GetItemWithError(v, kv);
608608
Py_DECREF(kv);
609-
if (rv == NULL && PyErr_Occurred()) {
609+
if (rv == nullptr && PyErr_Occurred()) {
610610
throw error_already_set();
611611
}
612612
return rv;
613613
}
614614

615615
inline PyObject *dict_getitem(PyObject *v, PyObject *key) {
616616
PyObject *rv = PyDict_GetItemWithError(v, key);
617-
if (rv == NULL && PyErr_Occurred()) {
617+
if (rv == nullptr && PyErr_Occurred()) {
618618
throw error_already_set();
619619
}
620620
return rv;

tests/cross_module_gil_utils.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ void gil_acquire() { py::gil_scoped_acquire gil; }
2525

2626
constexpr char kModuleName[] = "cross_module_gil_utils";
2727

28-
struct PyModuleDef moduledef
29-
= {PyModuleDef_HEAD_INIT, kModuleName, NULL, 0, NULL, NULL, NULL, NULL, NULL};
28+
struct PyModuleDef moduledef = {
29+
PyModuleDef_HEAD_INIT, kModuleName, nullptr, 0, nullptr, nullptr, nullptr, nullptr, nullptr};
3030

3131
} // namespace
3232

3333
extern "C" PYBIND11_EXPORT PyObject *PyInit_cross_module_gil_utils() {
3434

3535
PyObject *m = PyModule_Create(&moduledef);
3636

37-
if (m != NULL) {
37+
if (m != nullptr) {
3838
static_assert(sizeof(&gil_acquire) == sizeof(void *),
3939
"Function pointer must have the same size as void*");
4040
PyModule_AddObject(

tests/test_numpy_dtypes.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,8 @@ py::list test_dtype_ctors() {
289289
dict["itemsize"] = py::int_(20);
290290
list.append(py::dtype::from_args(dict));
291291
list.append(py::dtype(names, formats, offsets, 20));
292-
list.append(py::dtype(py::buffer_info((void *) 0, sizeof(unsigned int), "I", 1)));
293-
list.append(py::dtype(py::buffer_info((void *) 0, 0, "T{i:a:f:b:}", 1)));
292+
list.append(py::dtype(py::buffer_info((void *) nullptr, sizeof(unsigned int), "I", 1)));
293+
list.append(py::dtype(py::buffer_info((void *) nullptr, 0, "T{i:a:f:b:}", 1)));
294294
list.append(py::dtype(py::detail::npy_api::NPY_DOUBLE_));
295295
return list;
296296
}

0 commit comments

Comments
 (0)