Remove some usage of strdup

To fix visual c++ warning:
  warning C4996: 'strdup': The POSIX name for this item is deprecated.
This commit is contained in:
William S Fulton 2022-05-07 07:09:44 +01:00
commit fd846be18b
3 changed files with 20 additions and 10 deletions

View file

@ -512,7 +512,7 @@ like this:
<pre>
%typemap(in) (...)(char *vargs[10]) {
int i;
int argc;
Py_ssize_t argc;
for (i = 0; i &lt; 10; i++) vargs[i] = 0;
argc = PyTuple_Size(varargs);
if (argc &gt; 10) {
@ -523,6 +523,7 @@ like this:
PyObject *pyobj = PyTuple_GetItem(varargs, i);
char *str = 0;
%#if PY_VERSION_HEX&gt;=0x03000000
const char *strtmp = 0;
PyObject *pystr;
if (!PyUnicode_Check(pyobj)) {
PyErr_SetString(PyExc_ValueError, "Expected a string");
@ -532,7 +533,10 @@ like this:
if (!pystr) {
SWIG_fail;
}
str = strdup(PyBytes_AsString(pystr));
strtmp = PyBytes_AsString(pystr);
str = (char *)malloc(strlen(strtmp) + 1);
if (str)
strcpy(str, strtmp);
Py_DECREF(pystr);
%#else
if (!PyString_Check(pyobj)) {