diff options
author | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2015-06-02 14:25:46 +0100 |
---|---|---|
committer | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2015-06-02 14:25:46 +0100 |
commit | 2ad82b973b86fa71126657aacee89a30d2211894 (patch) | |
tree | 5c3db9a107a287bcec508b6316a34eabd3b64552 /psycopg/connection_int.c | |
parent | b326a277743b80dde7e5263a232db8df99149164 (diff) | |
download | psycopg2-2ad82b973b86fa71126657aacee89a30d2211894.tar.gz |
Pending notice list converted into a forward list
This allows inserting the elements in order without using list.insert().
Diffstat (limited to 'psycopg/connection_int.c')
-rw-r--r-- | psycopg/connection_int.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/psycopg/connection_int.c b/psycopg/connection_int.c index 8fce908..40f7e6c 100644 --- a/psycopg/connection_int.c +++ b/psycopg/connection_int.c @@ -87,13 +87,20 @@ conn_notice_callback(void *args, const char *message) /* Discard the notice in case of failed allocation. */ return; } + notice->next = NULL; notice->message = strdup(message); if (NULL == notice->message) { free(notice); 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. @@ -111,17 +118,14 @@ conn_notice_process(connectionObject *self) } notice = self->notice_pending; - nnotices = PyList_GET_SIZE(self->notice_list); while (notice != NULL) { PyObject *msg; msg = conn_text_from_chars(self, 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) { - PyList_Insert(self->notice_list, nnotices, msg); + PyList_Append(self->notice_list, msg); Py_DECREF(msg); } else { @@ -158,7 +162,7 @@ conn_notice_clean(connectionObject *self) free(tmp); } - self->notice_pending = NULL; + self->last_notice = self->notice_pending = NULL; } |