From c642d416cf66f6926aae1f81ee2e0a11e145938f Mon Sep 17 00:00:00 2001 From: Matthias Urlichs Date: Tue, 14 Jan 2025 09:54:22 +0100 Subject: [PATCH] more of them --- include/nanobind/nb_cast.h | 2 +- src/common.cpp | 2 +- src/implicit.cpp | 2 +- src/nb_func.cpp | 10 +++++----- src/nb_type.cpp | 18 +++++++++--------- src/trampoline.cpp | 2 +- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/include/nanobind/nb_cast.h b/include/nanobind/nb_cast.h index 5576304e..e2c2a930 100644 --- a/include/nanobind/nb_cast.h +++ b/include/nanobind/nb_cast.h @@ -466,7 +466,7 @@ template struct type_caster_base : type_caster_base_tag { if constexpr (is_pointer_v) ptr = (Type *) value; else - ptr = (Type *) &value; + ptr = (Type *) const_cast(&value); policy = infer_policy(policy); const std::type_info *type = &typeid(Type); diff --git a/src/common.cpp b/src/common.cpp index 02bc02ad..9bc80531 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -87,7 +87,7 @@ PyObject *capsule_new(const void *ptr, const char *name, cleanup_2(PyCapsule_GetPointer(o, PyCapsule_GetName(o))); }; - PyObject *c = PyCapsule_New((void *) ptr, name, capsule_cleanup); + PyObject *c = PyCapsule_New(const_cast(ptr), name, capsule_cleanup); check(c, "nanobind::detail::capsule_new(): allocation failed!"); diff --git a/src/implicit.cpp b/src/implicit.cpp index 10702a06..d29bd8a0 100644 --- a/src/implicit.cpp +++ b/src/implicit.cpp @@ -36,7 +36,7 @@ void implicitly_convertible(const std::type_info *src, if (size) memcpy(data, t->implicit.cpp, size * sizeof(void *)); - data[size] = (void *) src; + data[size] = (void *)const_cast(src); data[size + 1] = nullptr; PyMem_Free(t->implicit.cpp); t->implicit.cpp = (decltype(t->implicit.cpp)) data; diff --git a/src/nb_func.cpp b/src/nb_func.cpp index e1f38d32..bccdb1ab 100644 --- a/src/nb_func.cpp +++ b/src/nb_func.cpp @@ -99,16 +99,16 @@ void nb_func_dealloc(PyObject *self) { const arg_data &arg = f->args[j]; Py_XDECREF(arg.value); Py_XDECREF(arg.name_py); - free((char *) arg.signature); + free(const_cast(arg.signature)); } } if (f->flags & (uint32_t) func_flags::has_doc) - free((char *) f->doc); + free(const_cast(f->doc)); - free((char *) f->name); + free(const_cast(f->name)); free(f->args); - free((char *) f->descr); + free(const_cast(f->descr)); free(f->descr_types); free(f->signature); ++f; @@ -964,7 +964,7 @@ static PyObject *nb_bound_method_vectorcall(PyObject *self, bool alloc = false; if (NB_LIKELY(nargsf & NB_VECTORCALL_ARGUMENTS_OFFSET)) { - args = (PyObject **) (args_in - 1); + args = const_cast(args_in - 1); temp = args[0]; } else { size_t size = nargs + 1; diff --git a/src/nb_type.cpp b/src/nb_type.cpp index 94e07d56..6292659e 100644 --- a/src/nb_type.cpp +++ b/src/nb_type.cpp @@ -433,7 +433,7 @@ static void nb_type_dealloc(PyObject *o) { PyMem_Free(t->implicit.py); } - free((char *) t->name); + free(const_cast(t->name)); NB_SLOT(PyType_Type, tp_dealloc)(o); } @@ -988,7 +988,7 @@ static PyObject *nb_type_vectorcall(PyObject *self, PyObject *const *args_in, bool alloc = false; if (NB_LIKELY(nargsf & NB_VECTORCALL_ARGUMENTS_OFFSET)) { - args = (PyObject **) (args_in - 1); + args = const_cast(args_in - 1); temp = args[0]; } else { size_t size = nargs + 1; @@ -1074,7 +1074,7 @@ PyObject *nb_type_new(const type_init_data *t) noexcept { PyObject *tp = (PyObject *) it->second->type_py; Py_INCREF(tp); if (has_signature) - free((char *) t_name); + free(const_cast(t_name)); return tp; } } @@ -1183,7 +1183,7 @@ PyObject *nb_type_new(const type_init_data *t) noexcept { *s++ = { Py_tp_dealloc, (void *) inst_dealloc }; if (has_doc) - *s++ = { Py_tp_doc, (void *) t->doc }; + *s++ = { Py_tp_doc, (void *)const_cast(t->doc) }; vectorcallfunc type_vectorcall = nb_type_vectorcall; @@ -1355,7 +1355,7 @@ PyObject *nb_type_new(const type_init_data *t) noexcept { if (has_signature) { setattr(result, "__nb_signature__", str(t->name)); - free((char *) t_name); + free(const_cast(t_name)); } #if PY_VERSION_HEX >= 0x03090000 @@ -2137,7 +2137,7 @@ void nb_inst_copy(PyObject *dst, const PyObject *src) noexcept { if (src == dst) return; - PyTypeObject *tp = Py_TYPE((PyObject *) src); + PyTypeObject *tp = Py_TYPE(const_cast(src)); type_data *t = nb_type_data(tp); check(tp == Py_TYPE(dst) && @@ -2145,7 +2145,7 @@ void nb_inst_copy(PyObject *dst, const PyObject *src) noexcept { "nanobind::detail::nb_inst_copy(): invalid arguments!"); nb_inst *nbi = (nb_inst *) dst; - const void *src_data = inst_ptr((nb_inst *) src); + const void *src_data = inst_ptr((nb_inst *)const_cast(src)); void *dst_data = inst_ptr(nbi); if (t->flags & (uint32_t) type_flags::has_copy) @@ -2161,7 +2161,7 @@ void nb_inst_move(PyObject *dst, const PyObject *src) noexcept { if (src == dst) return; - PyTypeObject *tp = Py_TYPE((PyObject *) src); + PyTypeObject *tp = Py_TYPE(const_cast(src)); type_data *t = nb_type_data(tp); check(tp == Py_TYPE(dst) && @@ -2169,7 +2169,7 @@ void nb_inst_move(PyObject *dst, const PyObject *src) noexcept { "nanobind::detail::nb_inst_move(): invalid arguments!"); nb_inst *nbi = (nb_inst *) dst; - void *src_data = inst_ptr((nb_inst *) src); + void *src_data = inst_ptr((nb_inst *)const_cast(src)); void *dst_data = inst_ptr(nbi); if (t->flags & (uint32_t) type_flags::has_move) { diff --git a/src/trampoline.cpp b/src/trampoline.cpp index 9671efd5..685c4934 100644 --- a/src/trampoline.cpp +++ b/src/trampoline.cpp @@ -133,7 +133,7 @@ static void trampoline_enter_internal(void **data, size_t size, key = Py_None; } - data[2 * offset + 1] = (void *) name; + data[2 * offset + 1] = (void *)const_cast(name); data[2 * offset + 2] = key; if (key != None) {