]> granicus.if.org Git - php/commitdiff
Convert to Ex API. Does anyone have a better name for it?
authorSascha Schumann <sas@php.net>
Fri, 17 Sep 1999 09:56:30 +0000 (09:56 +0000)
committerSascha Schumann <sas@php.net>
Fri, 17 Sep 1999 09:56:30 +0000 (09:56 +0000)
ext/dba/dba.c
ext/dba/dba_db2.c
ext/dba/dba_dbm.c
ext/dba/dba_gdbm.c
ext/dba/dba_ndbm.c
ext/dba/php3_dba.h

index d95f4276221be6f81d3b7de9d92759db6b9f6ff1..d0b5a183fb7840f38dbbdb3733bd586a1a2c7862 100644 (file)
@@ -86,31 +86,35 @@ typedef struct dba_handler {
 
 /* {{{ macromania */
 
-#define DBA_ID_PARS pval *id; dba_info *info = NULL; int type, ac = ARG_COUNT(ht)
+#define DBA_ID_PARS                                                                                    \
+       pval **id;                                                                                                      \
+       dba_info *info = NULL;                                                                          \
+       int type, ac = ARG_COUNT(ht)
 
 /* these are used to get the standard arguments */
 
-#define DBA_GET1 \
-       if(ac != 1 || getParameters(ht, ac, &id) != SUCCESS) { \
-               WRONG_PARAM_COUNT; \
+#define DBA_GET1                                                                                               \
+       if(ac != 1 || getParametersEx(ac, &id) != SUCCESS) {            \
+               WRONG_PARAM_COUNT;                                                                              \
        }
 
-#define DBA_GET2 \
-       pval *key; \
-       if(ac != 2 || getParameters(ht, ac, &key, &id) != SUCCESS) { \
-               WRONG_PARAM_COUNT; \
-       } \
-       convert_to_string(key)
+#define DBA_GET2                                                                                               \
+       pval **key;                                                                                             \
+       if(ac != 2 || getParametersEx(ac, &key, &id) != SUCCESS) {      \
+               WRONG_PARAM_COUNT;                                                                              \
+       }                                                                                                                       \
+       convert_to_string_ex(key)
 
-#define DBA_IF_NOT_CORRECT_TYPE(link_id) \
-       info = php3_list_find(link_id, &type); \
+#define DBA_IF_NOT_CORRECT_TYPE(link_id)                                               \
+       info = php3_list_find(link_id, &type);                                          \
        if(!info || (type != GLOBAL(le_db) && type != GLOBAL(le_pdb)))
        
-#define DBA_ID_GET \
-       convert_to_long(id); \
-       DBA_IF_NOT_CORRECT_TYPE(id->value.lval) { \
-               php_error(E_WARNING, "Unable to find DBA identifier %d", id->value.lval); \
-               RETURN_FALSE; \
+#define DBA_ID_GET                                                                                             \
+       convert_to_long_ex(id);                                                                         \
+       DBA_IF_NOT_CORRECT_TYPE((*id)->value.lval) {                            \
+               php_error(E_WARNING, "Unable to find DBA identifier %d", \
+                               (*id)->value.lval);                                                     \
+               RETURN_FALSE;                                                                                   \
        }
        
 #define DBA_ID_GET1 DBA_ID_PARS; DBA_GET1; DBA_ID_GET
@@ -208,13 +212,13 @@ static PHP_MINFO_FUNCTION(dba)
 static void _php3_dba_update(INTERNAL_FUNCTION_PARAMETERS, int mode)
 {
        DBA_ID_PARS;
-       pval *val, *key;
+       pval **val, **key;
 
-       if(ac != 3 || getParameters(ht, ac, &key, &val, &id) != SUCCESS) {
+       if(ac != 3 || getParametersEx(ac, &key, &val, &id) != SUCCESS) {
                WRONG_PARAM_COUNT;
        }
-       convert_to_string(key);
-       convert_to_string(val);
+       convert_to_string_ex(key);
+       convert_to_string_ex(val);
        DBA_ID_GET;
 
        DBA_WRITE_CHECK;
@@ -230,7 +234,7 @@ static void _php3_dba_update(INTERNAL_FUNCTION_PARAMETERS, int mode)
 
 static void _php3_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent)
 {
-       pval **args = (pval **) NULL;
+       pval ***args = (pval ***) NULL;
        int ac = ARG_COUNT(ht);
        dba_mode_t modenr;
        dba_info *info;
@@ -246,15 +250,15 @@ static void _php3_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent)
        
        /* we pass additional args to the respective handler */
        args = emalloc(ac * sizeof(pval *));
-       if(getParametersArray(ht, ac, args) != SUCCESS) {
+       if(getParametersArrayEx(ac, args) != SUCCESS) {
                FREENOW;
                WRONG_PARAM_COUNT;
        }
                
        /* we only take string arguments */
        for(i = 0; i < ac; i++) {
-               convert_to_string(args[i]);
-               keylen += args[i]->value.str.len;
+               convert_to_string_ex(args[i]);
+               keylen += (*args[i])->value.str.len;
        }
 
        if(persistent) {
@@ -263,8 +267,8 @@ static void _php3_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent)
                keylen = 0;
                
                for(i = 0; i < ac; i++) {
-                       memcpy(key+keylen,args[i]->value.str.val,args[i]->value.str.len);
-                       keylen += args[i]->value.str.len;
+                       memcpy(key+keylen,(*args[i])->value.str.val,(*args[i])->value.str.len);
+                       keylen += (*args[i])->value.str.len;
                }
                
                if(zend_hash_find(&ht_keys, key, keylen, (void **) &info) == SUCCESS) {
@@ -273,17 +277,16 @@ static void _php3_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent)
                }
        }
        
-       /* this is O(n) and could be improved */
        for(hptr = handler; hptr->name &&
-                       strcasecmp(hptr->name, args[2]->value.str.val); hptr++);
+                       strcasecmp(hptr->name, (*args[2])->value.str.val); hptr++);
 
        if(!hptr->name) {
-               php_error(E_WARNING, "no such handler: %s", args[2]->value.str.val);
+               php_error(E_WARNING, "no such handler: %s", (*args[2])->value.str.val);
                FREENOW;
                RETURN_FALSE;
        }
 
-       switch(args[1]->value.str.val[0]) {
+       switch((*args[1])->value.str.val[0]) {
                case 'c': 
                        modenr = DBA_CREAT; 
                        break;
@@ -297,14 +300,14 @@ static void _php3_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent)
                        modenr = DBA_TRUNC;
                        break;
                default:
-                       php_error(E_WARNING,"illegal DBA mode: %s",args[1]->value.str.val);
+                       php_error(E_WARNING,"illegal DBA mode: %s",(*args[1])->value.str.val);
                        FREENOW;
                        RETURN_FALSE;
        }
                        
        info = malloc(sizeof(*info));
        memset(info, 0, sizeof(info));
-       info->path = strdup(args[0]->value.str.val);
+       info->path = strdup((*args[0])->value.str.val);
        info->mode = modenr;
        info->argc = ac - 3;
        info->argv = args + 3;
@@ -354,7 +357,7 @@ PHP_FUNCTION(dba_close)
 {
        DBA_ID_GET1;    
        
-       php3_list_delete(id->value.lval);
+       php3_list_delete((*id)->value.lval);
 }
 /* }}} */
 
index 7812fdfa71f6d6abc733a7923cdcda97a8503788..77f010a7f2120306c18cfb5819300644ae72fa5c 100644 (file)
@@ -78,8 +78,8 @@ DBA_OPEN_FUNC(db2)
                return FAILURE;
 
        if(info->argc > 0) {
-               convert_to_long(info->argv[0]);
-               filemode = info->argv[0]->value.lval;
+               convert_to_long_ex(info->argv[0]);
+               filemode = (*info->argv[0])->value.lval;
        }
 
        if(!db_open(info->path, type, gmode, filemode, NULL, NULL, &dbp)) {
index 5858e8e6105dbae6811030903c598a719e3c89fc..b8b4ea95f2d37df2e8fa666fa2f2c246b4f74ced 100644 (file)
@@ -66,8 +66,8 @@ DBA_OPEN_FUNC(dbm)
        int filemode = 0644;
 
        if(info->argc > 0) {
-               convert_to_long(info->argv[0]);
-               filemode = info->argv[0]->value.lval;
+               convert_to_long_ex(info->argv[0]);
+               filemode = (*info->argv[0])->value.lval;
        }
        
        if(info->mode == DBA_TRUNC) {
index 0e5f1450f258501e86022b353bc807d2b7f766fd..6fde65ec73405acbf4a5e4f360368e24b38ef221 100644 (file)
@@ -59,8 +59,8 @@ DBA_OPEN_FUNC(gdbm)
                return FAILURE;
 
        if(info->argc > 0) {
-               convert_to_long(info->argv[0]);
-               filemode = info->argv[0]->value.lval;
+               convert_to_long_ex(info->argv[0]);
+               filemode = (*info->argv[0])->value.lval;
        }
 
        dbf = gdbm_open(info->path, 0, gmode, filemode, NULL);
index 0c6e2cd077500c8731b0df9cd1e3996aaeeb1379..3c10868aaba21442337b12dbd044b399ea318aab 100644 (file)
@@ -69,8 +69,8 @@ DBA_OPEN_FUNC(ndbm)
        }
 
        if(info->argc > 0) {
-               convert_to_long(info->argv[0]);
-               filemode = info->argv[0]->value.lval;
+               convert_to_long_ex(info->argv[0]);
+               filemode = (*info->argv[0])->value.lval;
        }
 
        dbf = dbm_open(info->path, gmode, filemode);
index caa7bfed0540c2c329440c2be9e58618983e6586..4a1470c5034d3d976d28b2a41a25842089becd16 100644 (file)
@@ -48,7 +48,7 @@ typedef struct dba_info {
        dba_mode_t mode;
        /* arg[cv] are only available when the dba_open handler is called! */
        int argc;
-       pval **argv;
+       pval ***argv;
        /* private */
        struct dba_handler *hnd;
 } dba_info;
@@ -91,7 +91,7 @@ extern php3_module_entry dba_module_entry;
        DBA_OPTIMIZE_FUNC(x); \
        DBA_SYNC_FUNC(x)
 
-#define VALLEN(p) (p)->value.str.val, (p)->value.str.len
+#define VALLEN(p) (*p)->value.str.val, (*p)->value.str.len
        
 PHP_FUNCTION(dba_open);
 PHP_FUNCTION(dba_popen);