Index: ext/informix/ifx.ec =================================================================== RCS file: /repository/php-src/ext/informix/ifx.ec,v retrieving revision 1.109.2.7 diff -u -p -d -r1.109.2.7 ifx.ec --- ext/informix/ifx.ec 4 May 2006 22:48:16 -0000 1.109.2.7 +++ ext/informix/ifx.ec 11 May 2006 09:15:35 -0000 @@ -140,6 +140,34 @@ typedef char IFX[128]; } \ } while (0) +#define PHP_IFX_FETCH_BLOB(blob, id, type, error_value) \ + blob = (IFX_IDRES *) zend_list_find(id, &type); \ + if (blob == NULL || type != le_idresult || !(blob->type == TYPE_BLBYTE || blob->type == TYPE_BLTEXT)) { \ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "%ld is not a Informix blob-result index", id); \ + return error_value; \ + } \ + +#define PHP_IFX_FETCH_CLOB(clob, id, type, error_value) \ + clob = (IFX_IDRES *) zend_list_find(id, &type); \ + if (clob == NULL || type != le_idresult || clob->type != TYPE_CHAR) { \ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "%ld is not a Informix char-result index", id); \ + return error_value; \ + } \ + +#define PHP_IFX_FETCH_SLOB(slob, id, type, error_value) \ + slob = (IFX_IDRES *) zend_list_find(id, &type); \ + if (slob == NULL || type != le_idresult || slob->type != TYPE_SLOB) { \ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "%ld is not a Informix slob-result index", id); \ + return error_value; \ + } \ + +#define PHP_IFX_FETCH_SLOB_VOID(slob, id, type) \ + slob = (IFX_IDRES *) zend_list_find(id, &type); \ + if (slob == NULL || type != le_idresult || slob->type != TYPE_SLOB) { \ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "%ld is not a Informix slob-result index", id); \ + return; \ + } \ + zend_function_entry ifx_functions[] = { PHP_FE(ifx_connect, NULL) PHP_FE(ifx_pconnect, NULL) @@ -394,11 +422,8 @@ PHP_INI_END() static void php_ifx_init_globals(zend_ifx_globals *ifx_globals) { - ifx_globals->num_persistent = 0; - ifx_globals->nullvalue[0] = 0; + memset(ifx_globals, 0, sizeof(zend_ifx_globals)); strcpy(ifx_globals->nullstring, "NULL"); - ifx_globals->num_persistent = 0; - ifx_globals->sv_sqlcode = 0; } PHP_MINIT_FUNCTION(ifx) @@ -1880,7 +1905,7 @@ EXEC SQL END DECLARE SECTION; nullstr = php_intifx_null(TSRMLS_C); IFXG(sv_sqlcode) = 0; - if (strcmp(Ifx_Result->cursorid, "") == 0) { + if (Ifx_Result->iscursory != 1) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Not a select cursor!"); RETURN_FALSE; } @@ -2287,7 +2312,7 @@ EXEC SQL END DECLARE SECTION; ZEND_FETCH_RESOURCE(Ifx_Result, IFX_RES *, result, -1, "Informix Result", le_result); - if (strcmp(Ifx_Result->cursorid, "") == 0) { + if (Ifx_Result->iscursory != 1) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Not a select cursor!"); RETURN_FALSE; } @@ -2601,7 +2626,7 @@ EXEC SQL END DECLARE SECTION; ZEND_FETCH_RESOURCE(Ifx_Result, IFX_RES *, result, -1, "Informix Result", le_result); - if (strcmp(Ifx_Result->cursorid, "") == 0) { + if (Ifx_Result->iscursory != 1) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Not a select cursor!"); RETURN_FALSE; } @@ -2760,7 +2785,7 @@ EXEC SQL END DECLARE SECTION; ZEND_FETCH_RESOURCE(Ifx_Result, IFX_RES *, result, -1, "Informix Result", le_result); - if (strcmp(Ifx_Result->cursorid, "") == 0) { + if (Ifx_Result->iscursory != 1) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Not a select cursor!"); RETURN_FALSE; } @@ -3050,7 +3075,7 @@ static long php_intifx_getType(long id, int type; Ifx_res = (IFX_IDRES *) zend_list_find(id, &type); - if (type != le_idresult) { + if (Ifx_res == NULL || type != le_idresult) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "%ld is not a Informix id-result index", id); return -1; } @@ -3137,7 +3162,9 @@ static long php_intifx_create_blob(long } Ifx_blob->BLOB.mode = (int) mode; - if (php_intifx_init_blob(&Ifx_blob->BLOB.blob_data, mode, 1 TSRMLS_CC) < 0) { + if (php_intifx_init_blob(&Ifx_blob->BLOB.blob_data, mode, 1 TSRMLS_CC) < 0) { + php_intifx_release_blob(&Ifx_blob->BLOB.blob_data TSRMLS_CC); + efree(Ifx_blob); php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can't create blob-resource"); return -1; } @@ -3146,6 +3173,8 @@ static long php_intifx_create_blob(long if (len >= 0) { char *content = emalloc(len); if (content == NULL) { + php_intifx_release_blob(&Ifx_blob->BLOB.blob_data TSRMLS_CC); + efree(Ifx_blob); php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can't create blob-resource"); return -1; } @@ -3167,6 +3196,8 @@ static long php_intifx_create_blob(long */ if (Ifx_blob->BLOB.blob_data.loc_fname != NULL) { if (php_copy_file(param, Ifx_blob->BLOB.blob_data.loc_fname TSRMLS_CC) == FAILURE) { + php_intifx_release_blob(&Ifx_blob->BLOB.blob_data TSRMLS_CC); + efree(Ifx_blob); php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not create blob-resource file. File copy failed: %s", param); return -1; } @@ -3331,11 +3362,7 @@ static long php_intifx_copy_blob(long bi loc_t *locator, *locator_orig; int type; - Ifx_blob_orig = (IFX_IDRES *) zend_list_find(bid, &type); - if (type != le_idresult || !(Ifx_blob_orig->type == TYPE_BLBYTE || Ifx_blob_orig->type == TYPE_BLTEXT)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%ld is not a Informix blob-result index", bid); - return -1; - } + PHP_IFX_FETCH_BLOB(Ifx_blob_orig, bid, type, -1); Ifx_blob = emalloc(sizeof(IFX_IDRES)); if (Ifx_blob == NULL) { @@ -3425,16 +3452,7 @@ static long php_intifx_free_blob(long bi IFX_IDRES *Ifx_blob; int type; - Ifx_blob = (IFX_IDRES *) zend_list_find(bid, &type); - if (type != le_idresult && !(Ifx_blob->type == TYPE_BLTEXT || Ifx_blob->type == TYPE_BLBYTE)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%ld is not a Informix blob-result index", bid); - return -1; - } - - if (!(Ifx_blob->type == TYPE_BLTEXT || Ifx_blob->type == TYPE_BLBYTE)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%ld is not a Informix BYTE or TEXT type", bid); - return -1; - } + PHP_IFX_FETCH_BLOB(Ifx_blob, bid, type, -1); zend_list_delete(bid); @@ -3488,11 +3506,7 @@ static long php_intifx_get_blob(long bid IFX_IDRES *Ifx_blob; int type; - Ifx_blob = (IFX_IDRES *) zend_list_find(bid, &type); - if (type != le_idresult && !(Ifx_blob->type == TYPE_BLTEXT || Ifx_blob->type == TYPE_BLBYTE)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%ld is not a Informix blob-result index", bid); - return -1; - } + PHP_IFX_FETCH_BLOB(Ifx_blob, bid, type, -1); if (Ifx_blob->BLOB.mode == BLMODE_INMEM) { *content = Ifx_blob->BLOB.blob_data.loc_buffer; @@ -3517,11 +3531,7 @@ static loc_t *php_intifx_get_blobloc(lon IFX_IDRES *Ifx_blob; int type; - Ifx_blob = (IFX_IDRES *) zend_list_find(bid, &type); - if (type != le_idresult && !(Ifx_blob->type == TYPE_BLTEXT || Ifx_blob->type == TYPE_BLBYTE)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%ld is not a Informix blob-result index", bid); - return NULL; - } + PHP_IFX_FETCH_BLOB(Ifx_blob, bid, type, NULL); return &(Ifx_blob->BLOB.blob_data); } @@ -3572,11 +3582,7 @@ static long php_intifx_update_blob(long IFX_IDRES *Ifx_blob; int type; - Ifx_blob = (IFX_IDRES *) zend_list_find(bid, &type); - if (type != le_idresult && !(Ifx_blob->type == TYPE_BLTEXT || Ifx_blob->type == TYPE_BLBYTE)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%ld is not a Informix blob-result index", bid); - return -1; - } + PHP_IFX_FETCH_BLOB(Ifx_blob, bid, type, -1); if (Ifx_blob->BLOB.mode == BLMODE_INMEM) { char *content; @@ -4019,11 +4025,7 @@ static long php_intifx_get_char(long bid IFX_IDRES *Ifx_char; int type; - Ifx_char = (IFX_IDRES *) zend_list_find(bid, &type); - if (type != le_idresult && !(Ifx_char->type == TYPE_CHAR)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%ld is not a Informix char-result index", bid); - return -1; - } + PHP_IFX_FETCH_CLOB(Ifx_char, bid, type, -1); *content = Ifx_char->CHAR.char_data; return Ifx_char->CHAR.len; @@ -4072,11 +4074,7 @@ static long php_intifx_free_char(long bi IFX_IDRES *Ifx_char; int type; - Ifx_char = (IFX_IDRES *) zend_list_find(bid, &type); - if (type != le_idresult && !(Ifx_char->type == TYPE_CHAR)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%ld is not a Informix char-result index", bid); - return -1; - } + PHP_IFX_FETCH_CLOB(Ifx_char, bid, type, -1); if (Ifx_char->CHAR.char_data != NULL) { efree(Ifx_char->CHAR.char_data); @@ -4132,11 +4130,7 @@ static long php_intifx_update_char(long IFX_IDRES *Ifx_char; int type; - Ifx_char = (IFX_IDRES *) zend_list_find(bid, &type); - if (type != le_idresult && !(Ifx_char->type == TYPE_CHAR)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%ld is not a Informix char-result index", bid); - return -1; - } + PHP_IFX_FETCH_CLOB(Ifx_char, bid, type, -1); if (Ifx_char->CHAR.char_data != NULL) { efree(Ifx_char->CHAR.char_data); @@ -4295,11 +4289,7 @@ static long php_intifxus_free_slob(long IFX_IDRES *Ifx_slob; int type; - Ifx_slob = (IFX_IDRES *) zend_list_find(bid, &type); - if (type != le_idresult || Ifx_slob->type != TYPE_SLOB) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%d is not a Informix slob-result index", bid); - return -1; - } + PHP_IFX_FETCH_SLOB(Ifx_slob, bid, type, -1); if (php_intifxus_close_slob(bid, &EG(regular_list) TSRMLS_CC) < 0) { return -1; @@ -4357,11 +4347,7 @@ static long php_intifxus_close_slob(long IFX_IDRES *Ifx_slob; int type; - Ifx_slob = (IFX_IDRES *) zend_list_find(bid, &type); - if (type != le_idresult || Ifx_slob->type != TYPE_SLOB) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%d is not a Informix slob-result index", bid); - return -1; - } + PHP_IFX_FETCH_SLOB(Ifx_slob, bid, type, -1); if (Ifx_slob->SLOB.lofd < 0) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Slob-resource already closed"); @@ -4441,11 +4427,7 @@ static long php_intifxus_open_slob(long int errcode; int type; - Ifx_slob = (IFX_IDRES *) zend_list_find(bid, &type); - if (type != le_idresult || Ifx_slob->type != TYPE_SLOB) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%d is not a Informix slob-result index", bid); - return -1; - } + PHP_IFX_FETCH_SLOB(Ifx_slob, bid, type, -1); if (Ifx_slob->SLOB.lofd > 0) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Slob-resource already open"); @@ -4500,11 +4482,8 @@ static ifx_lo_t *php_intifxus_get_sloblo IFX_IDRES *Ifx_slob; int type; - Ifx_slob = (IFX_IDRES *) zend_list_find(bid, &type); - if (type != le_idresult || Ifx_slob->type != TYPE_SLOB) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%d is not a Informix slob-result index", bid); - return NULL; - } + PHP_IFX_FETCH_SLOB(Ifx_slob, bid, type, NULL); + return &(Ifx_slob->SLOB.slob_data); } @@ -4534,11 +4513,8 @@ PHP_FUNCTION(ifxus_tell_slob) convert_to_long_ex(pbid); bid = Z_LVAL_PP(pbid); - Ifx_slob = (IFX_IDRES *) zend_list_find(bid, &type); - if (type != le_idresult || Ifx_slob->type != TYPE_SLOB) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%d is not a Informix slob-result index", bid); - RETURN_FALSE; - } + RETVAL_FALSE; + PHP_IFX_FETCH_SLOB_VOID(Ifx_slob, bid, type); if (ifx_lo_tell(Ifx_slob->SLOB.lofd, &akt_seek_pos) < 0) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can't perform tell-operation"); @@ -4581,12 +4557,10 @@ PHP_FUNCTION(ifxus_seek_slob) convert_to_long_ex(pmode); convert_to_long_ex(poffset); + RETVAL_FALSE; + bid = Z_LVAL_PP(pbid); - Ifx_slob = (IFX_IDRES *) zend_list_find(bid, &type); - if (type != le_idresult || Ifx_slob->type != TYPE_SLOB) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%d is not a Informix slob-result index", bid); - RETURN_FALSE; - } + PHP_IFX_FETCH_SLOB_VOID(Ifx_slob, bid, type); mode = LO_SEEK_SET; if (Z_LVAL_PP(pmode) == 1) { @@ -4635,13 +4609,11 @@ PHP_FUNCTION(ifxus_read_slob) } convert_to_long_ex(pbid); convert_to_long_ex(pnbytes); - + + RETVAL_FALSE; + bid = Z_LVAL_PP(pbid); - Ifx_slob = (IFX_IDRES *) zend_list_find(bid, &type); - if (type != le_idresult || Ifx_slob->type != TYPE_SLOB) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%d is not a Informix slob-result index", bid); - RETURN_FALSE; - } + PHP_IFX_FETCH_SLOB_VOID(Ifx_slob, bid, type); nbytes = Z_LVAL_PP(pnbytes); buffer = emalloc(nbytes); @@ -4680,13 +4652,11 @@ PHP_FUNCTION(ifxus_write_slob) } convert_to_long_ex(pbid); convert_to_string_ex(pcontent); - + + RETVAL_FALSE; + bid = Z_LVAL_PP(pbid); - Ifx_slob = (IFX_IDRES *) zend_list_find(bid, &type); - if (type != le_idresult || Ifx_slob->type != TYPE_SLOB) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%d is not a Informix slob-result index", bid); - RETURN_FALSE; - } + PHP_IFX_FETCH_SLOB_VOID(Ifx_slob, bid, type); buffer = Z_STRVAL_PP(pcontent); nbytes = Z_STRLEN_PP(pcontent);