From 277f57ffb030b89544e878778dc385e3d0c59292 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Fri, 9 Nov 2007 02:28:47 +0000 Subject: [PATCH] - Hard limit on the connection.notices list to avoid them growing indefinitely. Notices are treated as a queue: when the queue is full drop the oldest notice. --- psycopg/connection.h | 3 +++ psycopg/connection_int.c | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/psycopg/connection.h b/psycopg/connection.h index baed6a2b..90dc1291 100644 --- a/psycopg/connection.h +++ b/psycopg/connection.h @@ -36,6 +36,9 @@ extern "C" { #define CONN_STATUS_SYNC 3 #define CONN_STATUS_ASYNC 4 +/* Hard limit on the notices stored by the Python connection */ +#define CONN_NOTICES_LIMIT 50 + extern PyTypeObject connectionType; typedef struct { diff --git a/psycopg/connection_int.c b/psycopg/connection_int.c index 6995451f..fb4018c3 100644 --- a/psycopg/connection_int.c +++ b/psycopg/connection_int.c @@ -45,8 +45,13 @@ conn_notice_callback(void *args, const char *message) if (self->protocol < 3 && strncmp(message, "ERROR", 5) == 0) pq_set_critical(self, message); - else + else { PyList_Append(self->notice_list, PyString_FromString(message)); + + /* Remove the oldest item if the queue is getting too long. */ + if (PyList_GET_SIZE(self->notice_list) > CONN_NOTICES_LIMIT) + PySequence_DelItem(self->notice_list, 0); + } } /* conn_connect - execute a connection to the dataabase */