mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-02-07 21:00:33 +03:00
Pending notice list converted into a forward list
This allows inserting the elements in order without using list.insert().
This commit is contained in:
parent
b326a27774
commit
2ad82b973b
|
@ -107,6 +107,7 @@ struct connectionObject {
|
||||||
/* notice processing */
|
/* notice processing */
|
||||||
PyObject *notice_list;
|
PyObject *notice_list;
|
||||||
struct connectionObject_notice *notice_pending;
|
struct connectionObject_notice *notice_pending;
|
||||||
|
struct connectionObject_notice *last_notice;
|
||||||
|
|
||||||
/* notifies */
|
/* notifies */
|
||||||
PyObject *notifies;
|
PyObject *notifies;
|
||||||
|
|
|
@ -87,13 +87,20 @@ conn_notice_callback(void *args, const char *message)
|
||||||
/* Discard the notice in case of failed allocation. */
|
/* Discard the notice in case of failed allocation. */
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
notice->next = NULL;
|
||||||
notice->message = strdup(message);
|
notice->message = strdup(message);
|
||||||
if (NULL == notice->message) {
|
if (NULL == notice->message) {
|
||||||
free(notice);
|
free(notice);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
notice->next = self->notice_pending;
|
|
||||||
self->notice_pending = notice;
|
if (NULL == self->last_notice) {
|
||||||
|
self->notice_pending = self->last_notice = notice;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
self->last_notice->next = notice;
|
||||||
|
self->last_notice = notice;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Expose the notices received as Python objects.
|
/* Expose the notices received as Python objects.
|
||||||
|
@ -111,17 +118,14 @@ conn_notice_process(connectionObject *self)
|
||||||
}
|
}
|
||||||
|
|
||||||
notice = self->notice_pending;
|
notice = self->notice_pending;
|
||||||
nnotices = PyList_GET_SIZE(self->notice_list);
|
|
||||||
|
|
||||||
while (notice != NULL) {
|
while (notice != NULL) {
|
||||||
PyObject *msg;
|
PyObject *msg;
|
||||||
msg = conn_text_from_chars(self, notice->message);
|
msg = conn_text_from_chars(self, notice->message);
|
||||||
Dprintf("conn_notice_process: %s", notice->message);
|
Dprintf("conn_notice_process: %s", notice->message);
|
||||||
|
|
||||||
/* Respect the order in which notices were produced,
|
|
||||||
because in notice_list they are reversed (see ticket #9) */
|
|
||||||
if (msg) {
|
if (msg) {
|
||||||
PyList_Insert(self->notice_list, nnotices, msg);
|
PyList_Append(self->notice_list, msg);
|
||||||
Py_DECREF(msg);
|
Py_DECREF(msg);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -158,7 +162,7 @@ conn_notice_clean(connectionObject *self)
|
||||||
free(tmp);
|
free(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
self->notice_pending = NULL;
|
self->last_notice = self->notice_pending = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user