Greetings PHP people,

I have written a patch to resolve the issue mentioned in the subject. Also I
wrote a small test case for it. This patch is to be applied on PHP5_2 CVS.
Still in this matter, I have written a patch for dbase.c (this was based on
Felipe's patch which seems to have been lost) to use zend_parse_parameters
and also to check for the PHP version to define if the arginfo should
receive a static identifier or not.
The patches are attached, and so is the test case.
These files can also be found in the following URLs:

Patch for the bug: http://felipe.ath.cx/typoon/dbase_php5.2.9_bug47002.diff
Patch for dbase.c: http://felipe.ath.cx/typoon/dbase_php5.2.9.diff
Test case for the bug: http://felipe.ath.cx/typoon/bug47002.phpt

Currently I am also working on getting the dbase fixed in the PECL
repositories so we can have a release (just finishing writing some test
cases).

In case there are any doubts or problems, please let me know so I can
verify.

BTW, I am Gilgamesh on #php.pecl (sometimes shows up as typoon because of
problems with mibbit). So you can also contact me there :)

Thanks!

Henrique
Index: ext/dbase/dbase.c
===================================================================
RCS file: /repository/php-src/ext/dbase/Attic/dbase.c,v
retrieving revision 1.74.2.2.2.11
diff -u -u -w -b -r1.74.2.2.2.11 dbase.c
--- ext/dbase/dbase.c   31 Dec 2008 11:17:36 -0000      1.74.2.2.2.11
+++ ext/dbase/dbase.c   14 Jan 2009 16:49:21 -0000
@@ -57,6 +57,12 @@
 #define DBase_TLS_VARS
 #endif
 
+#if (PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION >= 3) || PHP_MAJOR_VERSION 
> 5
+#define STATIC_ARGINFO
+#else
+#define STATIC_ARGINFO  static
+#endif
+
 #include <fcntl.h>
 #include <errno.h>
 
@@ -118,41 +124,42 @@
    Opens a dBase-format database file */
 PHP_FUNCTION(dbase_open)
 {
-       zval **dbf_name, **options;
+       char *dbf_name;
+       int dbf_name_len;
+       long options;
+
        dbhead_t *dbh;
        int handle;
        DBase_TLS_VARS;
 
-       if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &dbf_name, 
&options) == FAILURE) {
-               WRONG_PARAM_COUNT;
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl", &dbf_name, 
&dbf_name_len, &options) == FAILURE) {
+               return;
        }
-       convert_to_string_ex(dbf_name);
-       convert_to_long_ex(options);
 
