From bf1d4d8d3fbfe109fd64c53fe401736251d839ec Mon Sep 17 00:00:00 2001 From: Aaron Gokaslan Date: Tue, 11 Jan 2022 13:36:32 -0500 Subject: [PATCH 1/4] Remove deprecated c-headers --- include/pybind11/chrono.h | 2 -- include/pybind11/pybind11.h | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/include/pybind11/chrono.h b/include/pybind11/chrono.h index 007cc17b49..42b69fe830 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 diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index 8c7545ba3a..f1ba836fee 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 From 77092ac955a976364c1fa03ad6a490bfddeb0855 Mon Sep 17 00:00:00 2001 From: Aaron Gokaslan Date: Tue, 11 Jan 2022 14:07:53 -0500 Subject: [PATCH 2/4] Update calls to old cfunctions --- include/pybind11/chrono.h | 2 +- include/pybind11/detail/class.h | 4 ++-- include/pybind11/embed.h | 2 +- include/pybind11/pybind11.h | 12 ++++++------ 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/pybind11/chrono.h b/include/pybind11/chrono.h index 42b69fe830..460a28fa5d 100644 --- a/include/pybind11/chrono.h +++ b/include/pybind11/chrono.h @@ -106,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 b9376b4c0b..cc1e40ce7a 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 af36340f36..f1c4dbc4dd 100644 --- a/include/pybind11/embed.h +++ b/include/pybind11/embed.h @@ -110,7 +110,7 @@ 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); # endif diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index f1ba836fee..363499e981 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -327,8 +327,8 @@ class cpp_function : public function { 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 @@ class cpp_function : public function { 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__"); } @@ -1295,8 +1295,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(); } } From 1a2607cf3b38991933fbc77df0cac0d4d452c1af Mon Sep 17 00:00:00 2001 From: Aaron Gokaslan Date: Tue, 11 Jan 2022 14:10:29 -0500 Subject: [PATCH 3/4] Add missing one --- include/pybind11/embed.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/pybind11/embed.h b/include/pybind11/embed.h index f1c4dbc4dd..15372108f4 100644 --- a/include/pybind11/embed.h +++ b/include/pybind11/embed.h @@ -112,7 +112,7 @@ inline wchar_t *widen_chars(const char *safe_arg) { # if defined(HAVE_BROKEN_MBSTOWCS) && HAVE_BROKEN_MBSTOWCS 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]; From 6df3d850cac9b1f8fa385bb8dd64ca281fe93de8 Mon Sep 17 00:00:00 2001 From: Aaron Gokaslan Date: Tue, 11 Jan 2022 14:12:39 -0500 Subject: [PATCH 4/4] Add another missing one --- include/pybind11/embed.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/pybind11/embed.h b/include/pybind11/embed.h index 15372108f4..9ab1ce9c0a 100644 --- a/include/pybind11/embed.h +++ b/include/pybind11/embed.h @@ -116,7 +116,7 @@ inline wchar_t *widen_chars(const char *safe_arg) { # 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)