CVS update: php3/functions
| From: | cslawi | Date: | Thu, 17 Sep 1998 09:24:06 +0000 |
| Subject: | CVS update: php3/functions | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-1191@lists.php.net to get a copy of this message | ||
Date: Thursday September 17, 1998 @ 5:24
Author: cslawi
Update of /repository/php3/functions
In directory asf:/u2/tmp/cvs-serv27766/functions
Modified Files:
basic_functions.c basic_functions.h
Log Message:
Added register_shutdown_method().
Allow register_shutdown_(method|function) to accept arguments (using
call_user_*() as a model) to pass to the registered function.
Still need to clarify a couple of error messages.
Index: php3/functions/basic_functions.c
diff -c php3/functions/basic_functions.c:1.216 php3/functions/basic_functions.c:1.217
*** php3/functions/basic_functions.c:1.216 Thu Sep 10 19:57:17 1998
--- php3/functions/basic_functions.c Thu Sep 17 05:24:05 1998
***************
*** 89,94 ****
--- 89,95 ----
void user_shutdown_function_dtor(pval *user_shutdown_function_name);
int user_shutdown_function_executor(pval *user_shutdown_function_name);
void php3_call_shutdown_functions(void);
+ static void _php3_register_shutdown_function( pval **params, int arg_count, int is_method );
function_entry basic_functions[] = {
{"intval", int_value, NULL},
***************
*** 278,284 ****
{"call_user_method", php3_call_user_method, NULL},
PHP_FE(register_shutdown_function, NULL)
!
{NULL, NULL, NULL}
};
--- 279,286 ----
{"call_user_method", php3_call_user_method, NULL},
PHP_FE(register_shutdown_function, NULL)
! PHP_FE(register_shutdown_method, NULL)
!
{NULL, NULL, NULL}
};
***************
*** 1595,1611 ****
}
- void user_shutdown_function_dtor(pval *user_shutdown_function_name)
- {
- pval retval;
-
- if (call_user_function(&GLOBAL(function_table), NULL, user_shutdown_function_name,
&retval, 0, NULL)==SUCCESS) {
- pval_destructor(&retval);
- }
- pval_destructor(user_shutdown_function_name);
- }
-
-
int user_shutdown_function_executor(pval *user_shutdown_function_name)
{
return 1;
--- 1597,1602 ----
***************
*** 1620,1643 ****
}
! PHP_FUNCTION(register_shutdown_function)
{
! pval *arg, shutdown_function_name;
!
! if (ARG_COUNT(ht)!=1 || getParameters(ht, 1, &arg)==FAILURE) {
! WRONG_PARAM_COUNT;
}
! convert_to_string(arg);
if (!user_shutdown_function_names) {
user_shutdown_function_names = (HashTable *) emalloc(sizeof(HashTable));
_php3_hash_init(user_shutdown_function_names, 0, NULL, (void (*)(void
*))user_shutdown_function_dtor, 0);
}
!
! shutdown_function_name = *arg;
! pval_copy_constructor(&shutdown_function_name);
!
! _php3_hash_next_index_insert(user_shutdown_function_names, &shutdown_function_name,
sizeof(pval), NULL);
}
/*
--- 1611,1748 ----
}
! void user_shutdown_function_dtor(pval *arg)
{
! pval retval;
! pval **params;
! int i = 0, param_count;
!
! param_count = _php3_hash_num_elements( arg->value.ht );
!
! if ( param_count < 2 ) {
! /* no function to call */
! pval_destructor( arg );
! return;
! }
!
! params = (pval **) emalloc(sizeof(pval *) * param_count);
!
! for ( i = 0; i < param_count; i++ ) {
! _php3_hash_index_find( arg->value.ht, i, (void **) ¶ms[i] );
! }
!
! if ( params[0]->type == IS_LONG ) {
! if ( call_user_function(&GLOBAL(function_table), params[2], params[1], &retval,
param_count - 3, params + 3 )==SUCCESS) {
! pval_destructor(&retval);
! }
! } else {
! if ( call_user_function(&GLOBAL(function_table), NULL, params[1], &retval, param_count -
2, params + 2 )==SUCCESS) {
! pval_destructor(&retval);
! }
! }
!
! pval_destructor( arg );
! efree( params );
! }
!
!
! static void _php3_register_shutdown_function( pval **params, int arg_count, int is_method )
! {
! pval param_array, type_temp;
! HashTable *destroy;
! int i;
!
! if ( array_init( ¶m_array ) == FAILURE ) {
! return;
! }
! destroy = param_array.value.ht;
!
! /* just use type_temp to mark which kind of thing we're registering */
! if ( is_method ) {
! /* registering a method */
! type_temp.type = IS_LONG;
! } else {
! /* registering a function */
! type_temp.type = IS_STRING;
}
! if ( _php3_hash_next_index_pointer_insert(param_array.value.ht, &type_temp )==FAILURE) {
! php3_error(E_WARNING, "Couldn't register shutdown function %s()",
params[0]->value.str.val );
! _php3_hash_destroy( destroy );
! efree( destroy );
! return;
! }
!
! for ( i = 0; i < arg_count; i++ ) {
! if ( _php3_hash_next_index_pointer_insert(param_array.value.ht, params[i] )==FAILURE) {
! php3_error(E_WARNING, "Couldn't register shutdown function %s()",
params[0]->value.str.val );
! _php3_hash_destroy( destroy );
! efree( destroy );
! return;
! }
! }
!
! pval_copy_constructor( ¶m_array );
!
if (!user_shutdown_function_names) {
user_shutdown_function_names = (HashTable *) emalloc(sizeof(HashTable));
_php3_hash_init(user_shutdown_function_names, 0, NULL, (void (*)(void
*))user_shutdown_function_dtor, 0);
}
!
! if (_php3_hash_next_index_insert(user_shutdown_function_names, ¶m_array, sizeof(pval),
NULL)==FAILURE) {
! php3_error(E_WARNING, "Couldn't register shutdown function %s()",
params[0]->value.str.val );
! }
!
! _php3_hash_destroy( destroy );
! efree( destroy );
! }
!
!
! PHP_FUNCTION(register_shutdown_function)
! {
! pval **params;
! int arg_count = ARG_COUNT(ht);
!
! if ( arg_count < 1 ) {
! WRONG_PARAM_COUNT;
! }
!
! params = (pval **) emalloc(sizeof(pval)*arg_count);
!
! if (getParametersArray(ht, arg_count, params)==FAILURE) {
! efree(params);
! RETURN_FALSE;
! }
!
! _php3_register_shutdown_function( params, arg_count, 0 );
! efree( params );
! }
!
!
! PHP_FUNCTION(register_shutdown_method)
! {
! pval **params;
! int arg_count = ARG_COUNT(ht);
!
! if ( arg_count < 2 ) {
! WRONG_PARAM_COUNT;
! }
!
! params = (pval **) emalloc(sizeof(pval)*arg_count);
!
! if (getParametersArray(ht, arg_count, params)==FAILURE) {
! efree(params);
! RETURN_FALSE;
! }
!
! if (params[1]->type != IS_OBJECT) {
! php3_error(E_WARNING,"2nd argument to register_shutdown_method must be an object\n");
! efree(params);
! RETURN_FALSE;
! }
!
! _php3_register_shutdown_function( params, arg_count, 1 );
! efree( params );
}
/*
Index: php3/functions/basic_functions.h
diff -c php3/functions/basic_functions.h:1.31 php3/functions/basic_functions.h:1.32
*** php3/functions/basic_functions.h:1.31 Sun Sep 6 11:12:36 1998
--- php3/functions/basic_functions.h Thu Sep 17 05:24:05 1998
***************
*** 29,35 ****
*/
! /* $Id: basic_functions.h,v 1.31 1998/09/06 15:12:36 zeev Exp $ */
#ifndef _BASIC_FUNCTIONS_H
#define _BASIC_FUNCTIONS_H
--- 29,35 ----
*/
! /* $Id: basic_functions.h,v 1.32 1998/09/17 09:24:05 cslawi Exp $ */
#ifndef _BASIC_FUNCTIONS_H
#define _BASIC_FUNCTIONS_H
***************
*** 94,99 ****
--- 94,100 ----
extern void php3_call_user_method(INTERNAL_FUNCTION_PARAMETERS);
PHP_FUNCTION(register_shutdown_function);
+ PHP_FUNCTION(register_shutdown_method);
#if HAVE_PUTENV
typedef struct {
--
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