cvs: pecl /dbdo dbdo.c php_dbdo.h /dbdo/examples schema.php

From: Date: Sat, 13 Nov 2004 15:07:46 +0000
Subject: cvs: pecl /dbdo dbdo.c php_dbdo.h /dbdo/examples schema.php
Groups: php.pecl.cvs 
Request: Send a blank email to pecl-cvs+get-2027@lists.php.net to get a copy of this message
alan_k Sat Nov 13 10:07:46 2004 EDT Modified files: /pecl/dbdo dbdo.c php_dbdo.h /pecl/dbdo/examples schema.php Log: partial resturcture of struct storage, a few more memory leaks squashed

http://cvs.php.net/diff.php/pecl/dbdo/dbdo.c?r1=1.23&r2=1.24&ty=u Index: pecl/dbdo/dbdo.c diff -u pecl/dbdo/dbdo.c:1.23 pecl/dbdo/dbdo.c:1.24 --- pecl/dbdo/dbdo.c:1.23 Thu Oct 21 10:42:46 2004 +++ pecl/dbdo/dbdo.c Sat Nov 13 10:07:41 2004 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: dbdo.c,v 1.23 2004/10/21 14:42:46 alan_k Exp $ */ +/* $Id: dbdo.c,v 1.24 2004/11/13 15:07:41 alan_k Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -126,8 +126,7 @@ /* we cant free intern, cause it contains pointers to values */ - intern->table = NULL; - + intern->table = NULL; efree(intern); @@ -344,7 +343,10 @@ /* QUESTION? need a good example of a destructor callback.. */ dbdo_globals->signals = NULL; dbdo_globals->config = NULL; + dbdo_globals->config_len = 0; + dbdo_globals->tables = NULL; + dbdo_globals->tables_len = 0; } /* }}} */ @@ -446,46 +448,55 @@ */ PHP_RSHUTDOWN_FUNCTION(dbdo) {/* TODO: free sequences, tables .. */ - + int i; /* free client */ if (DBDO_G(client)) { gda_client_close_all_connections ( DBDO_G(client)); g_object_unref(G_OBJECT( DBDO_G(client))); DBDO_G(client) = NULL; } + /* free config */ - if (DBDO_G(config) && DBDO_G(config)->next) { - dbdo_config *con,*con_next; - con = DBDO_G(config)->next; - while(con) { + if (DBDO_G(config_len)) { + for (i=0;i<DBDO_G(config_len);i++) { + + dbdo_config *con = DBDO_G(config)[i]; + if (!con) { + continue; + } if (con->require_path) { efree(con->require_path); + con->require_path = NULL; } if (con->class_name) { efree(con->class_name); + con->class_name = NULL; } if (con->links) { efree(con->links); + con->links = NULL; } - con_next = (dbdo_config *) con->next; - con->prev = NULL; - con->next = NULL; efree(con); - con = con_next; + DBDO_G(config)[i] = NULL; + + /*DBDO_G(config) = NULL; */ } - DBDO_G(config)->next = NULL; - /*DBDO_G(config) = NULL; */ + efree(DBDO_G(config)); + } - //efree(DBDO_G(tables)); - + DBDO_G(config) = NULL; + DBDO_G(config_len) = 0; /* lets clear up the tables.. */ DBDO_DEBUG(("CLEARING TABLES\n")); if (DBDO_G(tables)) { - dbdo_table *table, *tablen; - table = DBDO_G(tables); - while (table) { + + for (i=0;i<DBDO_G(tables_len);i++) { + dbdo_table *table = DBDO_G(tables)[i]; + if (!table) { + continue; + } DBDO_DEBUG(("FREEING %s,%s\n",table->dsn,table->name)); if (table->dsn) { efree(table->dsn); @@ -507,16 +518,13 @@ table->schema = NULL; table->sequenceColumn = NULL; table->sequenceName = NULL; - tablen = table; - table = (dbdo_table*) table->next; - efree(tablen); - - + efree(table); + DBDO_G(tables)[i] = NULL; } - + efree(DBDO_G(tables)); } DBDO_G(tables) = NULL; - + DBDO_G(tables_len) = 0; return SUCCESS; } @@ -591,29 +599,23 @@ dbdo_table_new(char *dsn, char *name TSRMLS_DC) { dbdo_table *tbls; - - tbls = DBDO_G(tables); /* start at the beginning */ - if (tbls) { - while (tbls) { - if ((0 == strcmp(tbls->dsn, dsn)) && (0 == strcmp(tbls->name, name))) { - /* got match */ - DBDO_DEBUG( ("RETURNING EXISTING TABLE OBJECT: %s , %s : %x\n",dsn, name, tbls)); - return tbls; - } - if (tbls->next) { - tbls = (dbdo_table *)tbls->next; - continue; - } - - /* no next, and it's not found yet.. */ - tbls->next = emalloc(sizeof(dbdo_table)); - tbls = (dbdo_table *) tbls->next; + int i; + for (i=0;i<DBDO_G(tables_len);i++) { + tbls = DBDO_G(tables)[i]; + if (!tbls) { /* shouldnt really happen! */ + continue; } - } else { - DBDO_G(tables) = emalloc(sizeof(dbdo_table)); - tbls = DBDO_G(tables); + + if ((0 == strcmp(tbls->dsn, dsn)) && (0 == strcmp(tbls->name, name))) { + /* got match */ + DBDO_DEBUG( ("RETURNING EXISTING TABLE OBJECT: %s , %s : %x\n",dsn, name, tbls)); + return tbls; + } + } + DBDO_DEBUG( ("CREATING NEW TABLE OBJECT: %s , %s\n",dsn, name)); + tbls = emalloc(sizeof(dbdo_table)); tbls->dsn = estrdup(dsn); tbls->name = estrdup(name); tbls->schema = NULL; @@ -622,8 +624,14 @@ tbls->sequenceName = NULL; tbls->sequenceIsNative = FALSE; tbls->sequenceAssigned = FALSE; - tbls->next = NULL; - DBDO_DEBUG( ("RETURNING NEW TABLE OBJECT: %s , %s : %x\n",dsn, name, tbls)); + DBDO_G(tables_len)++; + if (DBDO_G(tables)) { + DBDO_G(tables) = (dbdo_table **) erealloc(DBDO_G(tables),DBDO_G(tables_len) * sizeof (dbdo_table *)); + } else { + DBDO_G(tables) = (dbdo_table **) emalloc(sizeof(dbdo_table *)); + } + DBDO_G(tables)[DBDO_G(tables_len)-1] = tbls; + DBDO_DEBUG( ("RETURNING NEW TABLE OBJECT: %s , %s : %x\n",tbls->dsn, tbls->name, tbls)); return tbls; } @@ -653,9 +661,11 @@ DBDO_DEBUG(("NO OBJECT!\n")); RETURN_FALSE; } + obj->table = dbdo_table_new(database_name, table_name); if (!dbdo_connect(obj TSRMLS_CC)) { + DBDO_DEBUG(("CONNECT FAILED!\n")); RETURN_FALSE; } @@ -668,7 +678,7 @@ RETURN_FALSE; } */ - + DBDO_DEBUG(("CONSTUCTOR DONE!!\n")); } @@ -719,6 +729,7 @@ eretval = emalloc(sizeof(zval)); compiled_string_description = zend_make_compiled_string_description("DBDO::factory()" TSRMLS_CC); zend_eval_string(cmd, eretval, compiled_string_description TSRMLS_DC); + FREE_ZVAL(eretval); } /* create the instance */ @@ -744,7 +755,7 @@ efree(classname); return; } - + efree(lc_name); /* now instantate it!! */ object_init_ex(return_value, *ce); @@ -754,7 +765,8 @@ { zval *params; zval ***signal_args; - MAKE_STD_ZVAL(c_ret); + /* MAKE_STD_ZVAL(c_ret); */ + c_ret = NULL; /*ALLOC_ZVAL(constructor); */ table_cp = estrdup(table); dsn_cp = estrdup(dsn); @@ -762,7 +774,7 @@ params = dbdo_build_value("(ss)", dsn_cp, table_cp); signal_args = dbdo_hash_as_array(params); - ZVAL_STRING(&constructor, ZEND_CONSTRUCTOR_FUNC_NAME, 1); + ZVAL_STRING(&constructor, ZEND_CONSTRUCTOR_FUNC_NAME, 0); if (call_user_function_ex(EG(function_table), &return_value, &constructor, &c_ret, 2, signal_args, 0, NULL TSRMLS_CC) @@ -770,10 +782,12 @@ php_error_docref(NULL TSRMLS_CC, E_ERROR, "Error calling constructor"); } - /* FREE_ZVAL(&constructor); */ + /* FREE_ZVAL(&constructor); */ if (c_ret) { FREE_ZVAL(c_ret); } + efree(table_cp); + efree(dsn_cp); } @@ -1990,7 +2004,7 @@ value = (GdaValue *) gda_row_get_value (row, column_id); string = gda_value_stringify (value); MAKE_STD_ZVAL(ztitle); - ZVAL_STRING(ztitle, title, 1); + ZVAL_STRING(ztitle, title, 0); if (std_object_handlers.has_property(object, ztitle, 0 TSRMLS_CC)) { std_object_handlers.unset_property(object, ztitle TSRMLS_CC); @@ -2221,7 +2235,7 @@ char *name; /* BOTH THESE APPEAR TO LEAK */ ALLOC_HASHTABLE(rv); - zend_hash_init(rv, 0, NULL, ZVAL_PTR_DTOR, 0); + zend_hash_init(rv, 0, NULL, ZVAL_PTR_DTOR, 0); if (obj->result == NULL) { /* throw errror!! - what about user set values...???? */ @@ -3540,12 +3554,13 @@ if (**format == '#') { ++*format; len = va_arg(*va, int); - } else + } else { len = strlen(str); + } ZVAL_STRINGL(result, str, len, 1); - } else + } else { ZVAL_NULL(result); - + } return result; } @@ -3790,18 +3805,20 @@ dbdo_config * dbdo_config_get(char *name TSRMLS_DC) { dbdo_config *con,*cons; - + int i; /* look for it on the stack.. */ - - cons = DBDO_G(config); /* start at the beginning */ - while (cons != NULL) { + for (i=0;i<DBDO_G(config_len);i++) { + cons = DBDO_G(config)[i]; /* start at the beginning */ + if (strcmp(cons->dsn,name)==0) { return cons; } - if (cons->next == NULL) { - break; - } - cons = cons->next; + } + DBDO_G(config_len)++; + if (DBDO_G(config) != NULL) { + DBDO_G(config) = (dbdo_config **) erealloc(DBDO_G(config),DBDO_G(config_len) * sizeof(dbdo_config *)); + } else { + DBDO_G(config) = (dbdo_config **) emalloc(sizeof(dbdo_config *)); } con = emalloc(sizeof(dbdo_config)); con->require_path = NULL; @@ -3809,14 +3826,8 @@ con->links = NULL; con->lowercase_columns = FALSE; con->quote_identifiers = FALSE; - con->next = NULL; - con->prev = (void *)cons; - if (cons) { - cons->next = (void *)con; - } else { - DBDO_G(config) = con; - } con->dsn = estrdup( name); + DBDO_G(config)[DBDO_G(config_len)-1] = con; return con; } http://cvs.php.net/diff.php/pecl/dbdo/php_dbdo.h?r1=1.8&r2=1.9&ty=u Index: pecl/dbdo/php_dbdo.h diff -u pecl/dbdo/php_dbdo.h:1.8 pecl/dbdo/php_dbdo.h:1.9 --- pecl/dbdo/php_dbdo.h:1.8 Wed Oct 20 05:48:42 2004 +++ pecl/dbdo/php_dbdo.h Sat Nov 13 10:07:41 2004 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_dbdo.h,v 1.8 2004/10/20 09:48:42 alan_k Exp $ */ +/* $Id: php_dbdo.h,v 1.9 2004/11/13 15:07:41 alan_k Exp $ */ #ifndef PHP_DBDO_H #define PHP_DBDO_H @@ -46,7 +46,7 @@ zend_class_entry *dbdo_class_entry_ce, *dbdo_class_entry_exception_ce; -typedef struct _dbdo_table { +typedef struct { gchar *dsn; /* dsn to use. */ gchar *name; /* name of table -- still need free policy*/ GdaDataModel *schema; /* datamodel schema for this table */ @@ -54,7 +54,6 @@ gboolean sequenceIsNative; /* is it native or emulated sequences */ gboolean sequenceAssigned; /* has a guess or assignment been made? */ gchar *sequenceName; /* the name of the sequence (eg. for nextval lookup) */ - struct _dbdo_table *next; /* link list pointer to next record */ } dbdo_table; typedef struct { @@ -64,8 +63,6 @@ gboolean lowercase_columns; char *links; gboolean quote_identifiers; - void *next; - void *prev; } dbdo_config; typedef struct { @@ -146,8 +143,10 @@ ZEND_BEGIN_MODULE_GLOBALS(dbdo) GdaClient *client; dbdo_signal *signals; /* link list of dbdo_signals */ - dbdo_config *config; /* the configuration ? dbdo_config */ - dbdo_table *tables; /* link list of dbdo_table's */ + dbdo_config **config; /* the configuration ? dbdo_config */ + int config_len; + dbdo_table **tables; /* link list of dbdo_table's */ + int tables_len; ZEND_END_MODULE_GLOBALS(dbdo) http://cvs.php.net/diff.php/pecl/dbdo/examples/schema.php?r1=1.2&r2=1.3&ty=u Index: pecl/dbdo/examples/schema.php diff -u pecl/dbdo/examples/schema.php:1.2 pecl/dbdo/examples/schema.php:1.3 --- pecl/dbdo/examples/schema.php:1.2 Fri Oct 22 09:59:49 2004 +++ pecl/dbdo/examples/schema.php Sat Nov 13 10:07:45 2004 @@ -2,6 +2,7 @@ $x = new DBDO('test','typetest'); $s = $x->schema(); +echo "START"; print_r($s); foreach ($s as $col) { print_r($x->schema($col)); @@ -88,4 +89,5 @@ [References] => [Default value] => ) -*/ \ No newline at end of file +*/ +exit; \ No newline at end of file
« previous php.pecl.cvs (#2027) next »