Skip to content

Commit e7459ff

Browse files
authoredSep 6, 2016
Merge pull request #46 from saghul/none-refcount
Fix refcount handling for None object
2 parents 4c0c59b + fe64f78 commit e7459ff

File tree

3 files changed

+32
-9
lines changed

3 files changed

+32
-9
lines changed
 

‎context_util.c

+7-2
Original file line numberDiff line numberDiff line change
@@ -87,23 +87,28 @@ callback_shim(struct getdns_context *context,
8787
}
8888
if (type == GETDNS_CALLBACK_CANCEL) {
8989
py_result = Py_None;
90+
Py_INCREF(Py_None);
9091
py_tid = Py_None;
92+
Py_INCREF(Py_None);
9193
py_userarg = Py_None;
94+
Py_INCREF(Py_None);
9295
} else {
9396
py_result = result_create(response);
9497
#if PY_MAJOR_VERSION >= 3
9598
py_tid = PyLong_FromLong((long)tid);
9699
#else
97100
py_tid = PyInt_FromLong((long)tid);
98101
#endif
99-
if (u->userarg)
102+
if (u->userarg) {
100103
#if PY_MAJOR_VERSION >= 3
101104
py_userarg = PyUnicode_FromString(u->userarg);
102105
#else
103106
py_userarg = PyString_FromString(u->userarg);
104107
#endif
105-
else
108+
} else {
106109
py_userarg = Py_None;
110+
Py_INCREF(Py_None);
111+
}
107112
}
108113
PyObject_CallFunctionObjArgs(u->callback_func, py_callback_type, py_result, py_userarg, py_tid, NULL);
109114
}

‎getdns.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,8 @@ get_errorstr_by_id(PyObject *self, PyObject *args, PyObject *keywds)
370370
PyErr_SetString(getdns_error, GETDNS_RETURN_INVALID_PARAMETER_TEXT);
371371
return NULL;
372372
}
373-
if ((errstr = (char *)getdns_get_errorstr_by_id((uint16_t)id)) == 0)
374-
return Py_None;
373+
if ((errstr = (char *)getdns_get_errorstr_by_id((uint16_t)id)) == 0)
374+
Py_RETURN_NONE;
375375
else
376376
#if PY_MAJOR_VERSION >= 3
377377
return PyUnicode_FromString(errstr);

‎result.c

+23-5
Original file line numberDiff line numberDiff line change
@@ -73,25 +73,34 @@ result_init(getdns_ResultObject *self, getdns_dict *result_dict)
7373
#else
7474
self->answer_type = PyInt_FromLong((long)answer_type);
7575
#endif
76-
if ((canonical_name = get_canonical_name(result_dict)) == 0)
76+
if ((canonical_name = get_canonical_name(result_dict)) == 0) {
7777
self->canonical_name = Py_None;
78-
else
78+
Py_INCREF(Py_None);
79+
} else {
7980
#if PY_MAJOR_VERSION >= 3
8081
self->canonical_name = PyUnicode_FromString(canonical_name);
8182
#else
8283
self->canonical_name = PyString_FromString(canonical_name);
8384
#endif
85+
}
8486
if ((self->just_address_answers = get_just_address_answers(result_dict)) == NULL) {
8587
self->just_address_answers = Py_None;
88+
Py_INCREF(Py_None);
8689
}
87-
if ((self->validation_chain = get_validation_chain(result_dict)) == NULL)
90+
if ((self->validation_chain = get_validation_chain(result_dict)) == NULL) {
8891
self->validation_chain = Py_None;
92+
Py_INCREF(Py_None);
93+
}
8994
#if GETDNS_NUMERIC_VERSION < 0x00090000
90-
if ((self->call_debugging = get_call_debugging(result_dict)) == NULL)
95+
if ((self->call_debugging = get_call_debugging(result_dict)) == NULL) {
9196
self->call_debugging = Py_None;
97+
Py_INCREF(Py_None);
98+
}
9299
#else
93-
if ((self->call_reporting = get_call_reporting(result_dict)) == NULL)
100+
if ((self->call_reporting = get_call_reporting(result_dict)) == NULL) {
94101
self->call_reporting = Py_None;
102+
Py_INCREF(Py_None);
103+
}
95104
#endif
96105
return 0;
97106
}
@@ -105,16 +114,25 @@ result_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
105114
self = (getdns_ResultObject *)type->tp_alloc(type, 0);
106115
if (self != NULL) {
107116
self->just_address_answers = Py_None;
117+
Py_INCREF(Py_None);
108118
self->answer_type = Py_None;
119+
Py_INCREF(Py_None);
109120
self->status = Py_None;
121+
Py_INCREF(Py_None);
110122
self->replies_tree = Py_None;
123+
Py_INCREF(Py_None);
111124
self->canonical_name = Py_None;
125+
Py_INCREF(Py_None);
112126
self->replies_full = Py_None;
127+
Py_INCREF(Py_None);
113128
self->validation_chain = Py_None;
129+
Py_INCREF(Py_None);
114130
#if GETDNS_NUMERIC_VERSION < 0x00090000
115131
self->call_debugging = Py_None;
132+
Py_INCREF(Py_None);
116133
#else
117134
self->call_reporting = Py_None;
135+
Py_INCREF(Py_None);
118136
#endif
119137
}
120138
return (PyObject *)self;

0 commit comments

Comments
 (0)
Please sign in to comment.