Skip to content

Commit

Permalink
more of them
Browse files Browse the repository at this point in the history
  • Loading branch information
smurfix committed Jan 14, 2025
1 parent 478a79c commit c642d41
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion include/nanobind/nb_cast.h
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ template <typename Type_> struct type_caster_base : type_caster_base_tag {
if constexpr (is_pointer_v<T>)
ptr = (Type *) value;
else
ptr = (Type *) &value;
ptr = (Type *) const_cast<decltype(&value)>(&value);

policy = infer_policy<T>(policy);
const std::type_info *type = &typeid(Type);
Expand Down
2 changes: 1 addition & 1 deletion src/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<void *>(ptr), name, capsule_cleanup);

check(c, "nanobind::detail::capsule_new(): allocation failed!");

Expand Down
2 changes: 1 addition & 1 deletion src/implicit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::type_info *>(src);
data[size + 1] = nullptr;
PyMem_Free(t->implicit.cpp);
t->implicit.cpp = (decltype(t->implicit.cpp)) data;
Expand Down
10 changes: 5 additions & 5 deletions src/nb_func.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<char *>(arg.signature));
}
}

if (f->flags & (uint32_t) func_flags::has_doc)
free((char *) f->doc);
free(const_cast<char *>(f->doc));

free((char *) f->name);
free(const_cast<char *>(f->name));
free(f->args);
free((char *) f->descr);
free(const_cast<char *>(f->descr));
free(f->descr_types);
free(f->signature);
++f;
Expand Down Expand Up @@ -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<PyObject **>(args_in - 1);
temp = args[0];
} else {
size_t size = nargs + 1;
Expand Down
18 changes: 9 additions & 9 deletions src/nb_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ static void nb_type_dealloc(PyObject *o) {
PyMem_Free(t->implicit.py);
}

free((char *) t->name);
free(const_cast<char *>(t->name));
NB_SLOT(PyType_Type, tp_dealloc)(o);
}

Expand Down Expand Up @@ -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<PyObject **>(args_in - 1);
temp = args[0];
} else {
size_t size = nargs + 1;
Expand Down Expand Up @@ -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<char *>(t_name));
return tp;
}
}
Expand Down Expand Up @@ -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<char *>(t->doc) };

vectorcallfunc type_vectorcall = nb_type_vectorcall;

Expand Down Expand Up @@ -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<char *>(t_name));
}

#if PY_VERSION_HEX >= 0x03090000
Expand Down Expand Up @@ -2137,15 +2137,15 @@ 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<PyObject *>(src));
type_data *t = nb_type_data(tp);

check(tp == Py_TYPE(dst) &&
(t->flags & (uint32_t) type_flags::is_copy_constructible),
"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<PyObject *>(src));
void *dst_data = inst_ptr(nbi);

if (t->flags & (uint32_t) type_flags::has_copy)
Expand All @@ -2161,15 +2161,15 @@ 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<PyObject *>(src));
type_data *t = nb_type_data(tp);

check(tp == Py_TYPE(dst) &&
(t->flags & (uint32_t) type_flags::is_move_constructible),
"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<PyObject *>(src));
void *dst_data = inst_ptr(nbi);

if (t->flags & (uint32_t) type_flags::has_move) {
Expand Down
2 changes: 1 addition & 1 deletion src/trampoline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<char *>(name);
data[2 * offset + 2] = key;

if (key != None) {
Expand Down

0 comments on commit c642d41

Please sign in to comment.