[PHP-CVS] cvs: php4 /ext/dba dba.c
helly Sat Jun 21 14:17:20 2003 EDT Modified files: /php4/ext/dba dba.c Log: Store the absolute path of the database file and use that in the external library Index: php4/ext/dba/dba.c diff -u php4/ext/dba/dba.c:1.94 php4/ext/dba/dba.c:1.95 --- php4/ext/dba/dba.c:1.94 Mon Jun 16 05:11:31 2003 +++ php4/ext/dba/dba.c Sat Jun 21 14:17:20 2003 @@ -17,7 +17,7 @@ +--+ */ -/* $Id: dba.c,v 1.94 2003/06/16 09:11:31 edink Exp $ */ +/* $Id: dba.c,v 1.95 2003/06/21 18:17:20 helly Exp $ */ #ifdef HAVE_CONFIG_H #include config.h @@ -520,6 +520,7 @@ char *file_mode; char mode[4], *pmode, *lock_file_mode = NULL; int persistent_flag = persistent ? STREAM_OPEN_PERSISTENT : 0; + char *opened_path, *lock_name; if(ac 2) { WRONG_PARAM_COUNT; @@ -640,13 +641,16 @@ case 'c': modenr = DBA_CREAT; lock_mode = (lock_flag DBA_LOCK_CREAT) ? LOCK_EX : 0; - file_mode = a+b; if (!lock_mode || !lock_dbf) { - break; + file_mode = a+b; + } else { + /* the create/append check will be done on the lock +* when the lib opens the file it is already created +*/ + file_mode = w+b; + lock_file_mode = a+b; } - /* When we lock the db file it will be created before the handler -* even tries to open it, hence we must change to truncate mode. -*/ + break; case 'n': modenr = DBA_TRUNC; lock_mode = (lock_flag DBA_LOCK_TRUNC) ? LOCK_EX : 0; @@ -657,6 +661,9 @@ lock_mode = 0; file_mode = ; } + if (!lock_file_mode) { + lock_file_mode = file_mode; + } if (*pmode=='d' || *pmode=='l' || *pmode=='-') { pmode++; /* done already - skip here */ } @@ -712,24 +719,45 @@ if (!error lock_mode) { if (lock_dbf) { - info-lock.name = pestrdup(info-path, persistent); - lock_file_mode = file_mode; + lock_name = estrdup(info-path); } else { - spprintf(info-lock.name, 0, %s.lck, info-path); + spprintf(lock_name, 0, %s.lck, info-path); if (!strcmp(file_mode, r)) { /* when in read only mode try to use existing .lck file first */ /* do not log errors for .lck file while in read ony mode on .lck file */ lock_file_mode = rb; - info-lock.fp = php_stream_open_wrapper(info-lock.name, lock_file_mode, STREAM_MUST_SEEK|IGNORE_PATH|ENFORCE_SAFE_MODE|persistent_flag, NULL); + info-lock.fp = php_stream_open_wrapper(lock_name, lock_file_mode, STREAM_MUST_SEEK|IGNORE_PATH|ENFORCE_SAFE_MODE|persistent_flag, opened_path); } if (!info-lock.fp) { /* when not in read mode or failed to open .lck file read only. now try again in create(write) mode and log errors */ lock_file_mode = a+b; + } else { + if (!persistent) { + info-lock.name = opened_path; + } else { + info-lock.name = pestrdup(opened_path, persistent); + efree(opened_path); + } } } if (!info-lock.fp) { - info-lock.fp = php_stream_open_wrapper(info-lock.name, lock_file_mode, STREAM_MUST_SEEK|REPORT_ERRORS|IGNORE_PATH|ENFORCE_SAFE_MODE|persistent_flag, NULL); + info-lock.fp = php_stream_open_wrapper(lock_name, lock_file_mode, STREAM_MUST_SEEK|REPORT_ERRORS|IGNORE_PATH|ENFORCE_SAFE_MODE|persistent_flag, opened_path); + if (info-lock.fp) { + if (lock_dbf) { + /* replace the path info with the real path of the opened file */ + pefree(info-path, persistent); + info-path = pestrdup(opened_path, persistent); + } + /* now store the
[PHP-CVS] cvs: php4 /ext/dba dba.c
helly Sat Jun 21 14:43:25 2003 EDT Modified files: /php4/ext/dba dba.c Log: Don't copy the filename when it is not needed Index: php4/ext/dba/dba.c diff -u php4/ext/dba/dba.c:1.95 php4/ext/dba/dba.c:1.96 --- php4/ext/dba/dba.c:1.95 Sat Jun 21 14:17:20 2003 +++ php4/ext/dba/dba.c Sat Jun 21 14:43:25 2003 @@ -17,7 +17,7 @@ +--+ */ -/* $Id: dba.c,v 1.95 2003/06/21 18:17:20 helly Exp $ */ +/* $Id: dba.c,v 1.96 2003/06/21 18:43:25 helly Exp $ */ #ifdef HAVE_CONFIG_H #include config.h @@ -719,7 +719,7 @@ if (!error lock_mode) { if (lock_dbf) { - lock_name = estrdup(info-path); + lock_name = Z_STRVAL_PP(args[0]); } else { spprintf(lock_name, 0, %s.lck, info-path); if (!strcmp(file_mode, r)) { @@ -757,7 +757,9 @@ } } } - efree(lock_name); + if (!lock_dbf) { + efree(lock_name); + } if (!info-lock.fp) { dba_close(info TSRMLS_CC); /* stream operation already wrote an error message */ -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/dba dba.c
edink Mon Jun 16 05:11:31 2003 EDT Modified files: /php4/ext/dba dba.c Log: Fixed win32 build Index: php4/ext/dba/dba.c diff -u php4/ext/dba/dba.c:1.93 php4/ext/dba/dba.c:1.94 --- php4/ext/dba/dba.c:1.93 Fri Jun 13 10:59:01 2003 +++ php4/ext/dba/dba.c Mon Jun 16 05:11:31 2003 @@ -17,7 +17,7 @@ +--+ */ -/* $Id: dba.c,v 1.93 2003/06/13 14:59:01 andrey Exp $ */ +/* $Id: dba.c,v 1.94 2003/06/16 09:11:31 edink Exp $ */ #ifdef HAVE_CONFIG_H #include config.h @@ -37,6 +37,7 @@ #include php_dba.h #include ext/standard/info.h #include ext/standard/php_string.h +#include ext/standard/flock_compat.h #include php_gdbm.h #include php_ndbm.h -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/dba dba.c
andrey Fri Jun 13 10:59:01 2003 EDT Modified files: /php4/ext/dba dba.c Log: proto fixes Index: php4/ext/dba/dba.c diff -u php4/ext/dba/dba.c:1.92 php4/ext/dba/dba.c:1.93 --- php4/ext/dba/dba.c:1.92 Thu Jun 12 15:53:40 2003 +++ php4/ext/dba/dba.c Fri Jun 13 10:59:01 2003 @@ -17,7 +17,7 @@ +--+ */ -/* $Id: dba.c,v 1.92 2003/06/12 19:53:40 helly Exp $ */ +/* $Id: dba.c,v 1.93 2003/06/13 14:59:01 andrey Exp $ */ #ifdef HAVE_CONFIG_H #include config.h @@ -788,7 +788,7 @@ /* }}} */ #undef FREENOW -/* {{{ proto int dba_popen(string path, string mode [, string handlername, string ...]) +/* {{{ proto resource dba_popen(string path, string mode [, string handlername, string ...]) Opens path using the specified handler in mode persistently */ PHP_FUNCTION(dba_popen) { @@ -796,7 +796,7 @@ } /* }}} */ -/* {{{ proto int dba_open(string path, string mode [, string handlername, string ...]) +/* {{{ proto resource dba_open(string path, string mode [, string handlername, string ...]) Opens path using the specified handler in mode*/ PHP_FUNCTION(dba_open) { -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/dba dba.c
helly Thu Jun 12 15:53:40 2003 EDT Modified files: /php4/ext/dba dba.c Log: Bugfix #2397: dba_open locking error with db3 Index: php4/ext/dba/dba.c diff -u php4/ext/dba/dba.c:1.91 php4/ext/dba/dba.c:1.92 --- php4/ext/dba/dba.c:1.91 Tue Jun 10 16:03:26 2003 +++ php4/ext/dba/dba.c Thu Jun 12 15:53:40 2003 @@ -17,7 +17,7 @@ +--+ */ -/* $Id: dba.c,v 1.91 2003/06/10 20:03:26 imajes Exp $ */ +/* $Id: dba.c,v 1.92 2003/06/12 19:53:40 helly Exp $ */ #ifdef HAVE_CONFIG_H #include config.h @@ -636,15 +636,20 @@ lock_mode = (lock_flag DBA_LOCK_WRITER) ? LOCK_EX : 0; file_mode = r+b; break; - case 'n': - modenr = DBA_TRUNC; - lock_mode = (lock_flag DBA_LOCK_TRUNC) ? LOCK_EX : 0; - file_mode = w+b; - break; case 'c': modenr = DBA_CREAT; lock_mode = (lock_flag DBA_LOCK_CREAT) ? LOCK_EX : 0; file_mode = a+b; + if (!lock_mode || !lock_dbf) { + break; + } + /* When we lock the db file it will be created before the handler +* even tries to open it, hence we must change to truncate mode. +*/ + case 'n': + modenr = DBA_TRUNC; + lock_mode = (lock_flag DBA_LOCK_TRUNC) ? LOCK_EX : 0; + file_mode = w+b; break; default: modenr = 0; -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/dba dba.c
helly Tue Mar 4 14:56:35 2003 EDT Modified files: /php4/ext/dba dba.c Log: fix dba by fixing key_len retrieval Index: php4/ext/dba/dba.c diff -u php4/ext/dba/dba.c:1.84 php4/ext/dba/dba.c:1.85 --- php4/ext/dba/dba.c:1.84 Wed Feb 26 17:07:50 2003 +++ php4/ext/dba/dba.c Tue Mar 4 14:56:35 2003 @@ -17,7 +17,7 @@ +--+ */ -/* $Id: dba.c,v 1.84 2003/02/26 22:07:50 helly Exp $ */ +/* $Id: dba.c,v 1.85 2003/03/04 19:56:35 helly Exp $ */ #ifdef HAVE_CONFIG_H #include config.h @@ -149,7 +149,7 @@ if(ac != 2 || zend_get_parameters_ex(ac, key, id) != SUCCESS) { \ WRONG_PARAM_COUNT; \ } \ - if ((key_len = php_dba_make_key(key, key_str, key_free TSRMLS_CC) 0)) {\ + if ((key_len = php_dba_make_key(key, key_str, key_free TSRMLS_CC)) == 0) {\ RETURN_FALSE; \ } @@ -175,7 +175,7 @@ default: \ WRONG_PARAM_COUNT; \ } \ - if ((key_len = php_dba_make_key(key, key_str, key_free TSRMLS_CC) 0)) {\ + if ((key_len = php_dba_make_key(key, key_str, key_free TSRMLS_CC)) == 0) {\ RETURN_FALSE; \ } @@ -187,7 +187,7 @@ WRONG_PARAM_COUNT; \ } \ convert_to_string_ex(val); \ - if ((key_len = php_dba_make_key(key, key_str, key_free TSRMLS_CC) 0)) {\ + if ((key_len = php_dba_make_key(key, key_str, key_free TSRMLS_CC)) == 0) {\ RETURN_FALSE; \ } -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/dba dba.c php_dba.h
helly Tue Mar 4 18:45:48 2003 EDT Modified files: /php4/ext/dba dba.c php_dba.h Log: Use stream locking support # needs more testing Index: php4/ext/dba/dba.c diff -u php4/ext/dba/dba.c:1.85 php4/ext/dba/dba.c:1.86 --- php4/ext/dba/dba.c:1.85 Tue Mar 4 14:56:35 2003 +++ php4/ext/dba/dba.c Tue Mar 4 18:45:48 2003 @@ -17,7 +17,7 @@ +--+ */ -/* $Id: dba.c,v 1.85 2003/03/04 19:56:35 helly Exp $ */ +/* $Id: dba.c,v 1.86 2003/03/04 23:45:48 helly Exp $ */ #ifdef HAVE_CONFIG_H #include config.h @@ -28,7 +28,6 @@ #if HAVE_DBA #include php_ini.h -#include ext/standard/flock_compat.h #include stdio.h #include fcntl.h #ifdef HAVE_SYS_FILE_H @@ -319,11 +318,6 @@ if (info-hnd) info-hnd-close(info TSRMLS_CC); if (info-path) pefree(info-path, info-flagsDBA_PERSISTENT); if (info-fp info-fp!=info-lock.fp) php_stream_close(info-fp); - if (info-lock.fd) { - php_flock(info-lock.fd, LOCK_UN); - /*close(info-lock.fd);*/ - info-lock.fd = 0; - } if (info-lock.fp) php_stream_close(info-lock.fp); if (info-lock.name) pefree(info-lock.name, info-flagsDBA_PERSISTENT); pefree(info, info-flagsDBA_PERSISTENT); @@ -707,13 +701,10 @@ FREENOW; RETURN_FALSE; } - if (php_stream_cast(info-lock.fp, PHP_STREAM_AS_FD, (void*)info-lock.fd, 1) == FAILURE) { - dba_close(info TSRMLS_CC); - /* stream operation already wrote an error message */ - FREENOW; - RETURN_FALSE; + if (!php_stream_supports_lock(info-lock.fp)) { + error = Stream does not support locking; } - if (php_flock(info-lock.fd, lock_mode)) { + if (php_stream_lock(info-lock.fp, lock_mode)) { error = Unable to establish lock; /* force failure exit */ } } Index: php4/ext/dba/php_dba.h diff -u php4/ext/dba/php_dba.h:1.23 php4/ext/dba/php_dba.h:1.24 --- php4/ext/dba/php_dba.h:1.23 Tue Dec 31 11:06:25 2002 +++ php4/ext/dba/php_dba.h Tue Mar 4 18:45:48 2003 @@ -16,7 +16,7 @@ +--+ */ -/* $Id: php_dba.h,v 1.23 2002/12/31 16:06:25 sebastian Exp $ */ +/* $Id: php_dba.h,v 1.24 2003/03/04 23:45:48 helly Exp $ */ #ifndef PHP_DBA_H #define PHP_DBA_H @@ -33,7 +33,6 @@ typedef struct dba_lock { php_stream *fp; - int fd; char *name; int mode; /* LOCK_EX,LOCK_SH */ } dba_lock; -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/dba dba.c
helly Wed Feb 26 17:07:50 2003 EDT Modified files: /php4/ext/dba dba.c Log: allow keys as array(group, name) for handler inifile Index: php4/ext/dba/dba.c diff -u php4/ext/dba/dba.c:1.83 php4/ext/dba/dba.c:1.84 --- php4/ext/dba/dba.c:1.83 Sat Feb 22 12:20:05 2003 +++ php4/ext/dba/dba.c Wed Feb 26 17:07:50 2003 @@ -17,7 +17,7 @@ +--+ */ -/* $Id: dba.c,v 1.83 2003/02/22 17:20:05 helly Exp $ */ +/* $Id: dba.c,v 1.84 2003/02/26 22:07:50 helly Exp $ */ #ifdef HAVE_CONFIG_H #include config.h @@ -103,19 +103,60 @@ /* these are used to get the standard arguments */ #define DBA_GET1 \ - if(ac != 1 || zend_get_parameters_ex(ac, id) != SUCCESS) { \ + if(ac != 1 || zend_get_parameters_ex(ac, id) != SUCCESS) { \ WRONG_PARAM_COUNT; \ } +/* {{{ php_dba_myke_key */ +static size_t php_dba_make_key(zval **key, char **key_str, char **key_free TSRMLS_DC) +{ + if (Z_TYPE_PP(key) == IS_ARRAY) { + zval **group, **name; + HashPosition pos; + size_t len; + + if (zend_hash_num_elements(Z_ARRVAL_PP(key)) != 2) { + php_error_docref(NULL TSRMLS_CC, E_ERROR, Key does not have exactly two elements: (key, name)); + return -1; + } + zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(key), pos); + zend_hash_get_current_data_ex(Z_ARRVAL_PP(key), (void **) group, pos); + zend_hash_move_forward_ex(Z_ARRVAL_PP(key), pos); + zend_hash_get_current_data_ex(Z_ARRVAL_PP(key), (void **) name, pos); + convert_to_string_ex(group); + convert_to_string_ex(name); + if (Z_STRLEN_PP(group) == 0) { + *key_str = Z_STRVAL_PP(name); + *key_free = NULL; + return Z_STRLEN_PP(name); + } + len = spprintf(key_str, 0, [%s]%s, Z_STRVAL_PP(group), Z_STRVAL_PP(name)); + *key_free = *key_str; + return len; + } else { + convert_to_string_ex(key); + *key_str = Z_STRVAL_PP(key); + *key_free = NULL; + return Z_STRLEN_PP(key); + } +} +/* }}} */ + #define DBA_GET2 \ zval **key; \ + char *key_str, *key_free; \ + size_t key_len; \ if(ac != 2 || zend_get_parameters_ex(ac, key, id) != SUCCESS) { \ WRONG_PARAM_COUNT; \ } \ - convert_to_string_ex(key) + if ((key_len = php_dba_make_key(key, key_str, key_free TSRMLS_CC) 0)) {\ + RETURN_FALSE; \ + } #define DBA_GET2_3 \ zval **key; \ + char *key_str, *key_free; \ + size_t key_len; \ zval **tmp; \ int skip = 0; \ switch(ac) { \ @@ -134,7 +175,21 @@ default: \ WRONG_PARAM_COUNT; \ } \ - convert_to_string_ex(key) + if ((key_len = php_dba_make_key(key, key_str, key_free TSRMLS_CC) 0)) {\ + RETURN_FALSE;
[PHP-CVS] cvs: php4 /ext/dba dba.c
helly Fri Jan 31 14:12:24 2003 EDT Modified files: /php4/ext/dba dba.c Log: Fix proto Index: php4/ext/dba/dba.c diff -u php4/ext/dba/dba.c:1.81 php4/ext/dba/dba.c:1.82 --- php4/ext/dba/dba.c:1.81 Sat Jan 18 14:49:25 2003 +++ php4/ext/dba/dba.c Fri Jan 31 14:12:23 2003 @@ -17,7 +17,7 @@ +--+ */ -/* $Id: dba.c,v 1.81 2003/01/18 19:49:25 iliaa Exp $ */ +/* $Id: dba.c,v 1.82 2003/01/31 19:12:23 helly Exp $ */ #ifdef HAVE_CONFIG_H #include config.h @@ -682,7 +682,7 @@ /* }}} */ #undef FREENOW -/* {{{ proto int dba_popen(string path [, string mode, string handlername, string ...]) +/* {{{ proto int dba_popen(string path, string mode [, string handlername, string +...]) Opens path using the specified handler in mode persistently */ PHP_FUNCTION(dba_popen) { -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/dba dba.c
helly Mon Dec 30 06:32:37 2002 EDT Modified files: /php4/ext/dba dba.c Log: -better parameter names for DBA_HND macros -remove unnecessary notice Index: php4/ext/dba/dba.c diff -u php4/ext/dba/dba.c:1.75 php4/ext/dba/dba.c:1.76 --- php4/ext/dba/dba.c:1.75 Sun Dec 29 10:31:00 2002 +++ php4/ext/dba/dba.c Mon Dec 30 06:32:37 2002 @@ -17,7 +17,7 @@ +--+ */ -/* $Id: dba.c,v 1.75 2002/12/29 15:31:00 helly Exp $ */ +/* $Id: dba.c,v 1.76 2002/12/30 11:32:37 helly Exp $ */ #ifdef HAVE_CONFIG_H #include config.h @@ -159,14 +159,14 @@ /* a DBA handler must have specific routines */ -#define DBA_NAMED_HND(name, x, flags) \ +#define DBA_NAMED_HND(alias, name, flags) \ {\ #name, flags, dba_open_##x, dba_close_##x, dba_fetch_##x, dba_update_##x, \ dba_exists_##x, dba_delete_##x, dba_firstkey_##x, dba_nextkey_##x, \ dba_optimize_##x, dba_sync_##x \ }, -#define DBA_HND(x, flags) DBA_NAMED_HND(x, x, flags) +#define DBA_HND(name, flags) DBA_NAMED_HND(name, name, flags) /* check whether the user has write access */ #define DBA_WRITE_CHECK \ @@ -513,6 +513,10 @@ switch (pmode[1]) { case 'd': lock_dbf = 1; + if ((hptr-flags DBA_LOCK_ALL) == 0) { + lock_flag = (hptr-flags DBA_LOCK_ALL); + break; + } /* no break */ case 'l': lock_flag = DBA_LOCK_ALL; -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/dba dba.c
helly Mon Dec 30 06:43:19 2002 EDT Modified files: /php4/ext/dba dba.c Log: 2nd part of the patch Index: php4/ext/dba/dba.c diff -u php4/ext/dba/dba.c:1.76 php4/ext/dba/dba.c:1.77 --- php4/ext/dba/dba.c:1.76 Mon Dec 30 06:32:37 2002 +++ php4/ext/dba/dba.c Mon Dec 30 06:43:18 2002 @@ -17,7 +17,7 @@ +--+ */ -/* $Id: dba.c,v 1.76 2002/12/30 11:32:37 helly Exp $ */ +/* $Id: dba.c,v 1.77 2002/12/30 11:43:18 helly Exp $ */ #ifdef HAVE_CONFIG_H #include config.h @@ -161,9 +161,9 @@ #define DBA_NAMED_HND(alias, name, flags) \ {\ - #name, flags, dba_open_##x, dba_close_##x, dba_fetch_##x, dba_update_##x, \ - dba_exists_##x, dba_delete_##x, dba_firstkey_##x, dba_nextkey_##x, \ - dba_optimize_##x, dba_sync_##x \ + #alias, flags, dba_open_##name, dba_close_##name, dba_fetch_##name, +dba_update_##name, \ + dba_exists_##name, dba_delete_##name, dba_firstkey_##name, dba_nextkey_##name, +\ + dba_optimize_##name, dba_sync_##name \ }, #define DBA_HND(name, flags) DBA_NAMED_HND(name, name, flags) -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/dba dba.c
helly Sun Dec 29 10:31:00 2002 EDT Modified files: /php4/ext/dba dba.c Log: Add a default handler that makes handler parameter to open functions optional. @Improved dba extension (Marcus) @-Made handler parameter of dba_(p)open() optional. @-Added php.ini option 'dba.default_handler' to specify a default handler. Index: php4/ext/dba/dba.c diff -u php4/ext/dba/dba.c:1.74 php4/ext/dba/dba.c:1.75 --- php4/ext/dba/dba.c:1.74 Fri Dec 20 20:09:27 2002 +++ php4/ext/dba/dba.c Sun Dec 29 10:31:00 2002 @@ -17,7 +17,7 @@ +--+ */ -/* $Id: dba.c,v 1.74 2002/12/21 01:09:27 andrei Exp $ */ +/* $Id: dba.c,v 1.75 2002/12/29 15:31:00 helly Exp $ */ #ifdef HAVE_CONFIG_H #include config.h @@ -27,6 +27,7 @@ #if HAVE_DBA +#include php_ini.h #include ext/standard/flock_compat.h #include stdio.h #include fcntl.h @@ -71,6 +72,7 @@ /* }}} */ PHP_MINIT_FUNCTION(dba); +PHP_MSHUTDOWN_FUNCTION(dba); PHP_MINFO_FUNCTION(dba); zend_module_entry dba_module_entry = { @@ -78,7 +80,7 @@ dba, dba_functions, PHP_MINIT(dba), - NULL, + PHP_MSHUTDOWN(dba), NULL, NULL, PHP_MINFO(dba), @@ -208,6 +210,37 @@ { NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL } }; +#if DBA_FLATFILE +#define DBA_DEFAULT flatfile +#elif DBA_DB4 +#define DBA_DEFAULT db4 +#elif DBA_DB3 +#define DBA_DEFAULT db3 +#elif DBA_DB2 +#define DBA_DEFAULT db2 +#elif DBA_GDBM +#define DBA_DEFAULT gdbm +#elif DBA_NBBM +#define DBA_DEFAULT ndbm +#elif DBA_DBM +#define DBA_DEFAULT dbm +#else +#define DBA_DEFAULT +#endif + +ZEND_BEGIN_MODULE_GLOBALS(dba) + char *default_handler; + dba_handler *default_hptr; +ZEND_END_MODULE_GLOBALS(dba) + +ZEND_DECLARE_MODULE_GLOBALS(dba) + +#ifdef ZTS +#define DBA_G(v) TSRMG(dba_globals_id, zend_dba_globals *, v) +#else +#define DBA_G(v) (dba_globals.v) +#endif + static int le_db; static int le_pdb; /* }}} */ @@ -240,10 +273,47 @@ } /* }}} */ +/* {{{ PHP_INI + */ +ZEND_API ZEND_INI_MH(OnUpdateDefaultHandler) +{ + dba_handler *hptr; + + if (!strlen(new_value)) { + DBA_G(default_hptr) = NULL; + return OnUpdateString(entry, new_value, new_value_length, mh_arg1, +mh_arg2, mh_arg3, stage TSRMLS_CC); + } + + for (hptr = handler; hptr-name strcasecmp(hptr-name, new_value); hptr++); + + if (!hptr-name) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, No such handler: %s, +new_value); + return FAILURE; + } + DBA_G(default_hptr) = hptr; + return OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, +mh_arg3, stage TSRMLS_CC); +} + +PHP_INI_BEGIN() +STD_PHP_INI_ENTRY(dba.default_handler, DBA_DEFAULT, PHP_INI_ALL, +OnUpdateDefaultHandler, default_handler,zend_dba_globals, dba_globals) +PHP_INI_END() +/* }}} */ + +/* {{{ php_dba_init_globals + */ +static void php_dba_init_globals(zend_dba_globals *dba_globals) +{ + dba_globals-default_handler = ; + dba_globals-default_hptr= NULL; +} +/* }}} */ + /* {{{ PHP_MINIT_FUNCTION */ PHP_MINIT_FUNCTION(dba) { + ZEND_INIT_MODULE_GLOBALS(dba, php_dba_init_globals, NULL); + REGISTER_INI_ENTRIES(); le_db = zend_register_list_destructors_ex(dba_close_rsrc, NULL, dba, module_number); le_pdb = zend_register_list_destructors_ex(NULL, dba_close_rsrc, dba persistent, module_number); return SUCCESS; @@ -254,6 +324,7 @@ */ PHP_MSHUTDOWN_FUNCTION(dba) { + UNREGISTER_INI_ENTRIES(); return SUCCESS; } /* }}} */ @@ -361,9 +432,9 @@ int i; int lock_mode, lock_flag, lock_dbf = 0; char *file_mode; - char mode[4], *pmode, *lock_file_mode; + char mode[4], *pmode, *lock_file_mode = NULL; - if(ac 3) { + if(ac 2) { WRONG_PARAM_COUNT; } @@ -407,7 +478,16 @@ } } - for (hptr = handler; hptr-name strcasecmp(hptr-name, Z_STRVAL_PP(args[2])); hptr++); + if (ac==2) { + hptr = DBA_G(default_hptr); + if (!hptr) { + php_error_docref2(NULL TSRMLS_CC, Z_STRVAL_PP(args[0]), +Z_STRVAL_PP(args[1]), E_WARNING, No default handler selected); + FREENOW; + RETURN_FALSE; + } + } else { + for (hptr = handler; hptr-name strcasecmp(hptr-name, +Z_STRVAL_PP(args[2])); hptr++); + } if (!hptr-name) { php_error_docref2(NULL TSRMLS_CC, Z_STRVAL_PP(args[0]), Z_STRVAL_PP(args[1]), E_WARNING, No such handler: %s, Z_STRVAL_PP(args[2])); @@ -587,7 +667,7 @@ if (error || hptr-open(info, error TSRMLS_CC) != SUCCESS) { dba_close(info TSRMLS_CC); - php_error_docref2(NULL TSRMLS_CC,
[PHP-CVS] cvs: php4 /ext/dba dba.c
andrei Fri Dec 20 11:45:35 2002 EDT Modified files: /php4/ext/dba dba.c Log: At least this problem exposed some leaks.. Index: php4/ext/dba/dba.c diff -u php4/ext/dba/dba.c:1.71 php4/ext/dba/dba.c:1.72 --- php4/ext/dba/dba.c:1.71 Wed Dec 11 05:37:38 2002 +++ php4/ext/dba/dba.c Fri Dec 20 11:45:34 2002 @@ -17,7 +17,7 @@ +--+ */ -/* $Id: dba.c,v 1.71 2002/12/11 10:37:38 helly Exp $ */ +/* $Id: dba.c,v 1.72 2002/12/20 16:45:34 andrei Exp $ */ #ifdef HAVE_CONFIG_H #include config.h @@ -508,9 +508,9 @@ RETURN_FALSE; } - info = emalloc(sizeof(dba_info)); + info = pemalloc(sizeof(dba_info), persistent); memset(info, 0, sizeof(dba_info)); - info-path = estrdup(Z_STRVAL_PP(args[0])); + info-path = pestrdup(Z_STRVAL_PP(args[0]), persistent); info-mode = modenr; info-argc = ac - 3; info-argv = args + 3; @@ -533,7 +533,7 @@ if (!error lock_mode) { if (lock_dbf) { - info-lock.name = estrdup(info-path); + info-lock.name = pestrdup(info-path, persistent); lock_file_mode = file_mode; } else { spprintf(info-lock.name, 0, %s.lck, info-path); -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/dba dba.c
andrei Fri Dec 20 20:09:27 2002 EDT Modified files: /php4/ext/dba dba.c Log: Alias dba_popen() to dba_open() until persistent STDIO streams are implemented. Index: php4/ext/dba/dba.c diff -u php4/ext/dba/dba.c:1.73 php4/ext/dba/dba.c:1.74 --- php4/ext/dba/dba.c:1.73 Fri Dec 20 12:47:57 2002 +++ php4/ext/dba/dba.c Fri Dec 20 20:09:27 2002 @@ -17,7 +17,7 @@ +--+ */ -/* $Id: dba.c,v 1.73 2002/12/20 17:47:57 helly Exp $ */ +/* $Id: dba.c,v 1.74 2002/12/21 01:09:27 andrei Exp $ */ #ifdef HAVE_CONFIG_H #include config.h @@ -51,7 +51,9 @@ */ function_entry dba_functions[] = { PHP_FE(dba_open, NULL) - PHP_FE(dba_popen, NULL) + PHP_FALIAS(dba_popen, dba_open, NULL) + /* Disabled until 4.3.1, when persistent STDIO streams are implemented. */ + /* PHP_FE(dba_popen, NULL) */ PHP_FE(dba_close, NULL) PHP_FE(dba_delete, NULL) PHP_FE(dba_exists, NULL) -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/dba dba.c
helly Wed Dec 11 05:37:39 2002 EDT Modified files: /php4/ext/dba dba.c Log: Warnings and Notices when lock modifiers for dba_(p)open are used wrong. This finally closes bug #20828 (and i hope it must not be reopened) Index: php4/ext/dba/dba.c diff -u php4/ext/dba/dba.c:1.70 php4/ext/dba/dba.c:1.71 --- php4/ext/dba/dba.c:1.70 Tue Dec 10 17:51:09 2002 +++ php4/ext/dba/dba.c Wed Dec 11 05:37:38 2002 @@ -17,7 +17,7 @@ +--+ */ -/* $Id: dba.c,v 1.70 2002/12/10 22:51:09 helly Exp $ */ +/* $Id: dba.c,v 1.71 2002/12/11 10:37:38 helly Exp $ */ #ifdef HAVE_CONFIG_H #include config.h @@ -430,16 +430,21 @@ if (pmode[0] (pmode[1]=='d' || pmode[1]=='l' || pmode[1]=='-')) { /* force lock on db file or lck file or disable locking */ switch (pmode[1]) { case 'd': - if ((hptr-flags DBA_LOCK_ALL) == 0) { - php_error_docref2(NULL TSRMLS_CC, Z_STRVAL_PP(args[0]), Z_STRVAL_PP(args[1]), E_NOTICE, Handler %s does locking internally, hptr-name); - } lock_dbf = 1; /* no break */ case 'l': lock_flag = DBA_LOCK_ALL; + if ((hptr-flags DBA_LOCK_ALL) == 0) { + php_error_docref2(NULL TSRMLS_CC, +Z_STRVAL_PP(args[0]), Z_STRVAL_PP(args[1]), E_NOTICE, Handler %s does locking +internally, hptr-name); + } break; default: case '-': + if ((hptr-flags DBA_LOCK_ALL) == 0) { + php_error_docref2(NULL TSRMLS_CC, +Z_STRVAL_PP(args[0]), Z_STRVAL_PP(args[1]), E_WARNING, Locking cannot be disabled +for handler %s, hptr-name); + FREENOW; + RETURN_FALSE; + } lock_flag = 0; break; } -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/dba dba.c
helly Tue Dec 10 17:02:53 2002 EDT Modified files: /php4/ext/dba dba.c Log: -remove second attempt to close lock file -default to lock on db file instead on .lck file. -try to use existing .lck file and only create it on failure (allows ro access) Index: php4/ext/dba/dba.c diff -u php4/ext/dba/dba.c:1.67 php4/ext/dba/dba.c:1.68 --- php4/ext/dba/dba.c:1.67 Mon Dec 9 13:03:00 2002 +++ php4/ext/dba/dba.c Tue Dec 10 17:02:52 2002 @@ -17,7 +17,7 @@ +--+ */ -/* $Id: dba.c,v 1.67 2002/12/09 18:03:00 helly Exp $ */ +/* $Id: dba.c,v 1.68 2002/12/10 22:02:52 helly Exp $ */ #ifdef HAVE_CONFIG_H #include config.h @@ -219,7 +219,7 @@ if (info-fp info-fp!=info-lock.fp) php_stream_close(info-fp); if (info-lock.fd) { php_flock(info-lock.fd, LOCK_UN); - close(info-lock.fd); + /*close(info-lock.fd);*/ info-lock.fd = 0; } if (info-lock.fp) php_stream_close(info-lock.fp); @@ -444,6 +444,7 @@ } } else { lock_flag = (hptr-flagsDBA_LOCK_ALL); + lock_dbf = 1; } switch (*pmode++) { case 'r': @@ -530,9 +531,14 @@ lock_file_mode = file_mode; } else { spprintf(info-lock.name, 0, %s.lck, info-path); - lock_file_mode = a+b; + lock_file_mode = rb; } info-lock.fp = php_stream_open_wrapper(info-lock.name, lock_file_mode, STREAM_MUST_SEEK|REPORT_ERRORS|IGNORE_PATH|ENFORCE_SAFE_MODE, NULL); + if (!info-lock.fp !lock_dbf) { + /* when using a .lck file and that could not be opened we try +to create one */ + lock_file_mode = a+b; + info-lock.fp = php_stream_open_wrapper(info-lock.name, +lock_file_mode, STREAM_MUST_SEEK|REPORT_ERRORS|IGNORE_PATH|ENFORCE_SAFE_MODE, NULL); + } if (!info-lock.fp) { dba_close(info TSRMLS_CC); /* stream operation already wrote an error message */ @@ -801,4 +807,3 @@ * vim600: sw=4 ts=4 fdm=marker * vim600: sw=4 ts=4 */ - -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/dba dba.c
helly Tue Dec 10 17:51:09 2002 EDT Modified files: /php4/ext/dba dba.c Log: add missing comment Index: php4/ext/dba/dba.c diff -u php4/ext/dba/dba.c:1.69 php4/ext/dba/dba.c:1.70 --- php4/ext/dba/dba.c:1.69 Tue Dec 10 17:49:33 2002 +++ php4/ext/dba/dba.c Tue Dec 10 17:51:09 2002 @@ -17,7 +17,7 @@ +--+ */ -/* $Id: dba.c,v 1.69 2002/12/10 22:49:33 helly Exp $ */ +/* $Id: dba.c,v 1.70 2002/12/10 22:51:09 helly Exp $ */ #ifdef HAVE_CONFIG_H #include config.h @@ -421,6 +421,7 @@ * * d: force lock on database file * l: force lock on lck file +* -: ignore locking * * t: test open database, warning if locked */ -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/dba dba.c
helly Mon Dec 9 12:54:13 2002 EDT Modified files: /php4/ext/dba dba.c Log: Added open modifier '-' to skip/ignore locking. See bug #20828, #20858 Index: php4/ext/dba/dba.c diff -u php4/ext/dba/dba.c:1.65 php4/ext/dba/dba.c:1.66 --- php4/ext/dba/dba.c:1.65 Tue Nov 26 07:05:59 2002 +++ php4/ext/dba/dba.c Mon Dec 9 12:54:13 2002 @@ -1,790 +1,804 @@ -/* - +--+ - | PHP Version 4| - +--+ - | Copyright (c) 1997-2002 The PHP Group| - +--+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is| - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | [EMAIL PROTECTED] so we can mail you a copy immediately. | - +--+ - | Authors: Sascha Schumann [EMAIL PROTECTED]| - | Marcus Boerger [EMAIL PROTECTED] | - +--+ - */ - -/* $Id: dba.c,v 1.65 2002/11/26 12:05:59 helly Exp $ */ - -#ifdef HAVE_CONFIG_H -#include config.h -#endif - -#include php.h - -#if HAVE_DBA - -#include ext/standard/flock_compat.h -#include stdio.h -#include fcntl.h -#ifdef HAVE_SYS_FILE_H -#include sys/file.h -#endif - -#include php_dba.h -#include ext/standard/info.h -#include ext/standard/php_string.h - -#include php_gdbm.h -#include php_ndbm.h -#include php_dbm.h -#include php_cdb.h -#include php_db2.h -#include php_db3.h -#include php_db4.h -#include php_flatfile.h - -/* {{{ dba_functions[] - */ -function_entry dba_functions[] = { - PHP_FE(dba_open, NULL) - PHP_FE(dba_popen, NULL) - PHP_FE(dba_close, NULL) - PHP_FE(dba_delete, NULL) - PHP_FE(dba_exists, NULL) - PHP_FE(dba_fetch, NULL) - PHP_FE(dba_insert, NULL) - PHP_FE(dba_replace, NULL) - PHP_FE(dba_firstkey, NULL) - PHP_FE(dba_nextkey, NULL) - PHP_FE(dba_optimize, NULL) - PHP_FE(dba_sync, NULL) - PHP_FE(dba_handlers, NULL) - PHP_FE(dba_list, NULL) - {NULL, NULL, NULL} -}; -/* }}} */ - -PHP_MINIT_FUNCTION(dba); -PHP_MINFO_FUNCTION(dba); - -zend_module_entry dba_module_entry = { - STANDARD_MODULE_HEADER, - dba, - dba_functions, - PHP_MINIT(dba), - NULL, - NULL, - NULL, - PHP_MINFO(dba), - NO_VERSION_YET, - STANDARD_MODULE_PROPERTIES -}; - -#ifdef COMPILE_DL_DBA -ZEND_GET_MODULE(dba) -#endif - -typedef struct dba_handler { - char *name; /* handler name */ - int flags; /* whether and how dba does locking and other flags*/ - int (*open)(dba_info *, char **error TSRMLS_DC); - void (*close)(dba_info * TSRMLS_DC); - char* (*fetch)(dba_info *, char *, int, int, int * TSRMLS_DC); - int (*update)(dba_info *, char *, int, char *, int, int TSRMLS_DC); - int (*exists)(dba_info *, char *, int TSRMLS_DC); - int (*delete)(dba_info *, char *, int TSRMLS_DC); - char* (*firstkey)(dba_info *, int * TSRMLS_DC); - char* (*nextkey)(dba_info *, int * TSRMLS_DC); - int (*optimize)(dba_info * TSRMLS_DC); - int (*sync)(dba_info * TSRMLS_DC); -} dba_handler; - -/* {{{ macromania */ - -#define DBA_ID_PARS \ - zval **id; \ - dba_info *info = NULL; \ - int ac = ZEND_NUM_ARGS() - -/* these are used to get the standard arguments */ - -#define DBA_GET1 \ - if(ac != 1 || zend_get_parameters_ex(ac, id) != SUCCESS) { \ - WRONG_PARAM_COUNT; \ - } - -#define DBA_GET2 \ - zval **key; \ - if(ac != 2 || zend_get_parameters_ex(ac, key, id) != SUCCESS) { \ - WRONG_PARAM_COUNT;
Re: [PHP-CVS] cvs: php4 /ext/dba dba.c
On Mon, 9 Dec 2002, Marcus Boerger wrote: helly Mon Dec 9 13:03:01 2002 EDT Modified files: /php4/ext/dba dba.c Log: Recheckin as unix # *** sorry ** a new diff tool converted it to dos before last comit *** sorry *** That's why you should run a 'cvs diff' _always_ before any commit. There is no exception for that rule. - Sascha -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] cvs: php4 /ext/dba dba.c
At 19:38 09.12.2002, Sascha Schumann wrote: On Mon, 9 Dec 2002, Marcus Boerger wrote: helly Mon Dec 9 13:03:01 2002 EDT Modified files: /php4/ext/dba dba.c Log: Recheckin as unix # *** sorry ** a new diff tool converted it to dos before last comit *** sorry *** That's why you should run a 'cvs diff' _always_ before any commit. There is no exception for that rule. - Sascha In this special case that was the problem. I removed a part which i did not want to commit yet in the diff and that resulted in changing the file to dos. When you use wincvs you are alloed to do so by using an external diff tool and calling it in the commit dialog. marcus -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/dba dba.c /ext/dba/tests dba008.phpt
helly Fri Nov 22 10:47:48 2002 EDT Modified files: /php4/ext/dba dba.c /php4/ext/dba/tests dba008.phpt Log: Make magic_quotes_runtime work bidirectional for dba Index: php4/ext/dba/dba.c diff -u php4/ext/dba/dba.c:1.63 php4/ext/dba/dba.c:1.64 --- php4/ext/dba/dba.c:1.63 Thu Nov 14 16:09:40 2002 +++ php4/ext/dba/dba.c Fri Nov 22 10:47:47 2002 @@ -17,7 +17,7 @@ +--+ */ -/* $Id: dba.c,v 1.63 2002/11/14 21:09:40 helly Exp $ */ +/* $Id: dba.c,v 1.64 2002/11/22 15:47:47 helly Exp $ */ #ifdef HAVE_CONFIG_H #include config.h @@ -285,6 +285,8 @@ { DBA_ID_PARS; zval **val, **key; + char *v; + int len; if(ac != 3 || zend_get_parameters_ex(ac, key, val, id) != SUCCESS) { WRONG_PARAM_COUNT; @@ -295,8 +297,19 @@ DBA_WRITE_CHECK; - if(info-hnd-update(info, VALLEN(key), VALLEN(val), mode TSRMLS_CC) == SUCCESS) - RETURN_TRUE; + if (PG(magic_quotes_runtime)) { + len = Z_STRLEN_PP(val); + v = estrndup(Z_STRVAL_PP(val), len); + php_stripslashes(v, len TSRMLS_CC); + if(info-hnd-update(info, VALLEN(key), v, len, mode TSRMLS_CC) == +SUCCESS) { + efree(v); + RETURN_TRUE; + } + efree(v); + } else { + if(info-hnd-update(info, VALLEN(key), VALLEN(val), mode TSRMLS_CC) +== SUCCESS) + RETURN_TRUE; + } RETURN_FALSE; } /* }}} */ Index: php4/ext/dba/tests/dba008.phpt diff -u php4/ext/dba/tests/dba008.phpt:1.2 php4/ext/dba/tests/dba008.phpt:1.3 --- php4/ext/dba/tests/dba008.phpt:1.2 Fri Nov 15 10:58:09 2002 +++ php4/ext/dba/tests/dba008.phpt Fri Nov 22 10:47:48 2002 @@ -10,11 +10,15 @@ require_once('test.inc'); echo database handler: $handler\n; if (($db_file=dba_open($db_file, n, $handler))!==FALSE) { - dba_insert(key1, '', $db_file); ini_set('magic_quotes_runtime', 0); + dba_insert(key1, '', $db_file); var_dump(dba_fetch(key1, $db_file)); ini_set('magic_quotes_runtime', 1); var_dump(dba_fetch(key1, $db_file)); + dba_replace(key1, '\', $db_file); + var_dump(dba_fetch(key1, $db_file)); + ini_set('magic_quotes_runtime', 0); + var_dump(dba_fetch(key1, $db_file)); dba_close($db_file); } else { echo Error creating database\n; @@ -24,3 +28,5 @@ database handler: %s string(1) string(2) \ +string(2) \ +string(1) -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] cvs: php4 /ext/dba dba.c dba_cdb.c dba_db2.c dba_db3.c dba_dbm.c dba_flatfile.c dba_gdbm.c dba_ndbm.c
At 18:59 06.11.2002, Sascha Schumann wrote: sas Wed Nov 6 12:59:04 2002 EDT Modified files: /php4/ext/dba dba.c dba_cdb.c dba_db2.c dba_db3.c dba_dbm.c dba_flatfile.c dba_gdbm.c dba_ndbm.c Log: emalloc never returns 0, so we can simplify the code paths. also replace ecalloc with emalloc+memset, so that the latter can be inlined. Could you explain what you meant with the second part? ecmalloc is a call that uses memset. If memset can be inlined it would be inlined in ecalloc as well as in the other place. In other words i do not see the difference. -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] cvs: php4 /ext/dba dba.c dba_cdb.c dba_db2.c dba_db3.cdba_dbm.c dba_flatfile.c dba_gdbm.c dba_ndbm.c
On Wed, 13 Nov 2002, Marcus Börger wrote: At 18:59 06.11.2002, Sascha Schumann wrote: sas Wed Nov 6 12:59:04 2002 EDT Modified files: /php4/ext/dba dba.c dba_cdb.c dba_db2.c dba_db3.c dba_dbm.c dba_flatfile.c dba_gdbm.c dba_ndbm.c Log: emalloc never returns 0, so we can simplify the code paths. also replace ecalloc with emalloc+memset, so that the latter can be inlined. Could you explain what you meant with the second part? ecmalloc is a call that uses memset. If memset can be inlined it would be inlined in ecalloc as well as in the other place. In other words i do not see the difference. The difference is the placement of the memset call. After the changes, a compiler which does not optimize across function borders can inline the memset call (e.g. GCC). memset() is a lot faster, if the compiler knows the size of the data field. Have a look at the assembler code here http://www.mail-archive.com/dev;httpd.apache.org/msg02492.html - Sascha -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] cvs: php4 /ext/dba dba.c dba_cdb.c dba_db2.c dba_db3.c dba_dbm.c dba_flatfile.c dba_gdbm.c dba_ndbm.c
At 13:37 13.11.2002, Sascha Schumann wrote: On Wed, 13 Nov 2002, Marcus Börger wrote: At 18:59 06.11.2002, Sascha Schumann wrote: sas Wed Nov 6 12:59:04 2002 EDT Modified files: /php4/ext/dba dba.c dba_cdb.c dba_db2.c dba_db3.c dba_dbm.c dba_flatfile.c dba_gdbm.c dba_ndbm.c Log: emalloc never returns 0, so we can simplify the code paths. also replace ecalloc with emalloc+memset, so that the latter can be inlined. Could you explain what you meant with the second part? ecmalloc is a call that uses memset. If memset can be inlined it would be inlined in ecalloc as well as in the other place. In other words i do not see the difference. The difference is the placement of the memset call. After the changes, a compiler which does not optimize across function borders can inline the memset call (e.g. GCC). memset() is a lot faster, if the compiler knows the size of the data field. You're right the compiler knows the size in the caller function but not in ecalloc of cause. Shouldn't then ecalloc be a compiler define? #define ecalloc(num, size) \ memset( emalloc(num*size), 0, num*size) marcus Have a look at the assembler code here http://www.mail-archive.com/dev;httpd.apache.org/msg02492.html - Sascha -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] cvs: php4 /ext/dba dba.c dba_cdb.c dba_db2.c dba_db3.cdba_dbm.c dba_flatfile.c dba_gdbm.c dba_ndbm.c
You're right the compiler knows the size in the caller function but not in ecalloc of cause. Shouldn't then ecalloc be a compiler define? #define ecalloc(num, size) \ memset( emalloc(num*size), 0, num*size) It was like that until Aug 18th. A commit back then turned the fast macro back into a slow function again and added a division. With that kind of setup, the compiler has no chance to reduce and optimize the target code. By using emalloc+memset, we get compile-time reduction (no multiplication at run-time) and inlining for free. - Sascha -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] cvs: php4 /ext/dba dba.c dba_cdb.c dba_db2.c dba_db3.c dba_dbm.c dba_flatfile.c dba_gdbm.c dba_ndbm.c
At 14:14 13.11.2002, Sascha Schumann wrote: You're right the compiler knows the size in the caller function but not in ecalloc of cause. Shouldn't then ecalloc be a compiler define? #define ecalloc(num, size) \ memset( emalloc(num*size), 0, num*size) It was like that until Aug 18th. A commit back then turned the fast macro back into a slow function again and added a division. With that kind of setup, the compiler has no chance to reduce and optimize the target code. By using emalloc+memset, we get compile-time reduction (no multiplication at run-time) and inlining for free. - Sascha Agree but with one single addition if num and size are both constants then the compiler does the multiplication at compiletime. So the above define shouldn't have a run-time multiplication where not necessary. -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/dba dba.c
helly Mon Nov 11 15:53:42 2002 EDT Modified files: /php4/ext/dba dba.c Log: Use php_flock instead of flock Index: php4/ext/dba/dba.c diff -u php4/ext/dba/dba.c:1.60 php4/ext/dba/dba.c:1.61 --- php4/ext/dba/dba.c:1.60 Mon Nov 11 07:04:12 2002 +++ php4/ext/dba/dba.c Mon Nov 11 15:53:41 2002 -17,7 +17,7 +--+ */ -/* $Id: dba.c,v 1.60 2002/11/11 12:04:12 helly Exp $ */ +/* $Id: dba.c,v 1.61 2002/11/11 20:53:41 helly Exp $ */ #ifdef HAVE_CONFIG_H #include config.h -213,7 +213,7 if (info-path) efree(info-path); if (info-fp info-fp!=info-lock.fp) php_stream_close(info-fp); if (info-lock.fd) { - flock(info-lock.fd, LOCK_UN); + php_flock(info-lock.fd, LOCK_UN); close(info-lock.fd); info-lock.fd = 0; } -473,7 +473,7 FREENOW; RETURN_FALSE; } - if (flock(info-lock.fd, lock_mode)) { + if (php_flock(info-lock.fd, lock_mode)) { error = Unable to establish lock; /* force failure exit */ } } -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/dba dba.c
helly Sun Nov 10 11:03:18 2002 EDT Modified files: /php4/ext/dba dba.c Log: finish work on locking -all but gdbm do internal locking now since only gdbm has internal locking -you can force locking on database or lck file (with gdbm this makes no sense so a notice is generated) Index: php4/ext/dba/dba.c diff -u php4/ext/dba/dba.c:1.56 php4/ext/dba/dba.c:1.57 --- php4/ext/dba/dba.c:1.56 Thu Nov 7 20:03:53 2002 +++ php4/ext/dba/dba.c Sun Nov 10 11:03:17 2002 -16,7 +16,7 +--+ */ -/* $Id: dba.c,v 1.56 2002/11/08 01:03:53 helly Exp $ */ +/* $Id: dba.c,v 1.57 2002/11/10 16:03:17 helly Exp $ */ #ifdef HAVE_CONFIG_H #include config.h -174,28 +174,28 static dba_handler handler[] = { #if DBA_GDBM - DBA_HND(gdbm, DBA_LOCK_EXT) + DBA_HND(gdbm, DBA_LOCK_EXT) /* Locking done in library if set */ #endif #if DBA_DBM - DBA_HND(dbm, DBA_LOCK_EXT) + DBA_HND(dbm, DBA_LOCK_ALL) /* No lock in lib */ #endif #if DBA_NDBM - DBA_HND(ndbm, DBA_LOCK_EXT) + DBA_HND(ndbm, DBA_LOCK_ALL) /* Could be done in library: filemode = 0644 + +S_ENFMT */ #endif #if DBA_CDB - DBA_HND(cdb, DBA_LOCK_ALL) + DBA_HND(cdb, DBA_LOCK_ALL) /* No lock in lib */ #endif #if DBA_CDB_BUILTIN -DBA_NAMED_HND(cdb_make, cdb, DBA_LOCK_ALL) +DBA_NAMED_HND(cdb_make, cdb, DBA_LOCK_ALL) /* No lock in lib */ #endif #if DBA_DB2 - DBA_HND(db2, DBA_LOCK_EXT) + DBA_HND(db2, DBA_LOCK_ALL) /* No lock in lib */ #endif #if DBA_DB3 - DBA_HND(db3, DBA_LOCK_EXT) + DBA_HND(db3, DBA_LOCK_ALL) /* No lock in lib */ #endif #if DBA_FLATFILE - DBA_HND(flatfile, DBA_LOCK_ALL) + DBA_HND(flatfile, DBA_LOCK_ALL) /* No lock in lib */ #endif { NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL } }; -312,7 +312,7 char *key = NULL, *error = NULL; int keylen = 0; int i; - int lock; + int lock, lock_flag, lock_dbf = 0; char mode[4], *pmode; if(ac 3) { -367,34 +367,57 RETURN_FALSE; } + /* Check mode: [rwnc][fl]?t? +* r: Read +* w: Write +* n: Create/Truncate +* c: Create +* +* d: force lock on database file +* l: force lock on lck file +* +* t: test open database, warning if locked +*/ strlcpy(mode, Z_STRVAL_PP(args[1]), sizeof(mode)); pmode = mode[0]; + if (pmode[0] (pmode[1]=='d' || pmode[1]=='l')) { /* force lock on db file +or lck file */ + if (pmode[1]=='d') { + if ((hptr-lock DBA_LOCK_ALL) == 0) { + php_error_docref2(NULL TSRMLS_CC, +Z_STRVAL_PP(args[0]), Z_STRVAL_PP(args[1]), E_NOTICE, Handler %s does locking +internally, hptr-name); + } + lock_dbf = 1; + } + lock_flag = DBA_LOCK_ALL; + } else { + lock_flag = hptr-lock; + } switch (*pmode++) { case 'r': modenr = DBA_READER; - lock = (hptr-lock DBA_LOCK_READER) ? LOCK_SH : 0; + lock = (lock_flag DBA_LOCK_READER) ? LOCK_SH : 0; break; case 'w': modenr = DBA_WRITER; - lock = (hptr-lock DBA_LOCK_WRITER) ? LOCK_EX : 0; + lock = (lock_flag DBA_LOCK_WRITER) ? LOCK_EX : 0; break; case 'n': modenr = DBA_TRUNC; - lock = (hptr-lock DBA_LOCK_TRUNC) ? LOCK_EX : 0; + lock = (lock_flag DBA_LOCK_TRUNC) ? LOCK_EX : 0; break; case 'c': modenr = DBA_CREAT; - lock = (hptr-lock DBA_LOCK_CREAT) ? LOCK_EX : 0; + lock = (lock_flag DBA_LOCK_CREAT) ? LOCK_EX : 0; break; default: lock = 0; modenr = 0; } + if (*pmode=='d' || *pmode=='l') { + pmode++; /* done already - skip here */ + } if (*pmode=='t') { pmode++; lock |= LOCK_NB; /* test =: non blocking */ - } else if (*pmode=='b') { - pmode++; /* default is blocking */ } if (*pmode || !modenr) { php_error_docref2(NULL TSRMLS_CC, Z_STRVAL_PP(args[0]), Z_STRVAL_PP(args[1]), E_WARNING, Illegal DBA mode); -410,7 +433,10 info-argv = args + 3; if (lock) { - spprintf(info-lock.name, 0, %s.lck, info-path); + if (lock_dbf) + info-lock.name = estrdup(info-path); + else +
[PHP-CVS] cvs: php4 /ext/dba dba.c
helly Sun Nov 10 18:07:35 2002 EDT Modified files: /php4/ext/dba dba.c Log: Emit a warning when open mode modifier t is used wrong. Index: php4/ext/dba/dba.c diff -u php4/ext/dba/dba.c:1.58 php4/ext/dba/dba.c:1.59 --- php4/ext/dba/dba.c:1.58 Sun Nov 10 12:58:46 2002 +++ php4/ext/dba/dba.c Sun Nov 10 18:07:35 2002 -16,7 +16,7 +--+ */ -/* $Id: dba.c,v 1.58 2002/11/10 17:58:46 helly Exp $ */ +/* $Id: dba.c,v 1.59 2002/11/10 23:07:35 helly Exp $ */ #ifdef HAVE_CONFIG_H #include config.h -424,7 +424,19 } if (*pmode=='t') { pmode++; - lock_mode |= LOCK_NB; /* test =: non blocking */ + if (!lock_mode) { + if ((hptr-flags DBA_LOCK_ALL) == 0) { + php_error_docref2(NULL TSRMLS_CC, +Z_STRVAL_PP(args[0]), Z_STRVAL_PP(args[1]), E_WARNING, Handler %s uses its own +locking which doesn't support mode modifier t (testing), hptr-name); + FREENOW; + RETURN_FALSE; + } else { + php_error_docref2(NULL TSRMLS_CC, +Z_STRVAL_PP(args[0]), Z_STRVAL_PP(args[1]), E_WARNING, Handler %s doesn't uses +locking for this mode which makes modifier t (testing) obsolete, hptr-name); + FREENOW; + RETURN_FALSE; + } + } else { + lock_mode |= LOCK_NB; /* test =: non blocking */ + } } if (*pmode || !modenr) { php_error_docref2(NULL TSRMLS_CC, Z_STRVAL_PP(args[0]), Z_STRVAL_PP(args[1]), E_WARNING, Illegal DBA mode); -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/dba dba.c dba_flatfile.c php_dba.h
helly Thu Nov 7 20:03:54 2002 EDT Modified files: /php4/ext/dba dba.c dba_flatfile.c php_dba.h Log: -lock support moved from dba_flatfile.c to dba.c -flatfile, cdb, cdb_make use locking now #locking is blocking per default use 'rt', 'wt', ct' or 'nt' for non blocking alias #test access to a database file. #locking uses flock() which will be emulated or warned if that is not eally #possible in ext/standard/flock_compat.c Index: php4/ext/dba/dba.c diff -u php4/ext/dba/dba.c:1.55 php4/ext/dba/dba.c:1.56 --- php4/ext/dba/dba.c:1.55 Wed Nov 6 12:59:03 2002 +++ php4/ext/dba/dba.c Thu Nov 7 20:03:53 2002 -16,7 +16,7 +--+ */ -/* $Id: dba.c,v 1.55 2002/11/06 17:59:03 sas Exp $ */ +/* $Id: dba.c,v 1.56 2002/11/08 01:03:53 helly Exp $ */ #ifdef HAVE_CONFIG_H #include config.h -26,6 +26,13 #if HAVE_DBA +#include ext/standard/flock_compat.h +#include stdio.h +#include fcntl.h +#ifdef HAVE_SYS_FILE_H +#include sys/file.h +#endif + #include php_dba.h #include ext/standard/info.h -79,7 +86,8 #endif typedef struct dba_handler { - char *name; + char *name; /* handler name */ + int lock; /* whether and how dba does locking */ int (*open)(dba_info *, char **error TSRMLS_DC); void (*close)(dba_info * TSRMLS_DC); char* (*fetch)(dba_info *, char *, int, int, int * TSRMLS_DC); -144,14 +152,14 /* a DBA handler must have specific routines */ -#define DBA_NAMED_HND(name, x) \ +#define DBA_NAMED_HND(name, x, lock) \ {\ - #name, dba_open_##x, dba_close_##x, dba_fetch_##x, dba_update_##x, \ + #name, lock, dba_open_##x, dba_close_##x, dba_fetch_##x, dba_update_##x, \ dba_exists_##x, dba_delete_##x, dba_firstkey_##x, dba_nextkey_##x, \ dba_optimize_##x, dba_sync_##x \ }, -#define DBA_HND(x) DBA_NAMED_HND(x, x) +#define DBA_HND(x, lock) DBA_NAMED_HND(x, x, lock) /* check whether the user has write access */ #define DBA_WRITE_CHECK \ -166,30 +174,30 static dba_handler handler[] = { #if DBA_GDBM - DBA_HND(gdbm) + DBA_HND(gdbm, DBA_LOCK_EXT) #endif #if DBA_DBM - DBA_HND(dbm) + DBA_HND(dbm, DBA_LOCK_EXT) #endif #if DBA_NDBM - DBA_HND(ndbm) + DBA_HND(ndbm, DBA_LOCK_EXT) #endif #if DBA_CDB - DBA_HND(cdb) + DBA_HND(cdb, DBA_LOCK_ALL) #endif #if DBA_CDB_BUILTIN -DBA_NAMED_HND(cdb_make, cdb) +DBA_NAMED_HND(cdb_make, cdb, DBA_LOCK_ALL) #endif #if DBA_DB2 - DBA_HND(db2) + DBA_HND(db2, DBA_LOCK_EXT) #endif #if DBA_DB3 - DBA_HND(db3) + DBA_HND(db3, DBA_LOCK_EXT) #endif #if DBA_FLATFILE - DBA_HND(flatfile) + DBA_HND(flatfile, DBA_LOCK_ALL) #endif - { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL } + { NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL } }; static int le_db; -200,8 +208,15 */ static void dba_close(dba_info *info TSRMLS_DC) { - if(info-hnd) info-hnd-close(info TSRMLS_CC); - if(info-path) efree(info-path); + if (info-hnd) info-hnd-close(info TSRMLS_CC); + if (info-path) efree(info-path); + if (info-lock.fd) { + flock(info-lock.fd, LOCK_UN); + close(info-lock.fd); + info-lock.fd = 0; + } + if (info-lock.fp) php_stream_close(info-lock.fp); + if (info-lock.name) efree(info-lock.name); efree(info); } /* }}} */ -297,6 +312,8 char *key = NULL, *error = NULL; int keylen = 0; int i; + int lock; + char mode[4], *pmode; if(ac 3) { WRONG_PARAM_COUNT; -350,23 +367,39 RETURN_FALSE; } - switch (Z_STRVAL_PP(args[1])[0]) { - case 'c': - modenr = DBA_CREAT; + strlcpy(mode, Z_STRVAL_PP(args[1]), sizeof(mode)); + pmode = mode[0]; + switch (*pmode++) { + case 'r': + modenr = DBA_READER; + lock = (hptr-lock DBA_LOCK_READER) ? LOCK_SH : 0; break; case 'w': modenr = DBA_WRITER; - break; - case 'r': - modenr = DBA_READER; + lock = (hptr-lock DBA_LOCK_WRITER) ? LOCK_EX : 0; break; case 'n': modenr = DBA_TRUNC; + lock = (hptr-lock DBA_LOCK_TRUNC) ? LOCK_EX : 0; + break; + case 'c': + modenr = DBA_CREAT; + lock = (hptr-lock DBA_LOCK_CREAT) ? LOCK_EX : 0; break; default: - php_error_docref2(NULL TSRMLS_CC, Z_STRVAL_PP(args[0]), Z_STRVAL_PP(args[1]), E_WARNING, Illegal
[PHP-CVS] cvs: php4 /ext/dba dba.c dba_cdb.c dba_db2.c dba_db3.c dba_dbm.c dba_flatfile.c dba_gdbm.c dba_ndbm.c
sas Wed Nov 6 12:59:04 2002 EDT Modified files: /php4/ext/dba dba.c dba_cdb.c dba_db2.c dba_db3.c dba_dbm.c dba_flatfile.c dba_gdbm.c dba_ndbm.c Log: emalloc never returns 0, so we can simplify the code paths. also replace ecalloc with emalloc+memset, so that the latter can be inlined. Index: php4/ext/dba/dba.c diff -u php4/ext/dba/dba.c:1.54 php4/ext/dba/dba.c:1.55 --- php4/ext/dba/dba.c:1.54 Wed Nov 6 04:17:50 2002 +++ php4/ext/dba/dba.c Wed Nov 6 12:59:03 2002 -16,7 +16,7 +--+ */ -/* $Id: dba.c,v 1.54 2002/11/06 09:17:50 helly Exp $ */ +/* $Id: dba.c,v 1.55 2002/11/06 17:59:03 sas Exp $ */ #ifdef HAVE_CONFIG_H #include config.h -369,12 +369,12 RETURN_FALSE; } - info = ecalloc(sizeof(dba_info), 1); + info = emalloc(sizeof(dba_info)); + memset(info, 0, sizeof(dba_info)); info-path = estrdup(Z_STRVAL_PP(args[0])); info-mode = modenr; info-argc = ac - 3; info-argv = args + 3; - /* info-hnd is NULL here */ if (hptr-open(info, error TSRMLS_CC) != SUCCESS) { dba_close(info TSRMLS_CC); Index: php4/ext/dba/dba_cdb.c diff -u php4/ext/dba/dba_cdb.c:1.20 php4/ext/dba/dba_cdb.c:1.21 --- php4/ext/dba/dba_cdb.c:1.20 Tue Nov 5 09:46:35 2002 +++ php4/ext/dba/dba_cdb.c Wed Nov 6 12:59:03 2002 -17,7 +17,7 +--+ */ -/* $Id: dba_cdb.c,v 1.20 2002/11/05 14:46:35 helly Exp $ */ +/* $Id: dba_cdb.c,v 1.21 2002/11/06 17:59:03 sas Exp $ */ #ifdef HAVE_CONFIG_H #include config.h -104,17 +104,8 return FAILURE; } - cdb = ecalloc(sizeof(dba_cdb), 1); - if (!cdb) { - pinfo-dbf = cdb; -#if DBA_CDB_BUILTIN - php_stream_close(file); -#else - close(file); -#endif - *error = Out of memory; - return FAILURE; - } + cdb = emalloc(sizeof(dba_cdb)); + memset(cdb, 0, sizeof(dba_cdb)); #if DBA_CDB_BUILTIN if (make) { Index: php4/ext/dba/dba_db2.c diff -u php4/ext/dba/dba_db2.c:1.29 php4/ext/dba/dba_db2.c:1.30 --- php4/ext/dba/dba_db2.c:1.29 Tue Nov 5 09:46:35 2002 +++ php4/ext/dba/dba_db2.c Wed Nov 6 12:59:03 2002 -16,7 +16,7 +--+ */ -/* $Id: dba_db2.c,v 1.29 2002/11/05 14:46:35 helly Exp $ */ +/* $Id: dba_db2.c,v 1.30 2002/11/06 17:59:03 sas Exp $ */ #ifdef HAVE_CONFIG_H #include config.h -76,11 +76,8 return FAILURE; } - info-dbf = ecalloc(sizeof(dba_db2_data), 1); - if (!info-dbf) { - *error = Out of memory; - return FAILURE; - } + info-dbf = emalloc(sizeof(dba_db2_data)); + memset(info-dbf, 0, sizeof(dba_db2_data)); ((dba_db2_data *) info-dbf)-dbp = dbp; return SUCCESS; } Index: php4/ext/dba/dba_db3.c diff -u php4/ext/dba/dba_db3.c:1.20 php4/ext/dba/dba_db3.c:1.21 --- php4/ext/dba/dba_db3.c:1.20 Tue Nov 5 09:46:36 2002 +++ php4/ext/dba/dba_db3.c Wed Nov 6 12:59:03 2002 -16,7 +16,7 +--+ */ -/* $Id: dba_db3.c,v 1.20 2002/11/05 14:46:36 helly Exp $ */ +/* $Id: dba_db3.c,v 1.21 2002/11/06 17:59:03 sas Exp $ */ #ifdef HAVE_CONFIG_H #include config.h -78,10 +78,6 dba_db3_data *data; data = emalloc(sizeof(*data)); - if (!data) { - *error = Out of memory; - return FAILURE; - } data-dbp = dbp; data-cursor = NULL; info-dbf = data; Index: php4/ext/dba/dba_dbm.c diff -u php4/ext/dba/dba_dbm.c:1.21 php4/ext/dba/dba_dbm.c:1.22 --- php4/ext/dba/dba_dbm.c:1.21 Tue Nov 5 23:16:17 2002 +++ php4/ext/dba/dba_dbm.c Wed Nov 6 12:59:03 2002 -16,7 +16,7 +--+ */ -/* $Id: dba_dbm.c,v 1.21 2002/11/06 04:16:17 helly Exp $ */ +/* $Id: dba_dbm.c,v 1.22 2002/11/06 17:59:03 sas Exp $ */ #ifdef HAVE_CONFIG_H #include config.h -78,11 +78,8 return FAILURE; } - info-dbf = ecalloc(sizeof(dba_dbm_data), 1); - if (!info-dbf) { - *error = Out of memory; - return FAILURE; - } + info-dbf = emalloc(sizeof(dba_dbm_data)); + memset(info-dbf, 0, sizeof(dba_dbm_data)); return SUCCESS; } Index: php4/ext/dba/dba_flatfile.c diff -u php4/ext/dba/dba_flatfile.c:1.2 php4/ext/dba/dba_flatfile.c:1.3 --- php4/ext/dba/dba_flatfile.c:1.2 Wed Nov 6 05:43:41 2002 +++ php4/ext/dba/dba_flatfile.c Wed Nov 6 12:59:03 2002 -16,7 +16,7
[PHP-CVS] cvs: php4 /ext/dba dba.c dba_cdb.c dba_db2.c dba_db3.c dba_dbm.c dba_gdbm.c dba_ndbm.c php_dba.h
helly Tue Nov 5 09:46:36 2002 EDT Modified files: /php4/ext/dba dba.c dba_cdb.c dba_db2.c dba_db3.c dba_dbm.c dba_gdbm.c dba_ndbm.c php_dba.h Log: Why did open fail? Index: php4/ext/dba/dba.c diff -u php4/ext/dba/dba.c:1.50 php4/ext/dba/dba.c:1.51 --- php4/ext/dba/dba.c:1.50 Mon Nov 4 12:53:04 2002 +++ php4/ext/dba/dba.c Tue Nov 5 09:46:35 2002 -16,7 +16,7 +--+ */ -/* $Id: dba.c,v 1.50 2002/11/04 17:53:04 helly Exp $ */ +/* $Id: dba.c,v 1.51 2002/11/05 14:46:35 helly Exp $ */ #ifdef HAVE_CONFIG_H #include config.h -79,7 +79,7 typedef struct dba_handler { char *name; - int (*open)(dba_info * TSRMLS_DC); + int (*open)(dba_info *, char **error TSRMLS_DC); void (*close)(dba_info * TSRMLS_DC); char* (*fetch)(dba_info *, char *, int, int, int * TSRMLS_DC); int (*update)(dba_info *, char *, int, char *, int, int TSRMLS_DC); -290,7 +290,7 dba_mode_t modenr; dba_info *info; dba_handler *hptr; - char *key = NULL; + char *key = NULL, *error = NULL; int keylen = 0; int i; -341,7 +341,7 for (hptr = handler; hptr-name strcasecmp(hptr-name, Z_STRVAL_PP(args[2])); hptr++); if (!hptr-name) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, No such handler: %s, Z_STRVAL_PP(args[2])); + php_error_docref2(NULL TSRMLS_CC, Z_STRVAL_PP(args[0]), +Z_STRVAL_PP(args[1]), E_WARNING, No such handler: %s, Z_STRVAL_PP(args[2])); FREENOW; RETURN_FALSE; } -360,7 +360,7 modenr = DBA_TRUNC; break; default: - php_error_docref(NULL TSRMLS_CC, E_WARNING, Illegal DBA mode: %s, Z_STRVAL_PP(args[1])); + php_error_docref2(NULL TSRMLS_CC, Z_STRVAL_PP(args[0]), +Z_STRVAL_PP(args[1]), E_WARNING, Illegal DBA mode); FREENOW; RETURN_FALSE; } -373,9 +373,9 info-argv = args + 3; info-hnd = NULL; - if (hptr-open(info TSRMLS_CC) != SUCCESS) { + if (hptr-open(info, error TSRMLS_CC) != SUCCESS) { dba_close(info TSRMLS_CC); - php_error_docref(NULL TSRMLS_CC, E_WARNING, Driver initialization failed for handler: %s, Z_STRVAL_PP(args[2])); + php_error_docref2(NULL TSRMLS_CC, Z_STRVAL_PP(args[0]), +Z_STRVAL_PP(args[1]), E_WARNING, Driver initialization failed for handler: %s%s%s, +Z_STRVAL_PP(args[2]), error?: :, error?error:); FREENOW; RETURN_FALSE; } Index: php4/ext/dba/dba_cdb.c diff -u php4/ext/dba/dba_cdb.c:1.19 php4/ext/dba/dba_cdb.c:1.20 --- php4/ext/dba/dba_cdb.c:1.19 Tue Nov 5 06:22:48 2002 +++ php4/ext/dba/dba_cdb.c Tue Nov 5 09:46:35 2002 -17,7 +17,7 +--+ */ -/* $Id: dba_cdb.c,v 1.19 2002/11/05 11:22:48 helly Exp $ */ +/* $Id: dba_cdb.c,v 1.20 2002/11/05 14:46:35 helly Exp $ */ #ifdef HAVE_CONFIG_H #include config.h -74,11 +74,13 make = 0; file = php_stream_open_wrapper(info-path, rb, STREAM_MUST_SEEK|IGNORE_PATH|ENFORCE_SAFE_MODE, NULL); if (!file) { + *error = Unable to open file; return FAILURE; } #else file = VCWD_OPEN(info-path, O_RDONLY); if (file 0) { + *error = Unable to open file; return FAILURE; } #endif -89,24 +91,28 make = 1; file = php_stream_open_wrapper(info-path, wb, STREAM_MUST_SEEK|IGNORE_PATH|ENFORCE_SAFE_MODE, NULL); if (!file) { + *error = Unable to open file; return FAILURE; } break; case DBA_WRITER: + *error = Update operations are not supported; return FAILURE; /* not supported */ #endif default: - /* currently not supported: */ + *error = Currently not supported; return FAILURE; } cdb = ecalloc(sizeof(dba_cdb), 1); if (!cdb) { + pinfo-dbf = cdb; #if DBA_CDB_BUILTIN php_stream_close(file); #else close(file); #endif + *error = Out of memory; return FAILURE; } Index: php4/ext/dba/dba_db2.c diff -u php4/ext/dba/dba_db2.c:1.28 php4/ext/dba/dba_db2.c:1.29 --- php4/ext/dba/dba_db2.c:1.28 Mon
[PHP-CVS] cvs: php4 /ext/dba dba.c
helly Tue Nov 5 10:01:21 2002 EDT Modified files: /php4/ext/dba dba.c Log: -use of emalloc functions -info was not initialised fulle due to memset parameters now that the whole structure is initialised we can stop putting 0 in it. Index: php4/ext/dba/dba.c diff -u php4/ext/dba/dba.c:1.51 php4/ext/dba/dba.c:1.52 --- php4/ext/dba/dba.c:1.51 Tue Nov 5 09:46:35 2002 +++ php4/ext/dba/dba.c Tue Nov 5 10:01:20 2002 -16,7 +16,7 +--+ */ -/* $Id: dba.c,v 1.51 2002/11/05 14:46:35 helly Exp $ */ +/* $Id: dba.c,v 1.52 2002/11/05 15:01:20 helly Exp $ */ #ifdef HAVE_CONFIG_H #include config.h -197,8 +197,8 static void dba_close(dba_info *info TSRMLS_DC) { if(info-hnd) info-hnd-close(info TSRMLS_CC); - if(info-path) free(info-path); - free(info); + if(info-path) efree(info-path); + efree(info); } /* }}} */ -365,13 +365,12 RETURN_FALSE; } - info = malloc(sizeof(*info)); - memset(info, 0, sizeof(info)); - info-path = strdup(Z_STRVAL_PP(args[0])); + info = ecalloc(sizeof(dba_info), 1); + info-path = estrdup(Z_STRVAL_PP(args[0])); info-mode = modenr; info-argc = ac - 3; info-argv = args + 3; - info-hnd = NULL; + /* info-hnd is NULL here */ if (hptr-open(info, error TSRMLS_CC) != SUCCESS) { dba_close(info TSRMLS_CC); -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/dba dba.c dba_cdb.c php_dba.h /ext/dba/tests dba_cdb_read.phpt
helly Sun Nov 3 11:43:07 2002 EDT Modified files: /php4/ext/dba dba.c dba_cdb.c php_dba.h /php4/ext/dba/tests dba_cdb_read.phpt Log: cdb now allows multiple key-value pairs with same key Index: php4/ext/dba/dba.c diff -u php4/ext/dba/dba.c:1.47 php4/ext/dba/dba.c:1.48 --- php4/ext/dba/dba.c:1.47 Fri Nov 1 09:15:24 2002 +++ php4/ext/dba/dba.c Sun Nov 3 11:43:06 2002 -16,7 +16,7 +--+ */ -/* $Id: dba.c,v 1.47 2002/11/01 14:15:24 helly Exp $ */ +/* $Id: dba.c,v 1.48 2002/11/03 16:43:06 helly Exp $ */ #ifdef HAVE_CONFIG_H #include config.h -81,7 +81,7 char *name; int (*open)(dba_info * TSRMLS_DC); void (*close)(dba_info *); - char* (*fetch)(dba_info *, char *, int, int *); + char* (*fetch)(dba_info *, char *, int, int, int *); int (*update)(dba_info *, char *, int, char *, int, int); int (*exists)(dba_info *, char *, int); int (*delete)(dba_info *, char *, int); -112,11 +112,34 } \ convert_to_string_ex(key) +#define DBA_GET2_3 + \ + zval **key; + \ + zval **tmp; + \ + int skip = 0; + \ + switch(ac) { + \ + case 2: + \ + if (zend_get_parameters_ex(ac, key, id) != SUCCESS) { \ + WRONG_PARAM_COUNT; + \ + } + \ + break; + \ + case 3: + \ + if (zend_get_parameters_ex(ac, key, tmp, id) != SUCCESS) { \ + WRONG_PARAM_COUNT; + \ + } + \ + convert_to_long_ex(tmp); + \ + skip = Z_LVAL_PP(tmp); + \ + break; + \ + default: + \ + WRONG_PARAM_COUNT; + \ + } + \ + convert_to_string_ex(key) + #define DBA_ID_GET \ ZEND_FETCH_RESOURCE2(info, dba_info *, id, -1, DBA identifier, le_db, le_pdb); -#define DBA_ID_GET1 DBA_ID_PARS; DBA_GET1; DBA_ID_GET -#define DBA_ID_GET2 DBA_ID_PARS; DBA_GET2; DBA_ID_GET +#define DBA_ID_GET1 DBA_ID_PARS; DBA_GET1; DBA_ID_GET +#define DBA_ID_GET2 DBA_ID_PARS; DBA_GET2; DBA_ID_GET +#define DBA_ID_GET2_3 DBA_ID_PARS; DBA_GET2_3; DBA_ID_GET /* a DBA handler must have specific routines */ -412,15 +435,18 } /* }}} */ -/* {{{ proto string dba_fetch(string key, int handle) +/* {{{ proto string dba_fetch(string key, [int skip ,] int handle) Fetches the data associated with key */ PHP_FUNCTION(dba_fetch) { char *val; int len = 0; - DBA_ID_GET2; + DBA_ID_GET2_3; - if((val = info-hnd-fetch(info, VALLEN(key), len)) != NULL) { + if (ac==3 strcmp(info-hnd-name, cdb)) { + php_error_docref(NULL TSRMLS_CC, E_NOTICE, Handler %s does not +support optional skip parameter, info-hnd-name); + } + if((val = info-hnd-fetch(info, VALLEN(key), skip, len)) != NULL) { RETURN_STRINGL(val, len, 0); } RETURN_FALSE; Index: php4/ext/dba/dba_cdb.c diff -u php4/ext/dba/dba_cdb.c:1.15 php4/ext/dba/dba_cdb.c:1.16 ---
[PHP-CVS] cvs: php4 /ext/dba dba.c
helly Fri Nov 1 09:15:24 2002 EDT Modified files: /php4/ext/dba dba.c Log: php_error - php_error_docref Index: php4/ext/dba/dba.c diff -u php4/ext/dba/dba.c:1.46 php4/ext/dba/dba.c:1.47 --- php4/ext/dba/dba.c:1.46 Fri Oct 25 06:06:35 2002 +++ php4/ext/dba/dba.c Fri Nov 1 09:15:24 2002 -16,7 +16,7 +--+ */ -/* $Id: dba.c,v 1.46 2002/10/25 10:06:35 helly Exp $ */ +/* $Id: dba.c,v 1.47 2002/11/01 14:15:24 helly Exp $ */ #ifdef HAVE_CONFIG_H #include config.h -130,7 +130,7 /* check whether the user has write access */ #define DBA_WRITE_CHECK \ if(info-mode != DBA_WRITER info-mode != DBA_TRUNC info-mode != DBA_CREAT) { \ - php_error(E_WARNING, %s(): you cannot perform a modification to a database without proper access, get_active_function_name(TSRMLS_C)); \ + php_error_docref(NULL TSRMLS_CC, E_WARNING, You cannot perform a +modification to a database without proper access); \ RETURN_FALSE; \ } -313,7 +313,7 for (hptr = handler; hptr-name strcasecmp(hptr-name, Z_STRVAL_PP(args[2])); hptr++); if (!hptr-name) { - php_error(E_WARNING, %s(): no such handler: %s, get_active_function_name(TSRMLS_C), Z_STRVAL_PP(args[2])); + php_error_docref(NULL TSRMLS_CC, E_WARNING, No such handler: %s, +Z_STRVAL_PP(args[2])); FREENOW; RETURN_FALSE; } -332,7 +332,7 modenr = DBA_TRUNC; break; default: - php_error(E_WARNING, %s(): illegal DBA mode: %s, get_active_function_name(TSRMLS_C), Z_STRVAL_PP(args[1])); + php_error_docref(NULL TSRMLS_CC, E_WARNING, Illegal DBA mode: +%s, Z_STRVAL_PP(args[1])); FREENOW; RETURN_FALSE; } -347,7 +347,7 if (hptr-open(info TSRMLS_CC) != SUCCESS) { dba_close(info); - php_error(E_WARNING, %s(): driver initialization failed, get_active_function_name(TSRMLS_C)); + php_error_docref(NULL TSRMLS_CC, E_WARNING, Driver initialization +failed for handler: %s, Z_STRVAL_PP(args[2])); FREENOW; RETURN_FALSE; } -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php