mirror of https://github.com/swig/swig
Py_DecRef Py_IncRef for examples and html docs
This commit is contained in:
parent
d79ab5ac6b
commit
5b710e3298
|
@ -5149,8 +5149,8 @@ A typemap can be used to handle this case as follows :
|
|||
PyTuple_SetItem(o3, 0, o);
|
||||
o2 = $result;
|
||||
$result = PySequence_Concat(o2, o3);
|
||||
Py_DECREF(o2);
|
||||
Py_DECREF(o3);
|
||||
Py_DecRef(o2);
|
||||
Py_DecRef(o3);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5265,12 +5265,12 @@ arrays of different sizes. To do this, you might write a typemap as follows:
|
|||
for (i =0; i < $1_dim0; i++) {
|
||||
PyObject *o = PySequence_GetItem($input, i);
|
||||
if (!PyFloat_Check(o)) {
|
||||
Py_XDECREF(o);
|
||||
Py_DecRef(o);
|
||||
PyErr_SetString(PyExc_ValueError, "Expecting a sequence of floats");
|
||||
SWIG_fail;
|
||||
}
|
||||
temp[i] = PyFloat_AsDouble(o);
|
||||
Py_DECREF(o);
|
||||
Py_DecRef(o);
|
||||
}
|
||||
$1 = &temp[0];
|
||||
}
|
||||
|
@ -5311,12 +5311,12 @@ static int convert_darray(PyObject *input, double *ptr, int size) {
|
|||
for (i =0; i < size; i++) {
|
||||
PyObject *o = PySequence_GetItem(input, i);
|
||||
if (!PyFloat_Check(o)) {
|
||||
Py_XDECREF(o);
|
||||
Py_DecRef(o);
|
||||
PyErr_SetString(PyExc_ValueError, "Expecting a sequence of floats");
|
||||
return 0;
|
||||
}
|
||||
ptr[i] = PyFloat_AsDouble(o);
|
||||
Py_DECREF(o);
|
||||
Py_DecRef(o);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -3719,7 +3719,7 @@ might write typemaps like this:
|
|||
|
||||
// Return the buffer. Discarding any previous return result
|
||||
%typemap(argout) (void *rbuffer, size_t len) {
|
||||
Py_XDECREF($result); /* Blow away any previous result */
|
||||
Py_DecRef($result); /* Blow away any previous result */
|
||||
if (result < 0) { /* Check for I/O error */
|
||||
free($1);
|
||||
PyErr_SetFromErrno(PyExc_IOError);
|
||||
|
|
|
@ -537,7 +537,7 @@ like this:
|
|||
str = (char *)malloc(strlen(strtmp) + 1);
|
||||
if (str)
|
||||
strcpy(str, strtmp);
|
||||
Py_DECREF(pystr);
|
||||
Py_DecRef(pystr);
|
||||
%#else
|
||||
if (!PyString_Check(pyobj)) {
|
||||
PyErr_SetString(PyExc_ValueError, "Expected a string");
|
||||
|
|
|
@ -47,7 +47,7 @@ extern int gcd(int x, int y);
|
|||
$2[i] = (char *)malloc(strlen(strtmp) + 1);
|
||||
if ($2[i])
|
||||
strcpy($2[i], strtmp);
|
||||
Py_DECREF(utf8str);
|
||||
Py_DecRef(utf8str);
|
||||
}
|
||||
%#else
|
||||
$2[i] = PyString_AsString(s);
|
||||
|
@ -84,7 +84,7 @@ extern int gcdmain(int argc, char *argv[]);
|
|||
PyBytes_AsStringAndSize(utf8str, &cstr, &len);
|
||||
$1 = strncpy((char *)malloc(len+1), cstr, (size_t)len);
|
||||
$2 = (int)len;
|
||||
Py_DECREF(utf8str);
|
||||
Py_DecRef(utf8str);
|
||||
%#else
|
||||
if (!PyString_Check($input)) {
|
||||
PyErr_SetString(PyExc_ValueError,"Expected a string");
|
||||
|
@ -120,7 +120,7 @@ extern int count(char *bytes, int len, char c);
|
|||
PyBytes_AsStringAndSize(utf8str, &cstr, &len);
|
||||
$1 = strncpy((char *)malloc(len+1), cstr, (size_t)len);
|
||||
$2 = (int)len;
|
||||
Py_DECREF(utf8str);
|
||||
Py_DecRef(utf8str);
|
||||
%#else
|
||||
$2 = (int)PyString_Size($input);
|
||||
$1 = (char *) malloc($2+1);
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
|
||||
SWIG_Object identity(SWIG_Object x) {
|
||||
#ifdef SWIGPYTHON
|
||||
Py_XINCREF(x);
|
||||
Py_IncRef(x);
|
||||
#endif
|
||||
return x;
|
||||
}
|
||||
|
|
|
@ -87,7 +87,7 @@ namespace test {
|
|||
%typemap(in) string_class * {
|
||||
PyObject *bytes = NULL;
|
||||
$1 = new string_class(SWIG_PyUnicode_AsUTF8AndSize($input, NULL, &bytes));
|
||||
Py_XDECREF(bytes);
|
||||
Py_DecRef(bytes);
|
||||
}
|
||||
%typemap(freearg) string_class * {
|
||||
delete $1;
|
||||
|
|
|
@ -26,7 +26,7 @@ def __reduce__(self):
|
|||
#else
|
||||
PyObject *callable = data->klass;
|
||||
#endif
|
||||
Py_INCREF(callable);
|
||||
Py_IncRef(callable);
|
||||
|
||||
PyObject *ret = PyTuple_New(2);
|
||||
PyTuple_SetItem(ret, 0, callable);
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
str = (char *)malloc(strlen(strtmp) + 1);
|
||||
if (str)
|
||||
strcpy(str, strtmp);
|
||||
Py_DECREF(pystr);
|
||||
Py_DecRef(pystr);
|
||||
%#else
|
||||
if (!PyString_Check(pyobj)) {
|
||||
PyErr_SetString(PyExc_ValueError, "Expected a string");
|
||||
|
|
Loading…
Reference in New Issue