Skip to content

Commit

Permalink
(chore): Remove deprecated c-headers (#3610)
Browse files Browse the repository at this point in the history
* Remove deprecated c-headers

* Update calls to old cfunctions

* Add missing one

* Add another missing one
  • Loading branch information
Skylion007 authored Jan 11, 2022
1 parent f588810 commit d434b5f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
4 changes: 1 addition & 3 deletions include/pybind11/chrono.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
#include <ctime>
#include <mutex>

#include <time.h>

#include <datetime.h>

// Backport the PyDateTime_DELTA functions from Python3.3 if required
Expand Down Expand Up @@ -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<std::mutex> lock(mtx);
std::tm *tm_ptr = localtime(time);
std::tm *tm_ptr = std::localtime(time);
if (tm_ptr != nullptr) {
*buf = *tm_ptr;
}
Expand Down
4 changes: 2 additions & 2 deletions include/pybind11/detail/class.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions include/pybind11/embed.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<size_t>(-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)
Expand Down
14 changes: 7 additions & 7 deletions include/pybind11/pybind11.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <string>
#include <utility>

#include <string.h>
#include <cstring>

#if defined(__cpp_lib_launder) && !(defined(_MSC_VER) && (_MSC_VER < 1914))
# define PYBIND11_STD_LAUNDER std::launder
Expand Down Expand Up @@ -327,8 +327,8 @@ class cpp_function : public function {
a.descr = guarded_strdup(repr(a.value).cast<std::string>().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) {
Expand Down Expand Up @@ -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__");
}
Expand Down Expand Up @@ -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();
}
}

Expand Down

0 comments on commit d434b5f

Please sign in to comment.