-       if (!Z_STRLEN_PP(dbf_name)) {
+       if (!strlen(dbf_name)) {
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "The filename 
cannot be empty.");
                RETURN_FALSE;
        }
 
-       if (Z_LVAL_PP(options) == 1) {
-               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot open %s in 
write-only mode", Z_STRVAL_PP(dbf_name));
+       if (options == 1) {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot open %s in 
write-only mode", dbf_name);
                RETURN_FALSE;
-       } else if (Z_LVAL_PP(options) < 0 || Z_LVAL_PP(options) > 3) {
-               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid access 
mode %ld", Z_LVAL_PP(options));
+       } else if (options < 0 || options > 3) {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid access 
mode %ld", options);
                RETURN_FALSE;
        }
 
-       if (PG(safe_mode) && (!php_checkuid(Z_STRVAL_PP(dbf_name), NULL, 
CHECKUID_CHECK_FILE_AND_DIR))) {
+       if (PG(safe_mode) && (!php_checkuid(dbf_name, NULL, 
CHECKUID_CHECK_FILE_AND_DIR))) {
                RETURN_FALSE;
        }
        
-       if (php_check_open_basedir(Z_STRVAL_PP(dbf_name) TSRMLS_CC)) {
+       if (php_check_open_basedir(dbf_name TSRMLS_CC)) {
                RETURN_FALSE;
        }
 
-       dbh = dbf_open(Z_STRVAL_PP(dbf_name), Z_LVAL_PP(options) TSRMLS_CC);
+       dbh = dbf_open(dbf_name, options TSRMLS_CC);
        if (dbh == NULL) {
-               php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to open 
database %s", Z_STRVAL_PP(dbf_name));
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to open 
database %s", dbf_name);
                RETURN_FALSE;
        }
 
@@ -165,22 +172,22 @@
    Closes an open dBase-format database file */
 PHP_FUNCTION(dbase_close)
 {
-       zval **dbh_id;
+       long dbh_id;
        dbhead_t *dbh;
        int dbh_type;
        DBase_TLS_VARS;
 
-       if (ZEND_NUM_ARGS() != 1 || (zend_get_parameters_ex(1, &dbh_id) == 
FAILURE)) {
-               WRONG_PARAM_COUNT;
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &dbh_id) == 
FAILURE) {
+               return;
        }
-       convert_to_long_ex(dbh_id);
-       dbh = zend_list_find(Z_LVAL_PP(dbh_id), &dbh_type);
+       
+       dbh = zend_list_find(dbh_id, &dbh_type);
        if (!dbh || dbh_type != DBase_GLOBAL(le_dbhead)) {
-               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find 
database for identifier %ld", Z_LVAL_PP(dbh_id));
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find 
database for identifier %ld", dbh_id);
                RETURN_FALSE;
        }
 
-       zend_list_delete(Z_LVAL_PP(dbh_id));
+       zend_list_delete(dbh_id);
        RETURN_TRUE;
 }
 /* }}} */
@@ -189,18 +196,18 @@
    Returns the number of records in the database */
 PHP_FUNCTION(dbase_numrecords)
 {
-       zval **dbh_id;
+       long dbh_id;
        dbhead_t *dbh;
        int dbh_type;
        DBase_TLS_VARS;
 
-       if (ZEND_NUM_ARGS() != 1 || (zend_get_parameters_ex(1, &dbh_id) == 
FAILURE)) {
-               WRONG_PARAM_COUNT;
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &dbh_id) == 
FAILURE) {
+               return;
        }
-       convert_to_long_ex(dbh_id);
-       dbh = zend_list_find(Z_LVAL_PP(dbh_id), &dbh_type);
+
+       dbh = zend_list_find(dbh_id, &dbh_type);
        if (!dbh || dbh_type != DBase_GLOBAL(le_dbhead)) {
-               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find 
database for identifier %ld", Z_LVAL_PP(dbh_id));
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find 
database for identifier %ld", dbh_id);
                RETURN_FALSE;
        }
 
@@ -212,18 +219,18 @@
    Returns the number of fields (columns) in the database */
 PHP_FUNCTION(dbase_numfields)
 {
-       zval **dbh_id;
+       long dbh_id;
        dbhead_t *dbh;
        int dbh_type;
        DBase_TLS_VARS;
 
-       if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &dbh_id) == 
FAILURE) {
-               WRONG_PARAM_COUNT;
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &dbh_id) == 
FAILURE) {
+               return;
        }
-       convert_to_long_ex(dbh_id);
-       dbh = zend_list_find(Z_LVAL_PP(dbh_id), &dbh_type);
+
+       dbh = zend_list_find(dbh_id, &dbh_type);
        if (!dbh || dbh_type != DBase_GLOBAL(le_dbhead)) {
-               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find 
database for identifier %ld", Z_LVAL_PP(dbh_id));
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find 
database for identifier %ld", dbh_id);
                RETURN_FALSE;
        }
 
@@ -235,18 +242,18 @@
    Packs the database (deletes records marked for deletion) */
 PHP_FUNCTION(dbase_pack)
 {
-       zval **dbh_id;
+       long dbh_id;
        dbhead_t *dbh;
        int dbh_type;
        DBase_TLS_VARS;
 
-       if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &dbh_id) == 
FAILURE) {
-               WRONG_PARAM_COUNT;
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &dbh_id) == 
FAILURE) {
+               return;
        }
-       convert_to_long_ex(dbh_id);
-       dbh = zend_list_find(Z_LVAL_PP(dbh_id), &dbh_type);
+
+       dbh = zend_list_find(dbh_id, &dbh_type);
        if (!dbh || dbh_type != DBase_GLOBAL(le_dbhead)) {
-               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find 
database for identifier %ld", Z_LVAL_PP(dbh_id));
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find 
database for identifier %ld", dbh_id);
                RETURN_FALSE;
        }
 
