From a7b91019e9b551ff48dd91587674784b7020673f Mon Sep 17 00:00:00 2001 From: Ilia Alshanetsky Date: Sat, 18 Jan 2003 19:49:28 +0000 Subject: [PATCH] Removed pointless memory allocation checks. --- ext/db/db.c | 10 +--- ext/dba/dba.c | 12 ++--- ext/dbx/dbx.c | 26 ++-------- ext/dbx/dbx_odbc.c | 6 +-- ext/domxml/php_domxml.c | 48 ++++-------------- ext/fbsql/php_fbsql.c | 7 +-- ext/fdf/fdf.c | 13 ++--- ext/hwapi/hwapi.cpp | 35 ++++--------- ext/hyperwave/hw.c | 108 ++++++++++------------------------------ ext/iconv/iconv.c | 19 ++----- 10 files changed, 68 insertions(+), 216 deletions(-) diff --git a/ext/db/db.c b/ext/db/db.c index 785eaebc7d..338d8dd581 100644 --- a/ext/db/db.c +++ b/ext/db/db.c @@ -198,10 +198,8 @@ PHP_FUNCTION(db_id_list) RETURN_FALSE; } - if (array_init(return_value) == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_ERROR, "Unable to initialize array"); - RETURN_FALSE; - } + array_init(return_value); + numitems = zend_hash_next_free_element(&EG(regular_list)); for (i=1; ifilename = estrdup(filename); info->lockfn = lockfn; diff --git a/ext/dba/dba.c b/ext/dba/dba.c index 2e59825c1b..5b98455e1f 100644 --- a/ext/dba/dba.c +++ b/ext/dba/dba.c @@ -841,10 +841,8 @@ PHP_FUNCTION(dba_handlers) RETURN_FALSE; } - if (array_init(return_value) == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_ERROR, "Unable to initialize array"); - RETURN_FALSE; - } + array_init(return_value); + for(hptr = handler; hptr->name; hptr++) { if (full_info) { add_assoc_string(return_value, hptr->name, hptr->info(hptr, NULL TSRMLS_CC), 0); @@ -868,10 +866,8 @@ PHP_FUNCTION(dba_list) RETURN_FALSE; } - if (array_init(return_value) == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_ERROR, "Unable to initialize array"); - RETURN_FALSE; - } + array_init(return_value); + numitems = zend_hash_next_free_element(&EG(regular_list)); for (i=1; iinput; if (ctxt->name) { @@ -1380,9 +1378,7 @@ static void domxml_error_validate(void *ctx, const char *msg, ...) if (ctxt != NULL && ctxt->errors != NULL) { zval *errormessages; MAKE_STD_ZVAL(errormessages); - if(array_init(errormessages) != SUCCESS) { - /* do error handling here */ - } + array_init(errormessages); if (ctxt->parser != NULL) { if (ctxt->parser->name) { add_assoc_string(errormessages,"nodename",ctxt->parser->name,1); @@ -2254,9 +2250,7 @@ PHP_FUNCTION(domxml_node_children) else last = nodep->children; - if (array_init(return_value) == FAILURE) { - RETURN_FALSE; - } + array_init(return_value); if (last) { while (last) { @@ -2932,9 +2926,6 @@ PHP_FUNCTION(domxml_doc_get_elements_by_tagname) } ctxp->node = contextnodep; str = (char*) emalloc((name_len+3) * sizeof(char)) ; - if (str == NULL) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot allocate memory for string"); - } sprintf(str ,"//%s",name); xpathobjp = xmlXPathEval(str, ctxp); @@ -2945,11 +2936,7 @@ PHP_FUNCTION(domxml_doc_get_elements_by_tagname) } MAKE_STD_ZVAL(rv); - if(array_init(rv) != SUCCESS) - { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot create required array"); - RETURN_FALSE; - } + array_init(rv); switch (Z_TYPE_P(xpathobjp)) { @@ -3040,10 +3027,7 @@ PHP_FUNCTION(domxml_elem_get_elements_by_tagname) MAKE_STD_ZVAL(rv); - if(array_init(rv) != SUCCESS) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot create required array"); - RETURN_FALSE; - } + array_init(rv); nodesetp = php_get_elements_by_tagname(nodep, name, NULL); @@ -3139,9 +3123,7 @@ PHP_FUNCTION(domxml_doctype_entities) RETURN_FALSE; } - if (array_init(return_value) == FAILURE) { - RETURN_FALSE; - } + array_init(return_value); while (last) { zval *child; @@ -3170,9 +3152,7 @@ PHP_FUNCTION(domxml_doctype_notations) RETURN_FALSE; } - if (array_init(return_value) == FAILURE) { - RETURN_FALSE; - } + array_init(return_value); while (last) { zval *child; @@ -3774,10 +3754,7 @@ PHP_FUNCTION(domxml_doc_ids) ids = docp->ids; if(ids) { - if (array_init(return_value) == FAILURE) { - RETURN_FALSE; - } - + array_init(return_value); xmlHashScan(ids, (void *)idsHashScanner2, return_value); } else { RETURN_FALSE; @@ -4508,9 +4485,7 @@ static int node_namespace(zval **attributes, xmlNode *nodep TSRMLS_DC) /* create an php array for the children */ MAKE_STD_ZVAL(*attributes); - if (array_init(*attributes) == FAILURE) { - return -1; - } + array_init(*attributes); while (ns) { zval *pattr; @@ -4792,10 +4767,7 @@ static void php_xpathptr_eval(INTERNAL_FUNCTION_PARAMETERS, int mode, int expr) xmlNodeSetPtr nodesetp; MAKE_STD_ZVAL(arr); - if (array_init(arr) == FAILURE) { - zval_dtor(rv); - RETURN_FALSE; - } + array_init(arr); if (NULL == (nodesetp = xpathobjp->nodesetval)) { zval_dtor(rv); diff --git a/ext/fbsql/php_fbsql.c b/ext/fbsql/php_fbsql.c index 75a6e14b98..11786c7b30 100644 --- a/ext/fbsql/php_fbsql.c +++ b/ext/fbsql/php_fbsql.c @@ -2815,10 +2815,7 @@ static void php_fbsql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int result_type) php_error_docref(NULL TSRMLS_CC, E_WARNING, "Illegal result type use FBSQL_NUM, FBSQL_ASSOC, or FBSQL_BOTH"); RETURN_FALSE; } - if (array_init(return_value)==FAILURE) - { - RETURN_FALSE; - } + array_init(return_value); if (result->fetchHandle == NULL) { if (result->array == NULL && result->list == NULL) @@ -3015,7 +3012,7 @@ PHP_FUNCTION(fbsql_fetch_lengths) ZEND_FETCH_RESOURCE(result, PHPFBResult *, fbsql_result_index, -1, "FrontBase-Result", le_result); if (result->row == NULL) RETURN_FALSE; - if (array_init(return_value)==FAILURE) RETURN_FALSE; + array_init(return_value); for (i=0; i < result->columnCount; i++) { unsigned length = 0; diff --git a/ext/fdf/fdf.c b/ext/fdf/fdf.c index 293d53df7d..2d77b947fa 100644 --- a/ext/fdf/fdf.c +++ b/ext/fdf/fdf.c @@ -358,10 +358,7 @@ PHP_FUNCTION(fdf_get_value) } #if HAVE_FDFTK_5 } else if((err == FDFErcValueIsArray) && (which == -1)) { - if (array_init(return_value) == FAILURE) { - efree(buffer); - FDF_FAILURE(FDFErcInternalError); - } + array_init(return_value); which = 0; do { err = FDFGetNthValue(fdf, fieldname, which, buffer, size-2, &nr); @@ -1037,9 +1034,7 @@ PHP_FUNCTION(fdf_get_opt) { if(err != FDFErcOK) { FDF_FAILURE(err); } - if (array_init(return_value) == FAILURE) { - RETURN_FALSE; - } + array_init(return_value); add_next_index_stringl(return_value, buf1, strlen(buf1), 1); add_next_index_stringl(return_value, buf2, strlen(buf2), 1); efree(buf1); @@ -1470,9 +1465,7 @@ PHP_FUNCTION(fdf_get_attachment) { FDF_FAILURE(err); } - if (array_init(return_value) == FAILURE) { - RETURN_FALSE; - } + array_init(return_value); add_assoc_string(return_value, "path", pathbuf, 1); add_assoc_string(return_value, "type", mimebuf, 1); stat(pathbuf, &statBuf); diff --git a/ext/hwapi/hwapi.cpp b/ext/hwapi/hwapi.cpp index 6ebc07fb7c..c8a03013d7 100644 --- a/ext/hwapi/hwapi.cpp +++ b/ext/hwapi/hwapi.cpp @@ -311,9 +311,7 @@ static void print_hwapi_stringarray(const HW_API_StringArray& strings) { } static int stringArray2indexArray(pval **return_value, HW_API_StringArray *values) { - if (array_init(*return_value) == FAILURE) { - return 0; - } + array_init(*return_value); for (int i=0; icount(); i++) { HW_API_String str; values->string(i, str); @@ -324,9 +322,7 @@ static int stringArray2indexArray(pval **return_value, HW_API_StringArray *value } static int objectArray2indexArray(pval **return_value, HW_API_ObjectArray *objarr) { - if (array_init(*return_value) == FAILURE) { - return 0; - } + array_init(*return_value); for(int i=0; icount(); i++) { zval *child; @@ -2400,9 +2396,7 @@ PHP_FUNCTION(hwapi_mychildren) { objarr = (HW_API_ObjectArray) out.objects(); } - if (array_init(return_value) == FAILURE) { - RETURN_FALSE; - } + array_init(return_value); for(i=0; ivalue.ht, "typeInfo", 9, &rv, sizeof(zval *), NULL); @@ -4588,16 +4578,13 @@ PHP_FUNCTION(hwapi_content_read) { Z_TYPE_PP(arg1) = IS_STRING; /* FIXME: Need to finish the new zval */ value = (char *) emalloc(Z_LVAL_PP(arg2)+1); - if(value) { - Z_STRVAL_PP(arg1) = value; - len = contentp->read(value, Z_LVAL_PP(arg2)); - value[len] = '\0'; - Z_STRLEN_PP(arg1) = len; - RETURN_LONG(len); - } else { - RETURN_FALSE; - } + Z_STRVAL_PP(arg1) = value; + len = contentp->read(value, Z_LVAL_PP(arg2)); + value[len] = '\0'; + Z_STRLEN_PP(arg1) = len; + + RETURN_LONG(len); } /* }}} */ diff --git a/ext/hyperwave/hw.c b/ext/hyperwave/hw.c index f893a3336a..e81c1d44e9 100644 --- a/ext/hyperwave/hw.c +++ b/ext/hyperwave/hw.c @@ -255,13 +255,7 @@ int make_return_objrec(pval **return_value, char **objrecs, int count) int hidden, collhead, fullcollhead, total; int collheadnr, fullcollheadnr; - if (array_init(*return_value) == FAILURE) { - /* Ups, failed! Let's at least free the memory */ - for(i=0; i