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:
parent
72bb68d556
commit
fd846be18b
3 changed files with 20 additions and 10 deletions
|
|
@ -512,7 +512,7 @@ like this:
|
||||||
<pre>
|
<pre>
|
||||||
%typemap(in) (...)(char *vargs[10]) {
|
%typemap(in) (...)(char *vargs[10]) {
|
||||||
int i;
|
int i;
|
||||||
int argc;
|
Py_ssize_t argc;
|
||||||
for (i = 0; i < 10; i++) vargs[i] = 0;
|
for (i = 0; i < 10; i++) vargs[i] = 0;
|
||||||
argc = PyTuple_Size(varargs);
|
argc = PyTuple_Size(varargs);
|
||||||
if (argc > 10) {
|
if (argc > 10) {
|
||||||
|
|
@ -523,6 +523,7 @@ like this:
|
||||||
PyObject *pyobj = PyTuple_GetItem(varargs, i);
|
PyObject *pyobj = PyTuple_GetItem(varargs, i);
|
||||||
char *str = 0;
|
char *str = 0;
|
||||||
%#if PY_VERSION_HEX>=0x03000000
|
%#if PY_VERSION_HEX>=0x03000000
|
||||||
|
const char *strtmp = 0;
|
||||||
PyObject *pystr;
|
PyObject *pystr;
|
||||||
if (!PyUnicode_Check(pyobj)) {
|
if (!PyUnicode_Check(pyobj)) {
|
||||||
PyErr_SetString(PyExc_ValueError, "Expected a string");
|
PyErr_SetString(PyExc_ValueError, "Expected a string");
|
||||||
|
|
@ -532,7 +533,10 @@ like this:
|
||||||
if (!pystr) {
|
if (!pystr) {
|
||||||
SWIG_fail;
|
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);
|
Py_DECREF(pystr);
|
||||||
%#else
|
%#else
|
||||||
if (!PyString_Check(pyobj)) {
|
if (!PyString_Check(pyobj)) {
|
||||||
|
|
|
||||||
|
|
@ -39,12 +39,14 @@ extern int gcd(int x, int y);
|
||||||
%#if PY_VERSION_HEX >= 0x03000000
|
%#if PY_VERSION_HEX >= 0x03000000
|
||||||
{
|
{
|
||||||
PyObject *utf8str = PyUnicode_AsUTF8String(s);
|
PyObject *utf8str = PyUnicode_AsUTF8String(s);
|
||||||
const char *cstr;
|
const char *strtmp = 0;
|
||||||
if (!utf8str) {
|
if (!utf8str) {
|
||||||
SWIG_fail;
|
SWIG_fail;
|
||||||
}
|
}
|
||||||
cstr = PyBytes_AsString(utf8str);
|
strtmp = PyBytes_AsString(utf8str);
|
||||||
$2[i] = strdup(cstr);
|
$2[i] = (char *)malloc(strlen(strtmp) + 1);
|
||||||
|
if ($2[i])
|
||||||
|
strcpy($2[i], strtmp);
|
||||||
Py_DECREF(utf8str);
|
Py_DECREF(utf8str);
|
||||||
}
|
}
|
||||||
%#else
|
%#else
|
||||||
|
|
|
||||||
|
|
@ -17,21 +17,25 @@
|
||||||
PyObject *pyobj = PyTuple_GetItem(varargs, i);
|
PyObject *pyobj = PyTuple_GetItem(varargs, i);
|
||||||
char *str = 0;
|
char *str = 0;
|
||||||
%#if PY_VERSION_HEX>=0x03000000
|
%#if PY_VERSION_HEX>=0x03000000
|
||||||
|
const char *strtmp = 0;
|
||||||
PyObject *pystr;
|
PyObject *pystr;
|
||||||
if (!PyUnicode_Check(pyobj)) {
|
if (!PyUnicode_Check(pyobj)) {
|
||||||
PyErr_SetString(PyExc_ValueError, "Expected a string");
|
PyErr_SetString(PyExc_ValueError, "Expected a string");
|
||||||
SWIG_fail;
|
SWIG_fail;
|
||||||
}
|
}
|
||||||
pystr = PyUnicode_AsUTF8String(pyobj);
|
pystr = PyUnicode_AsUTF8String(pyobj);
|
||||||
if (!pystr) {
|
if (!pystr) {
|
||||||
SWIG_fail;
|
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);
|
Py_DECREF(pystr);
|
||||||
%#else
|
%#else
|
||||||
if (!PyString_Check(pyobj)) {
|
if (!PyString_Check(pyobj)) {
|
||||||
PyErr_SetString(PyExc_ValueError, "Expected a string");
|
PyErr_SetString(PyExc_ValueError, "Expected a string");
|
||||||
SWIG_fail;
|
SWIG_fail;
|
||||||
}
|
}
|
||||||
str = PyString_AsString(pyobj);
|
str = PyString_AsString(pyobj);
|
||||||
%#endif
|
%#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue