cvs: /php3/functions interbase.c /php3/dl Makefile.tmpl

From: Date: Sun, 10 Oct 1999 14:49:12 +0000
Subject: cvs: /php3/functions interbase.c /php3/dl Makefile.tmpl
Groups: php.dev 
Request: Send a blank email to php-dev+get-11668@lists.php.net to get a copy of this message
andrew Sun Oct 10 10:49:12 1999 EDT Modified files: /php3/functions interbase.c /php3/dl Makefile.tmpl Log: Dynamic loading patch from Ivo Panacek <ivop@regionet.cz> Index: php3/functions/interbase.c diff -u php3/functions/interbase.c:1.18 php3/functions/interbase.c:1.19 --- php3/functions/interbase.c:1.18 Wed Aug 18 14:11:03 1999 +++ php3/functions/interbase.c Sun Oct 10 10:49:10 1999 @@ -1,43 +1,63 @@ /* +----------------------------------------------------------------------+ - | PHP HTML Embedded Scripting Language Version 3.0 | + | PHP HTML Embedded Scripting Language Version 3.0 | +----------------------------------------------------------------------+ | Copyright (c) 1997-1999 PHP Development Team (See Credits file) | +----------------------------------------------------------------------+ | This program is free software; you can redistribute it and/or modify | - | it under the terms of one of the following licenses: | - | | + | it under the terms of one of the following licenses: | + | | | A) the GNU General Public License as published by the Free Software | | Foundation; either version 2 of the License, or (at your option) | - | any later version. | - | | + | any later version. | + | | | B) the PHP License as published by the PHP Development Team and | - | included in the distribution in the file: LICENSE | - | | + | included in the distribution in the file: LICENSE | + | | | This program is distributed in the hope that it will be useful, | - | but WITHOUT ANY WARRANTY; without even the implied warranty of | - | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | - | GNU General Public License for more details. | - | | + | but WITHOUT ANY WARRANTY; without even the implied warranty of | + | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | + | GNU General Public License for more details. | + | | | You should have received a copy of both licenses referred to here. | | If you did not, or have any questions about PHP licensing, please | - | contact core@php.net. | + | contact core@php.net. | +----------------------------------------------------------------------+ - | Authors: Jouni Ahto <jah@mork.net> | - | Andrew Avdeev <andy@simgts.mv.ru> | + | Authors: Jouni Ahto <jah@mork.net> | + | Andrew Avdeev <andy@rsc.mv.ru> | +----------------------------------------------------------------------+ */ -/* $Id: interbase.c,v 1.18 1999/08/18 18:11:03 rasmus Exp $ */ +/* $Id: interbase.c,v 1.19 1999/10/10 14:49:10 andrew Exp $ */ /* TODO: Arrays, roles? A lot... */ +/* + Changes: + 1999-09-21: Ivo Panacek <ivop@regionet.cz> + - added COMPILE_DL section + - more verbose php3_info_ibase function + mostly stolen from pgsql.c for now + 1999-10-05: Ivo Panacek <ivop@regionet.cz> + - safe rinit/rfinish: check for NULL so + rfinish could be called repeatedly + emalloc & co. replaced with malloc & co. +*/ + #include "config.h" #include "php.h" #include "internal_functions.h" #include "php3_interbase.h" +#if COMPILE_DL +# if PHP_31 +# include "../phpdl.h" +# else +# include "dl/phpdl.h" +# endif +#endif + #if HAVE_IBASE #include <ibase.h> #include <time.h> @@ -93,6 +113,24 @@ php3_info_ibase, STANDARD_MODULE_PROPERTIES }; + +#if defined(COMPILE_DL) + +php3_module_entry *get_module() { return &ibase_module_entry; } + +#define DL_MALLOC(size) malloc(size) +#define DL_STRDUP(str) strdup(str) +#define DL_FREE(ptr) free(ptr) + +#else + +#define DL_MALLOC(size) emalloc(size) +#define DL_STRDUP(str) estrdup(str) +#define DL_FREE(ptr) efree(ptr) + +#endif + + /* }}} */ @@ -426,7 +464,11 @@ if (cfg_get_string("ibase.timeformat", &IBASE_GLOBAL(php3_ibase_module).timeformat) == FAILURE) { IBASE_GLOBAL(php3_ibase_module).cfg_timeformat = "%m/%d/%Y %H:%M:%S"; } - IBASE_GLOBAL(php3_ibase_module).num_persistent=0; + + IBASE_GLOBAL(php3_ibase_module).timeformat = NULL; + IBASE_GLOBAL(php3_ibase_module).errmsg = NULL; + + IBASE_GLOBAL(php3_ibase_module).num_persistent = 0; IBASE_GLOBAL(php3_ibase_module).le_result = register_list_destructors(_php3_ibase_free_result, NULL); IBASE_GLOBAL(php3_ibase_module).le_query = register_list_destructors(_php3_ibase_free_query, NULL); IBASE_GLOBAL(php3_ibase_module).le_blob = register_list_destructors(_php3_ibase_free_blob, NULL); @@ -444,14 +486,22 @@ return SUCCESS; } + int php3_rinit_ibase(INIT_FUNC_ARGS) { IBASE_TLS_VARS; + + IBASE_GLOBAL(php3_ibase_module).default_link= -1; + IBASE_GLOBAL(php3_ibase_module).num_links = IBASE_GLOBAL(php3_ibase_module).num_persistent; - IBASE_GLOBAL(php3_ibase_module).default_link= -1; - IBASE_GLOBAL(php3_ibase_module).num_links = php3_ibase_module.num_persistent; - IBASE_GLOBAL(php3_ibase_module).timeformat = estrndup(IBASE_GLOBAL(php3_ibase_module).cfg_timeformat, strlen(IBASE_GLOBAL(php3_ibase_module).cfg_timeformat)); - IBASE_GLOBAL(php3_ibase_module).errmsg = emalloc(sizeof(char)*MAX_ERRMSG); + if(IBASE_GLOBAL(php3_ibase_module).timeformat) + DL_FREE(IBASE_GLOBAL(php3_ibase_module).timeformat); + IBASE_GLOBAL(php3_ibase_module).timeformat = DL_STRDUP(IBASE_GLOBAL(php3_ibase_module).cfg_timeformat); + + if(IBASE_GLOBAL(php3_ibase_module).errmsg) + DL_FREE(IBASE_GLOBAL(php3_ibase_module).errmsg); + IBASE_GLOBAL(php3_ibase_module).errmsg = DL_MALLOC(sizeof(char)*MAX_ERRMSG+1); + return SUCCESS; } @@ -464,17 +514,51 @@ int php3_rfinish_ibase(void) { - IBASE_TLS_VARS; + IBASE_TLS_VARS; - efree(IBASE_GLOBAL(php3_ibase_module).timeformat); - efree(IBASE_GLOBAL(php3_ibase_module).errmsg); - return SUCCESS; -} + if(IBASE_GLOBAL(php3_ibase_module).timeformat) + DL_FREE(IBASE_GLOBAL(php3_ibase_module).timeformat); + IBASE_GLOBAL(php3_ibase_module).timeformat = NULL; + + if(IBASE_GLOBAL(php3_ibase_module).errmsg) + DL_FREE(IBASE_GLOBAL(php3_ibase_module).errmsg); + IBASE_GLOBAL(php3_ibase_module).errmsg = NULL; + return SUCCESS; +} + void php3_info_ibase(void) { - php3_printf("$Revision: 1.18 $"); + IBASE_TLS_VARS; + + php3_printf( + "<table>" + "<tr><td>Revision:</td><td>$Revision: 1.19 $</td></tr>\n" +#ifdef COMPILE_DL + "<tr><td>Dynamic module:</td><td>Yes</td></tr>\n" +#endif + "<tr><td>Allow persistent links:</td><td>%s</td></tr>\n" + "<tr><td>Persistent links:</td><td>%d/", + (IBASE_GLOBAL(php3_ibase_module).allow_persistent?"Yes":"No"), + IBASE_GLOBAL(php3_ibase_module).num_persistent); + if (IBASE_GLOBAL(php3_ibase_module).max_persistent == -1) { + php3_printf("Unlimited"); + } else { + php3_printf("%ld",IBASE_GLOBAL(php3_ibase_module).max_persistent); + } + php3_printf("</td></tr>\n" + "<tr><td>Total links:</td><td>%d/", + IBASE_GLOBAL(php3_ibase_module).num_links); + if (IBASE_GLOBAL(php3_ibase_module).max_links == -1) { + php3_printf("Unlimited"); + } else { + php3_printf("%ld",IBASE_GLOBAL(php3_ibase_module).max_links); + } + php3_printf("</td></tr>\n" + "<tr><td>Time format:</td><td>\"%s\"</td></tr>\n" + "</table>\n", + IBASE_GLOBAL(php3_ibase_module).timeformat); } /* }}} */ @@ -544,7 +628,7 @@ static void _php3_ibase_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) { pval **args; - char *ib_server, *ib_uname, *ib_passwd, *ib_charset = NULL; + char *ib_server = NULL, *ib_uname, *ib_passwd, *ib_charset = NULL; int i, ib_uname_len, ib_passwd_len; isc_db_handle db_handle = NULL; char *hashed_details; @@ -626,7 +710,7 @@ ib_link->trans[i] = NULL; /* hash it up */ - new_le.type = php3_ibase_module.le_plink; + new_le.type = IBASE_GLOBAL(php3_ibase_module).le_plink; new_le.ptr = ib_link; if (_php3_hash_update(plist, hashed_details, hashed_details_length+1, (void *) &new_le, sizeof(list_entry), NULL)==FAILURE) { efree(hashed_details); @@ -657,7 +741,7 @@ int type,xlink; void *ptr; - if (index_ptr->type != le_index_ptr) { + if (index_ptr->type != _php3_le_index_ptr()) { RETURN_FALSE; } xlink = (int) index_ptr->ptr; @@ -695,7 +779,7 @@ /* add it to the hash */ new_index_ptr.ptr = (void *) return_value->value.lval; - new_index_ptr.type = le_index_ptr; + new_index_ptr.type = _php3_le_index_ptr(); if (_php3_hash_update(list,hashed_details,hashed_details_length+1,(void *) &new_index_ptr, sizeof(list_entry), NULL)==FAILURE) { efree(hashed_details); RETURN_FALSE; @@ -1423,7 +1507,7 @@ ib_result->drop_stmt = 1; /* drop stmt when free result */ ib_query->stmt = NULL; /* keep stmt when free query */ _php3_ibase_free_query(ib_query); - RETURN_LONG(php3_list_insert(ib_result, php3_ibase_module.le_result)); + RETURN_LONG(php3_list_insert(ib_result, IBASE_GLOBAL(php3_ibase_module).le_result)); }else{ _php3_ibase_free_query(ib_query); RETURN_TRUE; @@ -1445,12 +1529,12 @@ /* fallout */ case SQL_TEXT: val->value.str.val = (char *)emalloc(sizeof(char)*(len+1)); - strncpy(val->value.str.val, data, len); + strncpy(val->value.str.val, data, len); if (php3_ini.magic_quotes_runtime) { char *tmp = val->value.str.val; val->value.str.val = _php3_addslashes(val->value.str.val, len, &len, 0); efree(tmp); - } + } val->type = IS_STRING; val->value.str.len = len; break; @@ -1496,7 +1580,6 @@ #if HAVE_TM_ZONE t.tm_zone = tzname[0]; #endif - if(flag & PHP3_IBASE_TIMESTAMP){ val->type = IS_LONG; val->value.lval = timestamp; @@ -1888,7 +1971,7 @@ efree(args); if (ib_result) { /* select statement */ - RETURN_LONG(php3_list_insert(ib_result, php3_ibase_module.le_result)); + RETURN_LONG(php3_list_insert(ib_result, IBASE_GLOBAL(php3_ibase_module).le_result)); } RETURN_TRUE; @@ -1935,9 +2018,12 @@ if (ARG_COUNT(ht)!=1 || getParameters(ht, 1, &fmt)==FAILURE) { WRONG_PARAM_COUNT; } - convert_to_string(fmt); - efree(IBASE_GLOBAL(php3_ibase_module).timeformat); - IBASE_GLOBAL(php3_ibase_module).timeformat = estrdup(fmt->value.str.val); + convert_to_string(fmt); + + if(IBASE_GLOBAL(php3_ibase_module).timeformat) + DL_FREE(IBASE_GLOBAL(php3_ibase_module).timeformat); + IBASE_GLOBAL(php3_ibase_module).timeformat = DL_STRDUP(fmt->value.str.val); + RETURN_TRUE; #else _php3_ibase_module_error("ibase_timefmt not supported on this platform"); @@ -2463,9 +2549,12 @@ /* from file.c. I'm not sure, this variables always initialized? */ +#ifndef THREAD_SAFE extern int le_fp,le_pp; -extern int wsa_fp; +extern int wsa_fp; /*to handle reading and writing to windows sockets*/ +#endif + /* {{{ proto string ibase_blob_import([link_identifier, ] file_id) Create blob, copy file in it, and close it*/ PHP_FUNCTION(ibase_blob_import) @@ -2510,16 +2599,18 @@ convert_to_long(file_arg); file_id = file_arg->value.lval; - fp = php3_list_find(file_id, &type); - if (type == GLOBAL(wsa_fp)){ + fp = php3_list_find(file_id, &type); + if (type == wsa_fp){ issock = 1; sock = php3_list_find(file_id, &type); socketd =* sock; - } - if ((!fp || (type!=GLOBAL(le_fp) && type!=GLOBAL(le_pp))) && (!socketd || type!=GLOBAL(wsa_fp))) { - _php3_ibase_module_error("Unable to find file identifier %d",file_id); - RETURN_FALSE; - } + } + + if ((!fp || (type!= le_fp) && type!=le_pp + && (!socketd || type != wsa_fp))) { + _php3_ibase_module_error("Unable to find file identifier %d",file_id); + RETURN_FALSE; + } ib_blob.link = ib_link->link; ib_blob.trans_handle = ib_link->trans[trans_n]; Index: php3/dl/Makefile.tmpl diff -u php3/dl/Makefile.tmpl:1.15 php3/dl/Makefile.tmpl:1.16 --- php3/dl/Makefile.tmpl:1.15 Thu Jul 8 08:57:45 1999 +++ php3/dl/Makefile.tmpl Sun Oct 10 10:49:11 1999 @@ -85,6 +85,17 @@ log/%.o: log/%.c $(CC) $(CFLAGS) -DCOMPILE_DL=1 -c -o $@ $< +IBASE_LIBS = -L$(IBASE_LIBDIR)/lib \ + -lgds \ + -lm \ + -ldl + +interbase.so: interbase/interbase.o + $(LD) -o $@ interbase/interbase.o $(IBASE_LIBS) + +interbase/interbase.o: ../functions/interbase.c ../functions/php3_interbase.h + $(CC) $(CFLAGS) -DCOMPILE_DL=1 -c -o $@ $< + clean: -rm -f *.so */*.o perl.out

« previous php.dev (#11668) next »