Skip to content

Commit d434b5f

Browse files
authored
(chore): Remove deprecated c-headers (#3610)
* Remove deprecated c-headers * Update calls to old cfunctions * Add missing one * Add another missing one
1 parent f588810 commit d434b5f

File tree

4 files changed

+13
-15
lines changed

4 files changed

+13
-15
lines changed

include/pybind11/chrono.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
#include <ctime>
1818
#include <mutex>
1919

20-
#include <time.h>
21-
2220
#include <datetime.h>
2321

2422
// 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) {
108106
#else
109107
static std::mutex mtx;
110108
std::lock_guard<std::mutex> lock(mtx);
111-
std::tm *tm_ptr = localtime(time);
109+
std::tm *tm_ptr = std::localtime(time);
112110
if (tm_ptr != nullptr) {
113111
*buf = *tm_ptr;
114112
}

include/pybind11/detail/class.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -624,9 +624,9 @@ inline PyObject* make_new_python_type(const type_record &rec) {
624624
if (rec.doc && options::show_user_defined_docstrings()) {
625625
/* Allocate memory for docstring (using PyObject_MALLOC, since
626626
Python will free this later on) */
627-
size_t size = strlen(rec.doc) + 1;
627+
size_t size = std::strlen(rec.doc) + 1;
628628
tp_doc = (char *) PyObject_MALLOC(size);
629-
memcpy((void *) tp_doc, rec.doc, size);
629+
std::memcpy((void *) tp_doc, rec.doc, size);
630630
}
631631

632632
auto &internals = get_internals();

include/pybind11/embed.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,13 @@ inline wchar_t *widen_chars(const char *safe_arg) {
110110
#endif
111111

112112
# if defined(HAVE_BROKEN_MBSTOWCS) && HAVE_BROKEN_MBSTOWCS
113-
size_t count = strlen(safe_arg);
113+
size_t count = std::strlen(safe_arg);
114114
# else
115-
size_t count = mbstowcs(nullptr, safe_arg, 0);
115+
size_t count = std::mbstowcs(nullptr, safe_arg, 0);
116116
# endif
117117
if (count != static_cast<size_t>(-1)) {
118118
widened_arg = new wchar_t[count + 1];
119-
mbstowcs(widened_arg, safe_arg, count + 1);
119+
std::mbstowcs(widened_arg, safe_arg, count + 1);
120120
}
121121

122122
#if defined(_MSC_VER)

include/pybind11/pybind11.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include <string>
2424
#include <utility>
2525

26-
#include <string.h>
26+
#include <cstring>
2727

2828
#if defined(__cpp_lib_launder) && !(defined(_MSC_VER) && (_MSC_VER < 1914))
2929
# define PYBIND11_STD_LAUNDER std::launder
@@ -327,8 +327,8 @@ class cpp_function : public function {
327327
a.descr = guarded_strdup(repr(a.value).cast<std::string>().c_str());
328328
}
329329

330-
rec->is_constructor
331-
= (strcmp(rec->name, "__init__") == 0) || (strcmp(rec->name, "__setstate__") == 0);
330+
rec->is_constructor = (std::strcmp(rec->name, "__init__") == 0)
331+
|| (std::strcmp(rec->name, "__setstate__") == 0);
332332

333333
#if !defined(NDEBUG) && !defined(PYBIND11_DISABLE_NEW_STYLE_INIT_WARNING)
334334
if (rec->is_constructor && !rec->is_new_style_constructor) {
@@ -409,10 +409,10 @@ class cpp_function : public function {
409409
pybind11_fail("Internal error while parsing type signature (2)");
410410

411411
#if PY_MAJOR_VERSION < 3
412-
if (strcmp(rec->name, "__next__") == 0) {
412+
if (std::strcmp(rec->name, "__next__") == 0) {
413413
std::free(rec->name);
414414
rec->name = guarded_strdup("next");
415-
} else if (strcmp(rec->name, "__bool__") == 0) {
415+
} else if (std::strcmp(rec->name, "__bool__") == 0) {
416416
std::free(rec->name);
417417
rec->name = guarded_strdup("__nonzero__");
418418
}
@@ -1302,8 +1302,8 @@ inline void call_operator_delete(void *p, size_t s, size_t a) {
13021302

13031303
inline void add_class_method(object& cls, const char *name_, const cpp_function &cf) {
13041304
cls.attr(cf.name()) = cf;
1305-
if (strcmp(name_, "__eq__") == 0 && !cls.attr("__dict__").contains("__hash__")) {
1306-
cls.attr("__hash__") = none();
1305+
if (std::strcmp(name_, "__eq__") == 0 && !cls.attr("__dict__").contains("__hash__")) {
1306+
cls.attr("__hash__") = none();
13071307
}
13081308
}
13091309

0 commit comments

Comments
 (0)