remover = (DictRemoverObject *)obj;
assert(remover->key == NULL);
assert(remover->dict == NULL);
- Py_INCREF(key);
- remover->key = key;
- Py_INCREF(dict);
- remover->dict = dict;
+ remover->key = Py_NewRef(key);
+ remover->dict = Py_NewRef(dict);
proxy = PyWeakref_NewProxy(item, obj);
Py_DECREF(obj);
struct_param->ptr = ptr;
} else {
ptr = self->b_ptr;
- obj = (PyObject *)self;
- Py_INCREF(obj);
+ obj = Py_NewRef(self);
}
parg = PyCArgObject_new();
if (res == -1)
return NULL;
if (res) {
- Py_INCREF(value);
- return value;
+ return Py_NewRef(value);
}
if (PyCArg_CheckExact(value)) {
PyCArgObject *p = (PyCArgObject *)value;
if (res == -1)
return NULL;
if (res) {
- Py_INCREF(value);
- return value;
+ return Py_NewRef(value);
}
}
ob_name = (ob) ? Py_TYPE(ob)->tp_name : "???";
parg->tag = 'P';
parg->pffi_type = &ffi_type_pointer;
- Py_INCREF(self);
- parg->obj = (PyObject *)self;
+ parg->obj = Py_NewRef(self);
parg->value.p = *(void **)self->b_ptr;
return parg;
}
if (value == Py_None) {
/* ConvParam will convert to a NULL pointer later */
- Py_INCREF(value);
- return value;
+ return Py_NewRef(value);
}
typedict = PyType_stgdict(type);
return NULL;
}
if (ret) {
- Py_INCREF(value);
- return value;
+ return Py_NewRef(value);
}
}
return CDataType_from_param(type, value);
p->tag = 'P';
p->pffi_type = &ffi_type_pointer;
p->value.p = (char *)self->b_ptr;
- Py_INCREF(self);
- p->obj = (PyObject *)self;
+ p->obj = Py_NewRef(self);
return p;
}
if (res == -1)
return NULL;
if (res) {
- Py_INCREF(value);
- return value;
+ return Py_NewRef(value);
}
if (ArrayObject_Check(value) || PointerObject_Check(value)) {
/* c_wchar array instance or pointer(c_wchar(...)) */
assert(dt); /* Cannot be NULL for pointer or array objects */
dict = dt && dt->proto ? PyType_stgdict(dt->proto) : NULL;
if (dict && (dict->setfunc == _ctypes_get_fielddesc("u")->setfunc)) {
- Py_INCREF(value);
- return value;
+ return Py_NewRef(value);
}
}
if (PyCArg_CheckExact(value)) {
PyCArgObject *a = (PyCArgObject *)value;
StgDictObject *dict = PyObject_stgdict(a->obj);
if (dict && (dict->setfunc == _ctypes_get_fielddesc("u")->setfunc)) {
- Py_INCREF(value);
- return value;
+ return Py_NewRef(value);
}
}
if (res == -1)
return NULL;
if (res) {
- Py_INCREF(value);
- return value;
+ return Py_NewRef(value);
}
if (ArrayObject_Check(value) || PointerObject_Check(value)) {
/* c_char array instance or pointer(c_char(...)) */
assert(dt); /* Cannot be NULL for pointer or array objects */
dict = dt && dt->proto ? PyType_stgdict(dt->proto) : NULL;
if (dict && (dict->setfunc == _ctypes_get_fielddesc("c")->setfunc)) {
- Py_INCREF(value);
- return value;
+ return Py_NewRef(value);
}
}
if (PyCArg_CheckExact(value)) {
PyCArgObject *a = (PyCArgObject *)value;
StgDictObject *dict = PyObject_stgdict(a->obj);
if (dict && (dict->setfunc == _ctypes_get_fielddesc("c")->setfunc)) {
- Py_INCREF(value);
- return value;
+ return Py_NewRef(value);
}
}
return NULL;
if (res) {
/* c_void_p instances */
- Py_INCREF(value);
- return value;
+ return Py_NewRef(value);
}
/* ctypes array or pointer instance */
if (ArrayObject_Check(value) || PointerObject_Check(value)) {
/* Any array or pointer is accepted */
- Py_INCREF(value);
- return value;
+ return Py_NewRef(value);
}
/* byref(...) */
if (PyCArg_CheckExact(value)) {
/* byref(c_xxx()) */
PyCArgObject *a = (PyCArgObject *)value;
if (a->tag == 'P') {
- Py_INCREF(value);
- return value;
+ return Py_NewRef(value);
}
}
/* function pointer */
return NULL;
parg->pffi_type = &ffi_type_pointer;
parg->tag = 'Z';
- Py_INCREF(value);
- parg->obj = value;
+ parg->obj = Py_NewRef(value);
/* Remember: b_ptr points to where the pointer is stored! */
parg->value.p = *(void **)(((CDataObject *)value)->b_ptr);
return (PyObject *)parg;
stgdict->setfunc = fmt->setfunc_swapped;
stgdict->getfunc = fmt->getfunc_swapped;
- Py_INCREF(proto);
- stgdict->proto = proto;
+ stgdict->proto = Py_NewRef(proto);
/* replace the class dict by our updated spam dict */
if (-1 == PyDict_Update((PyObject *)stgdict, result->tp_dict)) {
parg->tag = fmt[0];
parg->pffi_type = fd->pffi_type;
- Py_INCREF(self);
- parg->obj = (PyObject *)self;
+ parg->obj = Py_NewRef(self);
memcpy(&parg->value, self->b_ptr, self->b_size);
return parg;
}
if (res == -1)
return NULL;
if (res) {
- Py_INCREF(value);
- return value;
+ return Py_NewRef(value);
}
dict = PyType_stgdict(type);
converters = converters_from_argtypes(ob);
if (!converters)
return -1;
- Py_INCREF(ob);
- stgdict->argtypes = ob;
+ stgdict->argtypes = Py_NewRef(ob);
stgdict->converters = converters;
}
else if (PyErr_Occurred()) {
"_restype_ must be a type, a callable, or None");
return -1;
}
- Py_INCREF(ob);
- stgdict->restype = ob;
+ stgdict->restype = Py_NewRef(ob);
if (_PyObject_LookupAttr(ob, &_Py_ID(_check_retval_),
&stgdict->checker) < 0)
{
"_errcheck_ must be callable");
return -1;
}
- Py_INCREF(ob);
- stgdict->errcheck = ob;
+ stgdict->errcheck = Py_NewRef(ob);
}
else if (PyErr_Occurred()) {
return -1;
parg->tag = 'P';
parg->pffi_type = &ffi_type_pointer;
- Py_INCREF(self);
- parg->obj = (PyObject *)self;
+ parg->obj = Py_NewRef(self);
parg->value.p = *(void **)self->b_ptr;
return parg;
}
if (self->b_objects == NULL)
return NULL;
} else {
- Py_INCREF(Py_None);
- self->b_objects = Py_None;
+ self->b_objects = Py_NewRef(Py_None);
}
}
return self;
if (view == NULL) return 0;
view->buf = self->b_ptr;
- view->obj = myself;
- Py_INCREF(myself);
+ view->obj = Py_NewRef(myself);
view->len = self->b_size;
view->readonly = 0;
/* use default format character if not set */
static PyObject *
PyCData_from_outparam(PyObject *self, PyObject *args)
{
- Py_INCREF(self);
- return self;
+ return Py_NewRef(self);
}
static PyMethodDef PyCData_methods[] = {
if (value == NULL)
return NULL;
- Py_INCREF(value);
- return value;
+ return Py_NewRef(value);
}
if (PyCPointerTypeObject_Check(type)
PyCFuncPtr_get_errcheck(PyCFuncPtrObject *self, void *Py_UNUSED(ignored))
{
if (self->errcheck) {
- Py_INCREF(self->errcheck);
- return self->errcheck;
+ return Py_NewRef(self->errcheck);
}
Py_RETURN_NONE;
}
{
StgDictObject *dict;
if (self->restype) {
- Py_INCREF(self->restype);
- return self->restype;
+ return Py_NewRef(self->restype);
}
dict = PyObject_stgdict((PyObject *)self);
assert(dict); /* Cannot be NULL for PyCFuncPtrObject instances */
if (dict->restype) {
- Py_INCREF(dict->restype);
- return dict->restype;
+ return Py_NewRef(dict->restype);
} else {
Py_RETURN_NONE;
}
{
StgDictObject *dict;
if (self->argtypes) {
- Py_INCREF(self->argtypes);
- return self->argtypes;
+ return Py_NewRef(self->argtypes);
}
dict = PyObject_stgdict((PyObject *)self);
assert(dict); /* Cannot be NULL for PyCFuncPtrObject instances */
if (dict->argtypes) {
- Py_INCREF(dict->argtypes);
- return dict->argtypes;
+ return Py_NewRef(dict->argtypes);
} else {
Py_RETURN_NONE;
}
return NULL;
}
- Py_XINCREF(paramflags);
- self->paramflags = paramflags;
+ self->paramflags = Py_XNewRef(paramflags);
*(void **)self->b_ptr = address;
Py_INCREF(dll);
return NULL;
}
- Py_INCREF(self);
- self->callable = (PyObject *)self;
+ self->callable = Py_NewRef(self);
return (PyObject *)self;
}
self = (PyCFuncPtrObject *)GenericPyCData_new(type, args, kwds);
self->index = index + 0x1000;
- Py_XINCREF(paramflags);
- self->paramflags = paramflags;
+ self->paramflags = Py_XNewRef(paramflags);
if (iid_len == sizeof(GUID))
self->iid = iid;
return (PyObject *)self;
return NULL;
}
- Py_INCREF(callable);
- self->callable = callable;
+ self->callable = Py_NewRef(callable);
self->thunk = thunk;
*(void **)self->b_ptr = (void *)thunk->pcl_exec;
if (*pindex < PyTuple_GET_SIZE(inargs)) {
v = PyTuple_GET_ITEM(inargs, *pindex);
++*pindex;
- Py_INCREF(v);
- return v;
+ return Py_NewRef(v);
}
if (kwds && name) {
v = PyDict_GetItemWithError(kwds, name);
if (v) {
++*pindex;
- Py_INCREF(v);
- return v;
+ return Py_NewRef(v);
}
else if (PyErr_Occurred()) {
return NULL;
}
}
if (defval) {
- Py_INCREF(defval);
- return defval;
+ return Py_NewRef(defval);
}
/* we can't currently emit a better error message */
if (name)
if (self->index)
return PyTuple_GetSlice(inargs, 1, PyTuple_GET_SIZE(inargs));
#endif
- Py_INCREF(inargs);
- return inargs;
+ return Py_NewRef(inargs);
}
len = PyTuple_GET_SIZE(argtypes);
Simple_from_outparm(PyObject *self, PyObject *args)
{
if (_ctypes_simple_instance((PyObject *)Py_TYPE(self))) {
- Py_INCREF(self);
- return self;
+ return Py_NewRef(self);
}
/* call stgdict->getfunc */
return Simple_get_value((CDataObject *)self, NULL);
if (obj->b_objects == NULL)
goto failed;
}
- Py_XINCREF(obj->b_objects);
- result->b_objects = obj->b_objects;
+ result->b_objects = Py_XNewRef(obj->b_objects);
if (result->b_objects && PyDict_CheckExact(result->b_objects)) {
PyObject *index;
int rc;