|
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
|
@@ -76,8 +77,18 @@ inline bool apply_exception_translators(std::forward_list<ExceptionTranslator>&
|
76 | 77 | return false;
|
77 | 78 | }
|
78 | 79 |
|
79 |
| -PYBIND11_NAMESPACE_END(detail) |
| 80 | +#if defined(_MSC_VER) |
| 81 | +# pragma warning(push) |
| 82 | +# pragma warning(disable : 4996) // warning C4996: The POSIX name for this item is deprecated. |
| 83 | +#endif |
| 84 | + |
| 85 | +inline char *strdup_helper(const char *s) { return strdup(s); } |
80 | 86 |
|
| 87 | +#if defined(_MSC_VER) |
| 88 | +# pragma warning(pop) |
| 89 | +#endif |
| 90 | + |
| 91 | +PYBIND11_NAMESPACE_END(detail) |
81 | 92 |
|
82 | 93 | /// Wraps an arbitrary C++ function/method/lambda function/.. into a callable Python object
|
83 | 94 | class cpp_function : public function {
|
@@ -276,7 +287,7 @@ class cpp_function : public function {
|
276 | 287 | std::free(s);
|
277 | 288 | }
|
278 | 289 | char *operator()(const char *s) {
|
279 |
| - auto t = strdup(s); |
| 290 | + auto t = detail::strdup_helper(s); |
280 | 291 | strings.push_back(t);
|
281 | 292 | return t;
|
282 | 293 | }
|
@@ -520,7 +531,8 @@ class cpp_function : public function {
|
520 | 531 | auto *func = (PyCFunctionObject *) m_ptr;
|
521 | 532 | std::free(const_cast<char *>(func->m_ml->ml_doc));
|
522 | 533 | // Install docstring if it's non-empty (when at least one option is enabled)
|
523 |
| - func->m_ml->ml_doc = signatures.empty() ? nullptr : strdup(signatures.c_str()); |
| 534 | + func->m_ml->ml_doc |
| 535 | + = signatures.empty() ? nullptr : detail::strdup_helper(signatures.c_str()); |
524 | 536 |
|
525 | 537 | if (rec->is_method) {
|
526 | 538 | m_ptr = PYBIND11_INSTANCE_METHOD_NEW(m_ptr, rec->scope.ptr());
|
@@ -1525,15 +1537,15 @@ class class_ : public detail::generic_type {
|
1525 | 1537 | detail::process_attributes<Extra...>::init(extra..., rec_fget);
|
1526 | 1538 | if (rec_fget->doc && rec_fget->doc != doc_prev) {
|
1527 | 1539 | free(doc_prev);
|
1528 |
| - rec_fget->doc = strdup(rec_fget->doc); |
| 1540 | + rec_fget->doc = detail::strdup_helper(rec_fget->doc); |
1529 | 1541 | }
|
1530 | 1542 | }
|
1531 | 1543 | if (rec_fset) {
|
1532 | 1544 | char *doc_prev = rec_fset->doc;
|
1533 | 1545 | detail::process_attributes<Extra...>::init(extra..., rec_fset);
|
1534 | 1546 | if (rec_fset->doc && rec_fset->doc != doc_prev) {
|
1535 | 1547 | free(doc_prev);
|
1536 |
| - rec_fset->doc = strdup(rec_fset->doc); |
| 1548 | + rec_fset->doc = detail::strdup_helper(rec_fset->doc); |
1537 | 1549 | }
|
1538 | 1550 | if (! rec_active) rec_active = rec_fset;
|
1539 | 1551 | }
|
|
0 commit comments