|
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 | +PYBIND11_NAMESPACE_BEGIN(detail) |
| 61 | + |
| 62 | +#if defined(_MSC_VER) |
| 63 | +# pragma warning(push) |
| 64 | +# pragma warning(disable : 4996) // warning C4996: The POSIX name for this item is deprecated. |
| 65 | +#endif |
| 66 | + |
| 67 | +inline char *strdup_helper(const char *s) { return strdup(s); } |
| 68 | + |
| 69 | +#if defined(_MSC_VER) |
| 70 | +# pragma warning(pop) |
| 71 | +#endif |
| 72 | + |
| 73 | +PYBIND11_NAMESPACE_END(detail) |
| 74 | + |
59 | 75 | /// Wraps an arbitrary C++ function/method/lambda function/.. into a callable Python object
|
60 | 76 | class cpp_function : public function {
|
61 | 77 | public:
|
@@ -253,7 +269,7 @@ class cpp_function : public function {
|
253 | 269 | std::free(s);
|
254 | 270 | }
|
255 | 271 | char *operator()(const char *s) {
|
256 |
| - auto t = strdup(s); |
| 272 | + auto t = detail::strdup_helper(s); |
257 | 273 | strings.push_back(t);
|
258 | 274 | return t;
|
259 | 275 | }
|
@@ -497,7 +513,8 @@ class cpp_function : public function {
|
497 | 513 | auto *func = (PyCFunctionObject *) m_ptr;
|
498 | 514 | std::free(const_cast<char *>(func->m_ml->ml_doc));
|
499 | 515 | // 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()); |
| 516 | + func->m_ml->ml_doc |
| 517 | + = signatures.empty() ? nullptr : detail::strdup_helper(signatures.c_str()); |
501 | 518 |
|
502 | 519 | if (rec->is_method) {
|
503 | 520 | m_ptr = PYBIND11_INSTANCE_METHOD_NEW(m_ptr, rec->scope.ptr());
|
@@ -1498,15 +1515,15 @@ class class_ : public detail::generic_type {
|
1498 | 1515 | detail::process_attributes<Extra...>::init(extra..., rec_fget);
|
1499 | 1516 | if (rec_fget->doc && rec_fget->doc != doc_prev) {
|
1500 | 1517 | free(doc_prev);
|
1501 |
| - rec_fget->doc = strdup(rec_fget->doc); |
| 1518 | + rec_fget->doc = detail::strdup_helper(rec_fget->doc); |
1502 | 1519 | }
|
1503 | 1520 | }
|
1504 | 1521 | if (rec_fset) {
|
1505 | 1522 | char *doc_prev = rec_fset->doc;
|
1506 | 1523 | detail::process_attributes<Extra...>::init(extra..., rec_fset);
|
1507 | 1524 | if (rec_fset->doc && rec_fset->doc != doc_prev) {
|
1508 | 1525 | free(doc_prev);
|
1509 |
| - rec_fset->doc = strdup(rec_fset->doc); |
| 1526 | + rec_fset->doc = detail::strdup_helper(rec_fset->doc); |
1510 | 1527 | }
|
1511 | 1528 | if (! rec_active) rec_active = rec_fset;
|
1512 | 1529 | }
|
|
0 commit comments