From e2d66a6d28d36be54f22fd0175a59eb3dd6b3b88 Mon Sep 17 00:00:00 2001 From: "Thies C. Arntzen" Date: Wed, 13 Oct 1999 19:55:25 +0000 Subject: [PATCH] new api fo dl() - renamed php3_dl to php_dl (added compat header) --- ext/standard/dl.c | 14 +++++---- ext/standard/dl.h | 2 +- ext/standard/file.c | 61 ++++++++++++++++--------------------- main/configuration-parser.y | 2 +- main/php3_compat.h | 1 + 5 files changed, 37 insertions(+), 43 deletions(-) diff --git a/ext/standard/dl.c b/ext/standard/dl.c index 3920cd4493..886d25cc4c 100644 --- a/ext/standard/dl.c +++ b/ext/standard/dl.c @@ -53,33 +53,35 @@ php3_module_entry dl_module_entry = { #endif /* {{{ proto int dl(string extension_filename) + Load a PHP extension at runtime */ void dl(INTERNAL_FUNCTION_PARAMETERS) { - pval *file; + pval **file; PLS_FETCH(); /* obtain arguments */ - if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &file) == FAILURE) { + if (ARG_COUNT(ht) != 1 || getParametersEx(1, &file) == FAILURE) { WRONG_PARAM_COUNT; } - convert_to_string(file); + convert_to_string_ex(file); if (!PG(enable_dl)) { php_error(E_ERROR, "Dynamically loaded extentions aren't enabled."); } else if (PG(safe_mode)) { php_error(E_ERROR, "Dynamically loaded extensions aren't allowed when running in SAFE MODE."); } else { - php3_dl(file,MODULE_TEMPORARY,return_value); + php_dl(*file,MODULE_TEMPORARY,return_value); } } + /* }}} */ #if HAVE_LIBDL -void php3_dl(pval *file,int type,pval *return_value) +void php_dl(pval *file,int type,pval *return_value) { void *handle; char libpath[MAXPATHLEN + 1]; @@ -165,7 +167,7 @@ PHP_MINFO_FUNCTION(dl) #else -void php3_dl(pval *file,int type,pval *return_value) +void php_dl(pval *file,int type,pval *return_value) { php_error(E_WARNING,"Cannot dynamically load %s - dynamic modules are not supported",file->value.str.val); RETURN_FALSE; diff --git a/ext/standard/dl.h b/ext/standard/dl.h index 9489723e4b..58a969b1c2 100644 --- a/ext/standard/dl.h +++ b/ext/standard/dl.h @@ -35,7 +35,7 @@ #ifndef _DL_H #define _DL_H -void php3_dl(pval *file,int type,pval *return_value); +void php_dl(pval *file,int type,pval *return_value); #if HAVE_LIBDL diff --git a/ext/standard/file.c b/ext/standard/file.c index 4c248a96d5..33cce4c8a0 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -236,44 +236,36 @@ static int flock_values[] = { LOCK_SH, LOCK_EX, LOCK_UN }; portable file locking */ PHP_FUNCTION(flock) { - pval *arg1, *arg2; - FILE *fp; + pval **arg1, **arg2; int type; - int issock=0; - int *sock, fd=0; + int fd=0; int act = 0; + void *what; - if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &arg1, &arg2) == FAILURE) { + if (ARG_COUNT(ht) != 2 || getParametersEx(2, &arg1, &arg2) == FAILURE) { WRONG_PARAM_COUNT; } - convert_to_long(arg1); - convert_to_long(arg2); - - fp = php3_list_find(arg1->value.lval, &type); - if (type == le_socket){ - issock = 1; - sock = php3_list_find(arg1->value.lval, &type); - fd = *sock; - } - - if ((!fp || (type!=le_fopen && type!=le_popen)) && (!fd || type!=le_socket)) { - php_error(E_WARNING,"Unable to find file identifier %d",arg1->value.lval); - RETURN_FALSE; - } + what = zend_fetch_resource(arg1,-1,"File-Handle",&type,3,le_socket,le_popen,le_socket); + ZEND_VERIFY_RESOURCE(what); + + if (type == le_socket) { + fd = *(int *) what; + } else { + fd = fileno((FILE*) what); + } + + convert_to_long_ex(arg2); - if (!issock) { - fd = fileno(fp); + act = (*arg2)->value.lval & 3; + if (act < 1 || act > 3) { + php_error(E_WARNING, "illegal value for second argument"); + RETURN_FALSE; } - act = arg2->value.lval & 3; - if(act < 1 || act > 3) { - php_error(E_WARNING, "illegal value for second argument"); - RETURN_FALSE; - } /* flock_values contains all possible actions if (arg2 & 4) we won't block on the lock */ - act = flock_values[act - 1] | (arg2->value.lval & 4 ? LOCK_NB : 0); + act = flock_values[act - 1] | ((*arg2)->value.lval & 4 ? LOCK_NB : 0); if (flock(fd, act) == -1) { RETURN_FALSE; } @@ -545,7 +537,6 @@ PHP_FUNCTION(fopen) FILE *fp; char *p; int *sock; - int id; int use_include_path = 0; int issock=0, socketd=0; @@ -583,16 +574,17 @@ PHP_FUNCTION(fopen) efree(p); RETURN_FALSE; } + + efree(p); fgetss_state=0; + if (issock) { sock=emalloc(sizeof(int)); *sock=socketd; - id = php3_list_insert(sock,le_socket); + ZEND_REGISTER_RESOURCE(return_value,sock,le_socket); } else { - id = php3_list_insert(fp,le_fopen); + ZEND_REGISTER_RESOURCE(return_value,fp,le_fopen); } - efree(p); - RETURN_LONG(id); } /* }}} */ @@ -627,7 +619,6 @@ PHP_FUNCTION(popen) { pval *arg1, *arg2; FILE *fp; - int id; char *p; char *b, buf[1024]; PLS_FETCH(); @@ -670,9 +661,9 @@ PHP_FUNCTION(popen) RETURN_FALSE; } } - id = php3_list_insert(fp,le_popen); efree(p); - RETURN_LONG(id); + + ZEND_REGISTER_RESOURCE(return_value,fp,le_popen); } /* }}} */ diff --git a/main/configuration-parser.y b/main/configuration-parser.y index 4c41f7e10f..db7f950d54 100644 --- a/main/configuration-parser.y +++ b/main/configuration-parser.y @@ -370,7 +370,7 @@ statement: printf("Loading '%s'\n",$3.value.str.val); #endif - php3_dl(&$3,MODULE_PERSISTENT,&dummy); + php_dl(&$3,MODULE_PERSISTENT,&dummy); } | T_ZEND_EXTENSION '=' string { #if !defined(ZTS) && !ZEND_DEBUG diff --git a/main/php3_compat.h b/main/php3_compat.h index 1b8db14617..f6e60bea71 100644 --- a/main/php3_compat.h +++ b/main/php3_compat.h @@ -88,5 +88,6 @@ #define _php3_addslashes php_addslashes #define _php3_stripslashes php_stripslashes +#define php3_dl php_dl #endif /* _PHP3_COMPAT_H */ -- 2.40.0