@@ -260,7 +267,8 @@
    Adds a record to the database */
 PHP_FUNCTION(dbase_add_record)
 {
-       zval **dbh_id, **fields, **field;
+       long dbh_id;
+       zval *fields, **field;
        dbhead_t *dbh;
        int dbh_type;
 
@@ -270,22 +278,18 @@
        int i;
        DBase_TLS_VARS;
 
-       if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &dbh_id, &fields) 
== FAILURE) {
-               WRONG_PARAM_COUNT;
-       }
-       convert_to_long_ex(dbh_id);
-       if (Z_TYPE_PP(fields) != IS_ARRAY) {
-               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Expected array as 
second parameter");
-               RETURN_FALSE;
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la", &dbh_id, 
&fields) == FAILURE) {
+               return;
        }
 
-       dbh = zend_list_find(Z_LVAL_PP(dbh_id), &dbh_type);
+
+       dbh = zend_list_find(dbh_id, &dbh_type);
        if (!dbh || dbh_type != DBase_GLOBAL(le_dbhead)) {
-               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find 
database for identifier %ld", Z_LVAL_PP(dbh_id));
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find 
database for identifier %ld", dbh_id);
                RETURN_FALSE;
        }
 
-       num_fields = zend_hash_num_elements(Z_ARRVAL_PP(fields));
+       num_fields = zend_hash_num_elements(Z_ARRVAL_P(fields));
 
        if (num_fields != dbh->db_nfields) {
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "Wrong number of 
fields specified");
@@ -298,7 +302,7 @@
        dbf = dbh->db_fields;
        for (i = 0, cur_f = dbf; cur_f < &dbf[num_fields]; i++, cur_f++) {
                zval tmp;
-               if (zend_hash_index_find(Z_ARRVAL_PP(fields), i, (void 
**)&field) == FAILURE) {
+               if (zend_hash_index_find(Z_ARRVAL_P(fields), i, (void 
**)&field) == FAILURE) {
                        php_error_docref(NULL TSRMLS_CC, E_WARNING, "unexpected 
error");
                        efree(cp);
                        RETURN_FALSE;
@@ -330,7 +334,8 @@
    Replaces a record to the database */
 PHP_FUNCTION(dbase_replace_record)
 {
-       zval **dbh_id, **fields, **field, **recnum;
+       long dbh_id, recnum;
+       zval *fields, **field;
        dbhead_t *dbh;
        int dbh_type;
 
@@ -340,23 +345,17 @@
        int i;
        DBase_TLS_VARS;
 
-       if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &dbh_id, &fields, 
&recnum) == FAILURE) {
-               WRONG_PARAM_COUNT;
-       }
-       convert_to_long_ex(dbh_id);
-       convert_to_long_ex(recnum);
-       if (Z_TYPE_PP(fields) != IS_ARRAY) {
-               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Expected array as 
second parameter");
-               RETURN_FALSE;
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lal", &dbh_id, 
&fields, &recnum) == FAILURE) {
+               return;
        }
 
-       dbh = zend_list_find(Z_LVAL_PP(dbh_id), &dbh_type);
+       dbh = zend_list_find(dbh_id, &dbh_type);
        if (!dbh || dbh_type != DBase_GLOBAL(le_dbhead)) {
-               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find 
database for identifier %ld", Z_LVAL_PP(dbh_id));
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find 
database for identifier %ld", dbh_id);
                RETURN_FALSE;
        }
 
-       num_fields = zend_hash_num_elements(Z_ARRVAL_PP(fields));
+       num_fields = zend_hash_num_elements(Z_ARRVAL_P(fields));
 
        if (num_fields != dbh->db_nfields) {
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "Wrong number of 
fields specified");
@@ -368,7 +367,7 @@
 
        dbf = dbh->db_fields;
        for (i = 0, cur_f = dbf; cur_f < &dbf[num_fields]; i++, cur_f++) {
-               if (zend_hash_index_find(Z_ARRVAL_PP(fields), i, (void 
**)&field) == FAILURE) {
+               if (zend_hash_index_find(Z_ARRVAL_P(fields), i, (void 
**)&field) == FAILURE) {
                        php_error_docref(NULL TSRMLS_CC, E_WARNING, "unexpected 
error");
                        efree(cp);
                        RETURN_FALSE;
@@ -378,7 +377,7 @@
                t_cp += cur_f->db_flen;
        }
 
-       if (put_dbf_record(dbh, Z_LVAL_PP(recnum), cp) < 0) {
+       if (put_dbf_record(dbh, recnum, cp) < 0) {
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to put 
record at %ld", dbh->db_records);
                efree(cp);
                RETURN_FALSE;
@@ -395,28 +394,26 @@
    Marks a record to be deleted */
 PHP_FUNCTION(dbase_delete_record)
 {
-       zval **dbh_id, **record;
+       long dbh_id, record;
        dbhead_t *dbh;
        int dbh_type;
        DBase_TLS_VARS;
 
-       if (ZEND_NUM_ARGS() != 2 || (zend_get_parameters_ex(2, &dbh_id, 
&record) == FAILURE)) {
-               WRONG_PARAM_COUNT;
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &dbh_id, 
&record) == FAILURE) {
+               return;
        }
-       convert_to_long_ex(dbh_id);
-       convert_to_long_ex(record);
 
-       dbh = zend_list_find(Z_LVAL_PP(dbh_id), &dbh_type);
+       dbh = zend_list_find(dbh_id, &dbh_type);
        if (!dbh || dbh_type != DBase_GLOBAL(le_dbhead)) {
-               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find 
database for identifier %ld", Z_LVAL_PP(dbh_id));
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find 
database for identifier %ld", dbh_id);
                RETURN_FALSE;
        }
 
-       if (del_dbf_record(dbh, Z_LVAL_PP(record)) < 0) {
-               if (Z_LVAL_PP(record) > dbh->db_records) {
-                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "record %ld 
out of bounds", Z_LVAL_PP(record));
+       if (del_dbf_record(dbh, record) < 0) {
+               if (record > dbh->db_records) {
+                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "record %ld 
out of bounds", record);
                } else {
-                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to 
delete record %ld", Z_LVAL_PP(record));
+                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to 
delete record %ld", record);
                }
                RETURN_FALSE;
        }
@@ -430,7 +427,7 @@
  */  
 static void php_dbase_get_record(INTERNAL_FUNCTION_PARAMETERS, int assoc)
 {
-       zval **dbh_id, **record;
+       long dbh_id, record;
        dbhead_t *dbh;
        int dbh_type;
        dbfield_t *dbf, *cur_f;
@@ -440,20 +437,18 @@
        int errno_save;
        DBase_TLS_VARS;
 
-       if (ZEND_NUM_ARGS() != 2 || (zend_get_parameters_ex(2, &dbh_id, 
&record) == FAILURE)) {
-               WRONG_PARAM_COUNT;
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &dbh_id, 
&record) == FAILURE) {
+               return;
        }
-       convert_to_long_ex(dbh_id);
-       convert_to_long_ex(record);
 
-       dbh = zend_list_find(Z_LVAL_PP(dbh_id), &dbh_type);
+       dbh = zend_list_find(dbh_id, &dbh_type);
        if (!dbh || dbh_type != DBase_GLOBAL(le_dbhead)) {
-               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find 
database for identifier %ld", Z_LVAL_PP(dbh_id));
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find 
database for identifier %ld", dbh_id);
                RETURN_FALSE;
        }
 
-       if ((data = get_dbf_record(dbh, Z_LVAL_PP(record))) == NULL) {
-               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Tried to read bad 
record %ld", Z_LVAL_PP(record));
+       if ((data = get_dbf_record(dbh, record)) == NULL) {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Tried to read bad 
record %ld", record);
                RETURN_FALSE;
        }
 
@@ -587,8 +582,9 @@
    Creates a new dBase-format database file */
 PHP_FUNCTION(dbase_create)
 {
-       zval **filename, **fields, **field, **value;
-       int fd;
+       char *filename;
+       zval *fields, **field, **value;
+       int filename_len, fd;
        dbhead_t *dbh;
 
        int num_fields;
@@ -596,30 +592,24 @@
        int i, rlen, handle;
        DBase_TLS_VARS;
 
-       if (ZEND_NUM_ARGS() != 2 || (zend_get_parameters_ex(2, &filename, 
&fields) == FAILURE)) {
-               WRONG_PARAM_COUNT;
-       }
-       convert_to_string_ex(filename);
-
-       if (Z_TYPE_PP(fields) != IS_ARRAY) {
-               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Expected array as 
second parameter");
-               RETURN_FALSE;
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sa", &filename, 
&filename_len, &fields) == FAILURE) {
+               return;
        }
 
-       if (PG(safe_mode) && (!php_checkuid(Z_STRVAL_PP(filename), NULL, 
CHECKUID_CHECK_FILE_AND_DIR))) {
+       if (PG(safe_mode) && (!php_checkuid(filename, NULL, 
CHECKUID_CHECK_FILE_AND_DIR))) {
                RETURN_FALSE;
        }
        
-       if (php_check_open_basedir(Z_STRVAL_PP(filename) TSRMLS_CC)) {
+       if (php_check_open_basedir(filename TSRMLS_CC)) {
                RETURN_FALSE;
        }
 
-       if ((fd = VCWD_OPEN_MODE(Z_STRVAL_PP(filename), 
O_BINARY|O_RDWR|O_CREAT, 0644)) < 0) {
+       if ((fd = VCWD_OPEN_MODE(filename, O_BINARY|O_RDWR|O_CREAT, 0644)) < 0) 
{
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to create 
database (%d): %s", errno, strerror(errno));
                RETURN_FALSE;
        }
 
-       num_fields = zend_hash_num_elements(Z_ARRVAL_PP(fields));
+       num_fields = zend_hash_num_elements(Z_ARRVAL_P(fields));
 
        if (num_fields <= 0) {
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to create 
database without fields");
@@ -661,7 +651,7 @@
 
        for (i = 0, cur_f = dbf; i < num_fields; i++, cur_f++) {
                /* look up the first field */
-               if (zend_hash_index_find(Z_ARRVAL_PP(fields), i, (void 
**)&field) == FAILURE) {
+               if (zend_hash_index_find(Z_ARRVAL_P(fields), i, (void 
**)&field) == FAILURE) {
                        php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to 
find field %d", i);
                        free_dbf_head(dbh);
                        RETURN_FALSE;
@@ -754,70 +744,70 @@
 /* }}} */
 
 /* {{{ arginfo */
-static
+STATIC_ARGINFO
 ZEND_BEGIN_ARG_INFO(arginfo_dbase_open, 0)
        ZEND_ARG_INFO(0, name)
        ZEND_ARG_INFO(0, mode)
 ZEND_END_ARG_INFO()
 
-static
+STATIC_ARGINFO
 ZEND_BEGIN_ARG_INFO(arginfo_dbase_close, 0)
        ZEND_ARG_INFO(0, identifier)
 ZEND_END_ARG_INFO()
 
-static
+STATIC_ARGINFO
 ZEND_BEGIN_ARG_INFO(arginfo_dbase_numrecords, 0)
        ZEND_ARG_INFO(0, identifier)
 ZEND_END_ARG_INFO()
 
-static
+STATIC_ARGINFO
 ZEND_BEGIN_ARG_INFO(arginfo_dbase_numfields, 0)
        ZEND_ARG_INFO(0, identifier)
 ZEND_END_ARG_INFO()
 
-static
+STATIC_ARGINFO
 ZEND_BEGIN_ARG_INFO(arginfo_dbase_pack, 0)
        ZEND_ARG_INFO(0, identifier)
 ZEND_END_ARG_INFO()
 
-static
+STATIC_ARGINFO
 ZEND_BEGIN_ARG_INFO(arginfo_dbase_add_record, 0)
        ZEND_ARG_INFO(0, identifier)
        ZEND_ARG_INFO(0, data) /* ARRAY_INFO(0, data, 0) */
 ZEND_END_ARG_INFO()
 
-static
+STATIC_ARGINFO
 ZEND_BEGIN_ARG_INFO(arginfo_dbase_replace_record, 0)
        ZEND_ARG_INFO(0, identifier)
        ZEND_ARG_INFO(0, data) /* ARRAY_INFO(0, data, 0) */
        ZEND_ARG_INFO(0, recnum)
 ZEND_END_ARG_INFO()
 
-static
+STATIC_ARGINFO
 ZEND_BEGIN_ARG_INFO(arginfo_dbase_delete_record, 0)
        ZEND_ARG_INFO(0, identifier)
        ZEND_ARG_INFO(0, record)
 ZEND_END_ARG_INFO()
 
-static
+STATIC_ARGINFO
 ZEND_BEGIN_ARG_INFO(arginfo_dbase_get_record, 0)
        ZEND_ARG_INFO(0, identifier)
        ZEND_ARG_INFO(0, record)
 ZEND_END_ARG_INFO()
 
-static
+STATIC_ARGINFO
 ZEND_BEGIN_ARG_INFO(arginfo_dbase_get_record_with_names, 0)
        ZEND_ARG_INFO(0, identifier)
        ZEND_ARG_INFO(0, record)
 ZEND_END_ARG_INFO()
 
-static
+STATIC_ARGINFO
 ZEND_BEGIN_ARG_INFO(arginfo_dbase_create, 0)
        ZEND_ARG_INFO(0, filename)
        ZEND_ARG_INFO(0, fields) /* ARRAY_INFO(0, fields, 0) */
 ZEND_END_ARG_INFO()
 
-static
+STATIC_ARGINFO
 ZEND_BEGIN_ARG_INFO(arginfo_dbase_get_header_info, 0)
        ZEND_ARG_INFO(0, database_handle)
 ZEND_END_ARG_INFO()
@@ -848,20 +838,20 @@
  */
 PHP_FUNCTION(dbase_get_header_info)
 {
-       zval            **dbh_id, *row;
+       zval            *row;
+       long            dbh_id;
        dbfield_t       *dbf, *cur_f;
        dbhead_t        *dbh;
        int             dbh_type;
        DBase_TLS_VARS; 
 
-       if (ZEND_NUM_ARGS() != 1 || (zend_get_parameters_ex(1, &dbh_id) == 
FAILURE)) {
-               WRONG_PARAM_COUNT;
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &dbh_id) == 
FAILURE) {
+               return;
        }
-       convert_to_long_ex(dbh_id);
 
-       dbh = zend_list_find(Z_LVAL_PP(dbh_id), &dbh_type);
+       dbh = zend_list_find(dbh_id, &dbh_type);
        if (!dbh || dbh_type != DBase_GLOBAL(le_dbhead)) {
-               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find 
database for identifier %ld", Z_LVAL_PP(dbh_id));
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find 
database for identifier %ld", dbh_id);
                RETURN_FALSE;
        }
 
--TEST--
Bug #47002 (Incorrect number of fields when number of fields > 1024)
--SKIPIF--
<?php
if (!extension_loaded('dbase')) {
        die('skip dbase extension not available');
}
?>
--FILE--
<?php

$fields = array();
$file = dirname(__FILE__)."/bug47002.dbf";

for( $i = 0; $i < 2048; $i++ ) {
        $fields[] = array('field'.$i, 'C', 10);
}

$id = dbase_create($file, $fields);

var_dump(dbase_numfields($id));

@unlink($file);

echo "Done\n";
?>
--EXPECTF--     
int(2048)
Done
Index: ext/dbase/dbf_head.c
===================================================================
RCS file: /repository/php-src/ext/dbase/Attic/dbf_head.c,v
retrieving revision 1.14.4.1.2.8
diff -u -u -w -b -r1.14.4.1.2.8 dbf_head.c
--- ext/dbase/dbf_head.c        18 Nov 2007 14:20:17 -0000      1.14.4.1.2.8
+++ ext/dbase/dbf_head.c        14 Jan 2009 16:49:27 -0000
@@ -22,7 +22,7 @@
        dbhead_t *dbh;
        struct dbf_dhead  dbhead;
        dbfield_t *dbf, *cur_f, *tdbf;
-       int ret, nfields, offset, gf_retval;
+       int ret, nfields, offset, gf_retval, i;
 
        if ((dbh = (dbhead_t *)calloc(1, sizeof(dbhead_t))) == NULL)
                return NULL;
@@ -46,14 +46,16 @@
                dbhead.dbh_date[DBH_DATE_MONTH],
                dbhead.dbh_date[DBH_DATE_DAY]);
 
+       nfields = ((dbh->db_hlen - sizeof(dbhead_t)) / sizeof(dbfield_t))+1;
+
        /* malloc enough memory for the maximum number of fields:
           32 * 1024 = 32K dBase5 (for Win) seems to allow that many */
-       tdbf = (dbfield_t *)calloc(1, sizeof(dbfield_t)*1024);
+       tdbf = (dbfield_t *)malloc(sizeof(dbfield_t)*nfields);
        
        offset = 1;
-       nfields = 0;
        gf_retval = 0;
-       for (cur_f = tdbf; gf_retval < 2 && nfields < 1024; cur_f++) {
+       i = 0;
+       for (cur_f = tdbf; gf_retval < 2 && i < nfields; cur_f++) {
                gf_retval = get_dbf_field(dbh, cur_f);
 
                if (gf_retval < 0) {
@@ -64,7 +66,6 @@
                if (gf_retval != 2 ) {
                        cur_f->db_foffset = offset;
                        offset += cur_f->db_flen;
-                       nfields++;
                }
        }
        dbh->db_nfields = nfields;
-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to