From d434b5f31ec5e776cd002f019ad2cdab174358f3 Mon Sep 17 00:00:00 2001 From: Aaron Gokaslan Date: Tue, 11 Jan 2022 17:57:59 -0500 Subject: [PATCH] (chore): Remove deprecated c-headers (#3610) * Remove deprecated c-headers * Update calls to old cfunctions * Add missing one * Add another missing one --- include/pybind11/chrono.h | 4 +--- include/pybind11/detail/class.h | 4 ++-- include/pybind11/embed.h | 6 +++--- include/pybind11/pybind11.h | 14 +++++++------- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/include/pybind11/chrono.h b/include/pybind11/chrono.h index 007cc17b4..460a28fa5 100644 --- a/include/pybind11/chrono.h +++ b/include/pybind11/chrono.h @@ -17,8 +17,6 @@ #include #include -#include - #include // Backport the PyDateTime_DELTA functions from Python3.3 if required @@ -108,7 +106,7 @@ inline std::tm *localtime_thread_safe(const std::time_t *time, std::tm *buf) { #else static std::mutex mtx; std::lock_guard lock(mtx); - std::tm *tm_ptr = localtime(time); + std::tm *tm_ptr = std::localtime(time); if (tm_ptr != nullptr) { *buf = *tm_ptr; } diff --git a/include/pybind11/detail/class.h b/include/pybind11/detail/class.h index b9376b4c0..cc1e40ce7 100644 --- a/include/pybind11/detail/class.h +++ b/include/pybind11/detail/class.h @@ -624,9 +624,9 @@ inline PyObject* make_new_python_type(const type_record &rec) { if (rec.doc && options::show_user_defined_docstrings()) { /* Allocate memory for docstring (using PyObject_MALLOC, since Python will free this later on) */ - size_t size = strlen(rec.doc) + 1; + size_t size = std::strlen(rec.doc) + 1; tp_doc = (char *) PyObject_MALLOC(size); - memcpy((void *) tp_doc, rec.doc, size); + std::memcpy((void *) tp_doc, rec.doc, size); } auto &internals = get_internals(); diff --git a/include/pybind11/embed.h b/include/pybind11/embed.h index af36340f3..9ab1ce9c0 100644 --- a/include/pybind11/embed.h +++ b/include/pybind11/embed.h @@ -110,13 +110,13 @@ inline wchar_t *widen_chars(const char *safe_arg) { #endif # if defined(HAVE_BROKEN_MBSTOWCS) && HAVE_BROKEN_MBSTOWCS - size_t count = strlen(safe_arg); + size_t count = std::strlen(safe_arg); # else - size_t count = mbstowcs(nullptr, safe_arg, 0); + size_t count = std::mbstowcs(nullptr, safe_arg, 0); # endif if (count != static_cast(-1)) { widened_arg = new wchar_t[count + 1]; - mbstowcs(widened_arg, safe_arg, count + 1); + std::mbstowcs(widened_arg, safe_arg, count + 1); } #if defined(_MSC_VER) diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index ec60429b1..344a18c56 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -23,7 +23,7 @@ #include #include -#include +#include #if defined(__cpp_lib_launder) && !(defined(_MSC_VER) && (_MSC_VER < 1914)) # define PYBIND11_STD_LAUNDER std::launder @@ -327,8 +327,8 @@ protected: a.descr = guarded_strdup(repr(a.value).cast().c_str()); } - rec->is_constructor - = (strcmp(rec->name, "__init__") == 0) || (strcmp(rec->name, "__setstate__") == 0); + rec->is_constructor = (std::strcmp(rec->name, "__init__") == 0) + || (std::strcmp(rec->name, "__setstate__") == 0); #if !defined(NDEBUG) && !defined(PYBIND11_DISABLE_NEW_STYLE_INIT_WARNING) if (rec->is_constructor && !rec->is_new_style_constructor) { @@ -409,10 +409,10 @@ protected: pybind11_fail("Internal error while parsing type signature (2)"); #if PY_MAJOR_VERSION < 3 - if (strcmp(rec->name, "__next__") == 0) { + if (std::strcmp(rec->name, "__next__") == 0) { std::free(rec->name); rec->name = guarded_strdup("next"); - } else if (strcmp(rec->name, "__bool__") == 0) { + } else if (std::strcmp(rec->name, "__bool__") == 0) { std::free(rec->name); rec->name = guarded_strdup("__nonzero__"); } @@ -1302,8 +1302,8 @@ inline void call_operator_delete(void *p, size_t s, size_t a) { inline void add_class_method(object& cls, const char *name_, const cpp_function &cf) { cls.attr(cf.name()) = cf; - if (strcmp(name_, "__eq__") == 0 && !cls.attr("__dict__").contains("__hash__")) { - cls.attr("__hash__") = none(); + if (std::strcmp(name_, "__eq__") == 0 && !cls.attr("__dict__").contains("__hash__")) { + cls.attr("__hash__") = none(); } }