CVS update: php3/functions
| From: | nyenyon | Date: | Tue, 15 Sep 1998 21:46:56 +0000 |
| Subject: | CVS update: php3/functions | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-1136@lists.php.net to get a copy of this message | ||
Date: Tuesday September 15, 1998 @ 17:46
Author: nyenyon
Update of /repository/php3/functions
In directory asf:/u2/tmp/cvs-serv8524
Modified Files:
ifx.ec php3_ifx.h
Log Message:
a very tricky bug during ifx_free_result, which caused a seg-fault, is now fixed
Index: php3/functions/ifx.ec
diff -c php3/functions/ifx.ec:1.17 php3/functions/ifx.ec:1.18
*** php3/functions/ifx.ec:1.17 Mon Sep 14 18:19:46 1998
--- php3/functions/ifx.ec Tue Sep 15 17:46:55 1998
***************
*** 1940,1946 ****
*p = 0;
if (indicator == -1) { /* NULL */
! if(fieldtype==SQLTEXT || fieldtype==SQLBYTES) {
char *nullstr;
nullstr=php3_intifx_null();
--- 1940,1946 ----
*p = 0;
if (indicator == -1) { /* NULL */
! if((Informix_GLOBAL(php3_ifx_module).textasvarchar==0 && fieldtype==SQLTEXT) ||
(Informix_GLOBAL(php3_ifx_module).byteasvarchar==0 && fieldtype==SQLBYTES)) {
char *nullstr;
nullstr=php3_intifx_null();
***************
*** 1952,1957 ****
--- 1952,1960 ----
++locind;
continue;
}
+ if(fieldtype==SQLTEXT || fieldtype==SQLBYTES) {
+ ++locind;
+ }
add_assoc_string(return_value, fieldname, php3_intifx_null(), 0);
continue;
}
***************
*** 2032,2037 ****
--- 2035,2041 ----
case SQLTEXT :
bid_b=Ifx_Result->blob_id[locind];
locator_b=php3_intifx_get_blobloc(bid_b,list);
+ ++locind;
EXEC SQL GET DESCRIPTOR :descrpid VALUE :i :*locator_b = DATA;
if (locator_b->loc_status < 0) { /* blob too large */
***************
*** 2040,2073 ****
RETURN_FALSE;
}
- bid=php3_intifx_copy_blob(bid_b, list);
if(locator_b->loc_indicator==-1) {
char *nullstr;
!
nullstr=php3_intifx_null();
php3_intifx_update_blob(bid,nullstr,strlen(nullstr),list);
add_assoc_long(return_value,fieldname,bid);
efree(nullstr);
! ++locind;
! break;
! }
! if(locator_b->loc_loctype==LOCFNAME) {
! blobfilename=php3_intifx_create_tmpfile(bid_b);
! php3_intifx_update_blob(bid_b,blobfilename,strlen(blobfilename),list);
! efree(blobfilename);
! EXEC SQL SET DESCRIPTOR :descrpid VALUE :i DATA= :*locator_b;
! }
! ++locind;
! if((Informix_GLOBAL(php3_ifx_module).textasvarchar!=0 && fieldtype==SQLTEXT) ||
(Informix_GLOBAL(php3_ifx_module).byteasvarchar!=0 && fieldtype==SQLBYTES)) {
char *content;
long lg;
lg=php3_intifx_get_blob(bid, list, &content);
if(content==NULL || lg<0) {
! add_assoc_string(return_value,fieldname,php3_intifx_null(),DUP);
} else {
add_assoc_stringl(return_value,fieldname,content,lg,DUP);
}
--- 2044,2081 ----
RETURN_FALSE;
}
if(locator_b->loc_indicator==-1) {
+ if((Informix_GLOBAL(php3_ifx_module).textasvarchar!=0 && fieldtype==SQLTEXT) ||
(Informix_GLOBAL(php3_ifx_module).byteasvarchar!=0 && fieldtype==SQLBYTES)) {
+ add_assoc_string(return_value, fieldname, php3_intifx_null(), 0);
+ } else {
char *nullstr;
!
! bid=php3_intifx_copy_blob(bid_b, list);
nullstr=php3_intifx_null();
php3_intifx_update_blob(bid,nullstr,strlen(nullstr),list);
add_assoc_long(return_value,fieldname,bid);
efree(nullstr);
! }
! break;
! }
!
! bid=php3_intifx_copy_blob(bid_b, list);
! if(locator_b->loc_loctype==LOCFNAME) {
! blobfilename=php3_intifx_create_tmpfile(bid_b);
! php3_intifx_update_blob(bid_b,blobfilename,strlen(blobfilename),list);
! efree(blobfilename);
! EXEC SQL SET DESCRIPTOR :descrpid VALUE :i DATA= :*locator_b;
! }
! if((Informix_GLOBAL(php3_ifx_module).textasvarchar!=0 && fieldtype==SQLTEXT)
|| (Informix_GLOBAL(php3_ifx_module).byteasvarchar!=0 && fieldtype==SQLBYTES)) {
char *content;
long lg;
lg=php3_intifx_get_blob(bid, list, &content);
if(content==NULL || lg<0) {
! add_assoc_string(return_value,fieldname,php3_intifx_null(),0);
} else {
add_assoc_stringl(return_value,fieldname,content,lg,DUP);
}
***************
*** 2926,2931 ****
--- 2934,2940 ----
Informix_TLS_VARS;
+
if (ARG_COUNT(ht)!=1 || getParameters(ht, 1, &result)==FAILURE) {
WRONG_PARAM_COUNT;
}
***************
*** 2945,2974 ****
Informix_GLOBAL(php3_ifx_module).sv_sqlcode = 0;
! cursorid = Ifx_Result->cursorid;
! statemid = Ifx_Result->statemid;
! descrpid = Ifx_Result->descrpid;
!
! EXEC SQL free :statemid;
! if (strlen(cursorid) != 0) {
! EXEC SQL CLOSE :cursorid;
! EXEC SQL FREE :cursorid;
! }
!
for (i = 0; i < MAXBLOBS; ++i) {
if (Ifx_Result->blob_id[i]>0) {
! php3_intifx_free_blob(Ifx_Result->blob_id[i],list);
Ifx_Result->blob_id[i]=-1;
}
}
#if HAVE_IFX_IUS
for (i = 0; i < MAXSLOBS; ++i) {
if (Ifx_Result->slob_id[i]>0) {
! /* php3_intifxus_free_slob(Ifx_Result->slob_id[i],list);
! Ifx_Result->slob_id[i]=-1; */
}
}
#endif
EXEC SQL DEALLOCATE DESCRIPTOR :descrpid;
--- 2954,2985 ----
Informix_GLOBAL(php3_ifx_module).sv_sqlcode = 0;
!
for (i = 0; i < MAXBLOBS; ++i) {
if (Ifx_Result->blob_id[i]>0) {
! php3_intifx2_free_blob(Ifx_Result->blob_id[i],list);
Ifx_Result->blob_id[i]=-1;
}
}
#if HAVE_IFX_IUS
for (i = 0; i < MAXSLOBS; ++i) {
if (Ifx_Result->slob_id[i]>0) {
! php3_intifxus_free_slob(Ifx_Result->slob_id[i],list);
! Ifx_Result->slob_id[i]=-1;
}
}
#endif
+
+ cursorid = Ifx_Result->cursorid;
+ statemid = Ifx_Result->statemid;
+ descrpid = Ifx_Result->descrpid;
+
+ EXEC SQL free :statemid;
+ if (strlen(cursorid) != 0) {
+ EXEC SQL CLOSE :cursorid;
+ EXEC SQL FREE :cursorid;
+ }
+
EXEC SQL DEALLOCATE DESCRIPTOR :descrpid;
***************
*** 3050,3056 ****
php3_error(E_WARNING,"can't create blob-resource");
return -1;
}
! memcpy(content,param, len);
Ifx_blob->blob_data.loc_loctype=LOCMEMORY;
Ifx_blob->blob_data.loc_buffer=content;
Ifx_blob->blob_data.loc_bufsize=len;
--- 3061,3067 ----
php3_error(E_WARNING,"can't create blob-resource");
return -1;
}
! memcpy(content,param,len);
Ifx_blob->blob_data.loc_loctype=LOCMEMORY;
Ifx_blob->blob_data.loc_buffer=content;
Ifx_blob->blob_data.loc_bufsize=len;
***************
*** 3071,3077 ****
php3_error(E_WARNING,"can't create blob-resource");
return -1;
}
! memcpy(filename,param, len);
filename[len]=0;
Ifx_blob->blob_data.loc_loctype=LOCFNAME;
Ifx_blob->blob_data.loc_fname=filename;
--- 3082,3088 ----
php3_error(E_WARNING,"can't create blob-resource");
return -1;
}
! memcpy(filename,param,len);
filename[len]=0;
Ifx_blob->blob_data.loc_loctype=LOCFNAME;
Ifx_blob->blob_data.loc_fname=filename;
***************
*** 3217,3222 ****
--- 3228,3234 ----
** list: internal hashlist of php3
**
** return -1 on error otherwise 0
+ ** FREES BYTE-MEMORY WITH EFREE()
** ----------------------------------------------------------------------
*/
long php3_intifx_free_blob(long bid, HashTable *list) {
***************
*** 3229,3247 ****
bid);
return -1;
}
! if(Ifx_blob->mode==0)
! if(Ifx_blob->blob_data.loc_buffer!=NULL)
! efree(Ifx_blob->blob_data.loc_buffer);
! else
! if(Ifx_blob->blob_data.loc_fname!=NULL)
! efree(Ifx_blob->blob_data.loc_fname);
php3_list_delete(bid);
! efree(Ifx_blob);
return 0;
}
/* ----------------------------------------------------------------------
** string php3_ifx_get_blob(int bid)
**
** returns the content of the blob-object
--- 3241,3301 ----
bid);
return -1;
}
! if(Ifx_blob->mode==0) {
! if(Ifx_blob->blob_data.loc_buffer==NULL || Ifx_blob->blob_data.loc_size<=0 ||
Ifx_blob->blob_data.loc_indicator==-1) {} else {
! efree(Ifx_blob->blob_data.loc_buffer);
! }
! } else {
! if(Ifx_blob->blob_data.loc_fname!=NULL) {
! efree(Ifx_blob->blob_data.loc_fname);
! }
! }
!
!
php3_list_delete(bid);
! efree(Ifx_blob);
return 0;
}
+
/* ----------------------------------------------------------------------
+ ** internal function
+ ** long php3_intifx2_free_blob(long bid, HashTable *list)
+ **
+ ** deletes the blob-object
+ ** bid: Id of Blobobject
+ ** list: internal hashlist of php3
+ **
+ ** return -1 on error otherwise 0
+ ** FREES BYTE-MEMORY WITH FREE(), use this for freeing blob-source after select (in
ifx_free_result)
+ ** ----------------------------------------------------------------------
+ */long php3_intifx2_free_blob(long bid, HashTable *list) {
+ IFX_BLOBRES *Ifx_blob;
+ int type;
+
+ Ifx_blob = (IFX_BLOBRES *) php3_list_find(bid,&type);
+ if (type!=Informix_GLOBAL(php3_ifx_module).le_blobresult) {
+ php3_error(E_WARNING,"%d is not a Informix blob-result index",
+ bid);
+ return -1;
+ }
+ if(Ifx_blob->mode==0) {
+ if(Ifx_blob->blob_data.loc_buffer==NULL || Ifx_blob->blob_data.loc_size<=0 ||
Ifx_blob->blob_data.loc_indicator==-1) {} else {
+ free(Ifx_blob->blob_data.loc_buffer);
+ }
+ } else {
+ if(Ifx_blob->blob_data.loc_fname!=NULL) {
+ efree(Ifx_blob->blob_data.loc_fname);
+ }
+ }
+
+ php3_list_delete(bid);
+ efree(Ifx_blob);
+ return 0;
+ }
+
+ /* ----------------------------------------------------------------------
** string php3_ifx_get_blob(int bid)
**
** returns the content of the blob-object
***************
*** 3261,3270 ****
convert_to_long(pbid);
len=php3_intifx_get_blob(pbid->value.lval,list,&content);
! if(len<0) {
! RETURN_FALSE;
! }
! if(content==NULL) {
RETURN_STRING(php3_intifx_null(),1);
}
RETURN_STRINGL(content,len,1);
--- 3315,3321 ----
convert_to_long(pbid);
len=php3_intifx_get_blob(pbid->value.lval,list,&content);
! if(content==NULL || len<0) {
RETURN_STRING(php3_intifx_null(),1);
}
RETURN_STRINGL(content,len,1);
***************
*** 3426,3431 ****
--- 3477,3483 ----
char filename[10];
char *blobdir;
char *blobfile;
+ char *retval;
if ((blobdir = getenv("php3_blobdir")) == NULL)
blobdir=".";
***************
*** 3433,3439 ****
sprintf(filename,"blb%d",bid);
blobfile=tempnam(blobdir,filename);
free(blobdir);
! return blobfile;
}
--- 3485,3496 ----
sprintf(filename,"blb%d",bid);
blobfile=tempnam(blobdir,filename);
free(blobdir);
! retval=emalloc(strlen(blobfile)+1);
! if(retval==NULL)
! return NULL;
! strcpy(retval,blobfile);
! free(blobfile);
! return retval;
}
Index: php3/functions/php3_ifx.h
diff -c php3/functions/php3_ifx.h:1.9 php3/functions/php3_ifx.h:1.10
*** php3/functions/php3_ifx.h:1.9 Mon Sep 14 18:19:48 1998
--- php3/functions/php3_ifx.h Tue Sep 15 17:46:55 1998
***************
*** 77,82 ****
--- 77,85 ----
long php3_intifx_create_blob(long type, long mode, char* param, long len, HashTable *list);
extern void php3_ifx_free_blob(INTERNAL_FUNCTION_PARAMETERS) ;
long php3_intifx_free_blob(long id, HashTable *list);
+
+ long php3_intifx2_free_blob(long id, HashTable *list);
+
extern void php3_ifx_get_blob(INTERNAL_FUNCTION_PARAMETERS);
long php3_intifx_get_blob(long bid, HashTable *list, char** content);
extern void php3_ifx_update_blob(INTERNAL_FUNCTION_PARAMETERS);
--
PHP Development Mailing List http://www.php.net/
To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net
For help: php-dev-help@lists.php.net