|
19 | 19 | # pragma warning(disable: 4100) // warning C4100: Unreferenced formal parameter
|
20 | 20 | # pragma warning(disable: 4127) // warning C4127: Conditional expression is constant
|
21 | 21 | # pragma warning(disable: 4800) // warning C4800: 'int': forcing value to bool 'true' or 'false' (performance warning)
|
22 |
| -# pragma warning(disable: 4996) // warning C4996: The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name |
23 | 22 | # pragma warning(disable: 4522) // warning C4522: multiple assignment operators specified
|
24 | 23 | # pragma warning(disable: 4505) // warning C4505: 'PySlice_GetIndicesEx': unreferenced local function has been removed (PyPy only)
|
25 | 24 | #elif defined(__GNUG__) && !defined(__clang__)
|
|
43 | 42 | #include <string>
|
44 | 43 | #include <utility>
|
45 | 44 |
|
| 45 | +#include <string.h> |
| 46 | + |
46 | 47 | #if defined(__cpp_lib_launder) && !(defined(_MSC_VER) && (_MSC_VER < 1914))
|
47 | 48 | # define PYBIND11_STD_LAUNDER std::launder
|
48 | 49 | # define PYBIND11_HAS_STD_LAUNDER 1
|
|
56 | 57 |
|
57 | 58 | PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
|
58 | 59 |
|
| 60 | +#if defined(_MSC_VER) |
| 61 | +# define PYBIND11_COMPAT_STRDUP _strdup |
| 62 | +#else |
| 63 | +# define PYBIND11_COMPAT_STRDUP strdup |
| 64 | +#endif |
| 65 | + |
59 | 66 | /// Wraps an arbitrary C++ function/method/lambda function/.. into a callable Python object
|
60 | 67 | class cpp_function : public function {
|
61 | 68 | public:
|
@@ -253,7 +260,7 @@ class cpp_function : public function {
|
253 | 260 | std::free(s);
|
254 | 261 | }
|
255 | 262 | char *operator()(const char *s) {
|
256 |
| - auto t = strdup(s); |
| 263 | + auto t = PYBIND11_COMPAT_STRDUP(s); |
257 | 264 | strings.push_back(t);
|
258 | 265 | return t;
|
259 | 266 | }
|
@@ -497,7 +504,8 @@ class cpp_function : public function {
|
497 | 504 | auto *func = (PyCFunctionObject *) m_ptr;
|
498 | 505 | std::free(const_cast<char *>(func->m_ml->ml_doc));
|
499 | 506 | // Install docstring if it's non-empty (when at least one option is enabled)
|
500 |
| - func->m_ml->ml_doc = signatures.empty() ? nullptr : strdup(signatures.c_str()); |
| 507 | + func->m_ml->ml_doc |
| 508 | + = signatures.empty() ? nullptr : PYBIND11_COMPAT_STRDUP(signatures.c_str()); |
501 | 509 |
|
502 | 510 | if (rec->is_method) {
|
503 | 511 | m_ptr = PYBIND11_INSTANCE_METHOD_NEW(m_ptr, rec->scope.ptr());
|
@@ -1498,15 +1506,15 @@ class class_ : public detail::generic_type {
|
1498 | 1506 | detail::process_attributes<Extra...>::init(extra..., rec_fget);
|
1499 | 1507 | if (rec_fget->doc && rec_fget->doc != doc_prev) {
|
1500 | 1508 | free(doc_prev);
|
1501 |
| - rec_fget->doc = strdup(rec_fget->doc); |
| 1509 | + rec_fget->doc = PYBIND11_COMPAT_STRDUP(rec_fget->doc); |
1502 | 1510 | }
|
1503 | 1511 | }
|
1504 | 1512 | if (rec_fset) {
|
1505 | 1513 | char *doc_prev = rec_fset->doc;
|
1506 | 1514 | detail::process_attributes<Extra...>::init(extra..., rec_fset);
|
1507 | 1515 | if (rec_fset->doc && rec_fset->doc != doc_prev) {
|
1508 | 1516 | free(doc_prev);
|
1509 |
| - rec_fset->doc = strdup(rec_fset->doc); |
| 1517 | + rec_fset->doc = PYBIND11_COMPAT_STRDUP(rec_fset->doc); |
1510 | 1518 | }
|
1511 | 1519 | if (! rec_active) rec_active = rec_fset;
|
1512 | 1520 | }
|
|
0 commit comments