summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDiego 'Flameeyes' Pettenò <flameeyes@gmail.com>2006-09-09 19:35:40 +0000
committerDiego 'Flameeyes' Pettenò <flameeyes@gmail.com>2006-09-09 19:35:40 +0000
commit1c7be91287cdc473e8eaf593c2c5e23a92368a19 (patch)
treee816e96a538df9b2086e6ae9b37dad6df0039592 /src
parentab481384d1d547c4f8794489f95b3ddf28c8e17a (diff)
downloadxine-lib-1c7be91287cdc473e8eaf593c2c5e23a92368a19.tar.gz
xine-lib-1c7be91287cdc473e8eaf593c2c5e23a92368a19.tar.bz2
Dynamically create the log_buffers entries and the lines buffers for the logs, so that it does not waste 450KiB immediately at startup.
CVS patchset: 8212 CVS date: 2006/09/09 19:35:40
Diffstat (limited to 'src')
-rw-r--r--src/xine-engine/scratch.c14
-rw-r--r--src/xine-engine/xine.c20
2 files changed, 22 insertions, 12 deletions
diff --git a/src/xine-engine/scratch.c b/src/xine-engine/scratch.c
index 2dfd80b54..b8f72ee93 100644
--- a/src/xine-engine/scratch.c
+++ b/src/xine-engine/scratch.c
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*
- * $Id: scratch.c,v 1.18 2006/07/17 17:59:56 dsalt Exp $
+ * $Id: scratch.c,v 1.19 2006/09/09 19:35:40 dgp85 Exp $
*
* top-level xine functions
*
@@ -50,6 +50,9 @@ static void __attribute__((__format__(__printf__, 2, 0)))
time (&t);
localtime_r (&t, &tm);
+ if ( ! this->lines[this->cur] )
+ this->lines[this->cur] = xine_xmalloc(SCRATCH_LINE_LEN_MAX+1);
+
strftime (this->lines[this->cur], SCRATCH_LINE_LEN_MAX, "%X: ", &tm);
l = strlen (this->lines[this->cur]);
vsnprintf (this->lines[this->cur] + l, SCRATCH_LINE_LEN_MAX - l, format, argp);
@@ -79,10 +82,11 @@ static void scratch_dispose (scratch_buffer_t *this) {
int i;
mem = (char *) this->lines[0];
- free(mem);
- for(i = 0; i < this->num_lines; i++ )
+ for(i = 0; i < this->num_lines; i++ ) {
+ free(this->lines[i]);
this->lines[i] = NULL;
+ }
free (this->lines);
free (this->ordered);
@@ -99,10 +103,8 @@ scratch_buffer_t *_x_new_scratch_buffer (int num_lines) {
this->lines = xine_xmalloc (sizeof (char *) * (num_lines + 1));
this->ordered = xine_xmalloc (sizeof (char *) * (num_lines + 1));
- mem = (char *) xine_xmalloc((sizeof(char) * SCRATCH_LINE_LEN_MAX) * num_lines);
-
for (i = 0; i < num_lines; i++)
- this->lines[i] = (char *) (mem + (i * SCRATCH_LINE_LEN_MAX));
+ this->lines[i] = NULL;
this->ordered[i] = NULL;
this->lines[i] = NULL;
diff --git a/src/xine-engine/xine.c b/src/xine-engine/xine.c
index 432fca579..d8ca81d4a 100644
--- a/src/xine-engine/xine.c
+++ b/src/xine-engine/xine.c
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*
- * $Id: xine.c,v 1.328 2006/09/09 17:41:45 dgp85 Exp $
+ * $Id: xine.c,v 1.329 2006/09/09 19:35:40 dgp85 Exp $
*/
/*
@@ -1360,7 +1360,8 @@ void xine_exit (xine_t *this) {
xprintf (this, XINE_VERBOSITY_DEBUG, "xine_exit: bye!\n");
for (i = 0; i < XINE_LOG_NUM; i++)
- this->log_buffers[i]->dispose (this->log_buffers[i]);
+ if ( this->log_buffers[i] )
+ this->log_buffers[i]->dispose (this->log_buffers[i]);
_x_dispose_plugins (this);
@@ -1421,9 +1422,7 @@ xine_t *xine_new (void) {
/*
* log buffers
*/
-
- for (i = 0; i < XINE_LOG_NUM; i++)
- this->log_buffers[i] = _x_new_scratch_buffer (150);
+ memset(this->log_buffers, 0, sizeof(this->log_buffers));
#ifdef WIN32
@@ -1945,6 +1944,9 @@ void xine_log (xine_t *this, int buf, const char *format, ...) {
va_list argp;
char buffer[SCRATCH_LINE_LEN_MAX];
+ if ( ! this->log_buffers[buf] )
+ this->log_buffers[buf] = _x_new_scratch_buffer(150);
+
va_start (argp, format);
this->log_buffers[buf]->scratch_printf (this->log_buffers[buf], format, argp);
va_end(argp);
@@ -1960,6 +1962,9 @@ void xine_log (xine_t *this, int buf, const char *format, ...) {
void xine_vlog(xine_t *this, int buf, const char *format,
va_list args)
{
+ if ( ! this->log_buffers[buf] )
+ this->log_buffers[buf] = _x_new_scratch_buffer(150);
+
this->log_buffers[buf]->scratch_printf(this->log_buffers[buf], format, args);
}
@@ -1968,7 +1973,10 @@ const char *const *xine_get_log (xine_t *this, int buf) {
if(buf >= XINE_LOG_NUM)
return NULL;
- return this->log_buffers[buf]->get_content (this->log_buffers[buf]);
+ if ( this->log_buffers[buf] )
+ return this->log_buffers[buf]->get_content (this->log_buffers[buf]);
+ else
+ return NULL;
}
void xine_register_log_cb (xine_t *this, xine_log_cb_t cb, void *user_data) {