ssb Mon Mar 12 02:12:57 2001 EDT Added files: /pear/PEAR .cvsignore INSTALL Makefile.in config.m4 pear.c php_pear.h Log: * started converting the PEAR base class to C (currently only constructor and destructor is implemented)
Index: pear/PEAR/.cvsignore +++ pear/PEAR/.cvsignore deps Makefile *.lo *.la libs libs.mk *.slo build acinclude.m4 dynlib.m4 configure.in install-sh mkinstalldirs missing aclocal.m4 configure config.guess config.sub ltconfig ltmain.sh config.h config.log config.cache libtool config_vars.mk config.status modules config.h.in test*.php Index: pear/PEAR/Makefile.in +++ pear/PEAR/Makefile.in # $Id: Makefile.in,v 1.1 2001/03/12 10:12:57 ssb Exp $ LTLIBRARY_NAME = libPEAR.la LTLIBRARY_SOURCES = pear.c LTLIBRARY_SHARED_NAME = PEAR.la LTLIBRARY_SHARED_LIBADD = $(PEAR_SHARED_LIBADD) include $(top_srcdir)/build/dynlib.mk $(srcdir)/pear.c: $(srcdir)/php_pear.h Index: pear/PEAR/config.m4 +++ pear/PEAR/config.m4 dnl $Id: config.m4,v 1.1 2001/03/12 10:12:57 ssb Exp $ dnl config.m4 for extension pear dnl don't forget to call PHP_EXTENSION(pear) dnl Comments in this file start with the string 'dnl'. dnl Remove where necessary. This file will not work dnl without editing. dnl If your extension references something external, use with: dnl PHP_ARG_WITH(pear, for pear support, dnl Make sure that the comment is aligned: dnl [ --with-pear Include pear support]) dnl Otherwise use enable: dnl PHP_ARG_ENABLE(pear, whether to enable pear support, dnl Make sure that the comment is aligned: dnl [ --enable-pear Enable pear support]) dnl if test "$PHP_PEAR" != "no"; then dnl dnl If you will not be testing anything external, like existence of dnl dnl headers, libraries or functions in them, just uncomment the dnl dnl following line and you are ready to go. dnl dnl Write more examples of tests here... dnl PHP_EXTENSION(pear, $ext_shared) dnl fi PHP_EXTENSION(pear, yes) Index: pear/PEAR/pear.c +++ pear/PEAR/pear.c /* +----------------------------------------------------------------------+ | PHP version 4.0 | +----------------------------------------------------------------------+ | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 2.02 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available at through the world-wide-web at | | http://www.php.net/license/2_02.txt. | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [EMAIL PROTECTED] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Stig Sæther Bakken <[EMAIL PROTECTED]> | | | +----------------------------------------------------------------------+ */ #include "php.h" #include "php_ini.h" #include "php_pear.h" #include "config.h" ZEND_DECLARE_MODULE_GLOBALS(pear) /* Every user visible function must have an entry in pear_functions[]. */ function_entry pear_functions[] = { {NULL, NULL, NULL} /* Must be the last line in pear_functions[] */ }; static zend_function_entry php_class_functions_pear[] = { PHP_FALIAS(pear, pear_constructor, NULL) PHP_FALIAS(_pear, pear_destructor, NULL) #if 0 PHP_FALIAS(iserror, pear_isError, first_arg_force_ref) PHP_FALIAS(seterrorhandling, pear_setErrorHandling, NULL) PHP_FALIAS(raiseerror, pear_raiseError, NULL) #endif {NULL, NULL, NULL} }; static zend_function_entry php_class_functions_pear_error[] = { #if 0 PHP_FALIAS(pear_error, pear_error_constructor, NULL) PHP_FALIAS(getmode, pear_error_getmode, NULL) PHP_FALIAS(getcallback, pear_error_getcallback, NULL) PHP_FALIAS(getmessage, pear_error_getmessage, NULL) PHP_FALIAS(getcode, pear_error_getcode, NULL) PHP_FALIAS(gettype, pear_error_gettype, NULL) PHP_FALIAS(getuserinfo, pear_error_getuserinfo, NULL) PHP_FALIAS(getdebuginfo, pear_error_getdebuginfo, NULL) PHP_FALIAS(tostring, pear_error_tostring, NULL) #endif {NULL, NULL, NULL} }; zend_module_entry pear_module_entry = { "PEAR", pear_functions, PHP_MINIT(pear), PHP_MSHUTDOWN(pear), PHP_RINIT(pear), /* Replace with NULL if there's nothing to do at request start */ PHP_RSHUTDOWN(pear), /* Replace with NULL if there's nothing to do at request end */ PHP_MINFO(pear), STANDARD_MODULE_PROPERTIES }; static zend_class_entry *pear_ptr, *pear_error_ptr; #ifdef COMPILE_DL_PEAR ZEND_GET_MODULE(pear) #endif /* Remove comments and fill if you need to have entries in php.ini PHP_INI_BEGIN() PHP_INI_END() */ PHP_MINIT_FUNCTION(pear) { zend_class_entry pear, pear_error; /* REGISTER_INI_ENTRIES();*/ pear.name = strdup("pear"); pear.name_length = 4; pear.builtin_functions = php_class_functions_pear; pear.handle_function_call = NULL; pear.handle_property_get = NULL; pear.handle_property_set = NULL; pear_ptr = zend_register_internal_class(&pear); pear_error.name = strdup("pear_error"); pear_error.name_length = 10; pear_error.builtin_functions = php_class_functions_pear_error; pear_error.handle_function_call = NULL; pear_error.handle_property_get = NULL; pear_error.handle_property_set = NULL; pear_error_ptr = zend_register_internal_class(&pear_error); return SUCCESS; } PHP_MSHUTDOWN_FUNCTION(pear) { /* Remove comments if you have entries in php.ini UNREGISTER_INI_ENTRIES(); */ return SUCCESS; } static void _destructor_objects_dtor(void *data) { zval *object = (zval *)data; object->refcount--; } /* Remove if there's nothing to do at request start */ PHP_RINIT_FUNCTION(pear) { zend_llist_init(&PEARG(destructor_objects), sizeof(zval), NULL, 0); return SUCCESS; } static zval *_pear_string_zval(const char *str) { zval *ret; int len = strlen(str); MAKE_STD_ZVAL(ret); ret->type = IS_STRING; ret->value.str.len = len; ret->value.str.val = estrndup(str, len); return ret; } static void _call_destructors(void *data) { zval *object = (zval *)data, *funcname, *arg, *retval; int res; MAKE_STD_ZVAL(funcname); MAKE_STD_ZVAL(retval); MAKE_STD_ZVAL(arg); funcname->type = IS_STRING; funcname->value.str.len = object->value.obj.ce->name_length + 1; funcname->value.str.val = emalloc(funcname->value.str.len + 1); funcname->value.str.val[0] = '_'; memcpy(&funcname->value.str.val[1], object->value.obj.ce->name, funcname->value.str.len); funcname->value.str.val[funcname->value.str.len] = '\0'; res = call_user_function(&object->value.obj.ce->function_table, &object, funcname, retval, 0, &arg); if (res == FAILURE) { php_error(E_WARNING, "calling %s::%s destructor failed!", object->value.obj.ce->name, funcname->value.str.val); } zval_dtor(funcname); zval_dtor(retval); zval_dtor(arg); } /* Remove if there's nothing to do at request end */ PHP_RSHUTDOWN_FUNCTION(pear) { zend_llist_apply(&PEARG(destructor_objects), _call_destructors); zend_llist_destroy(&PEARG(destructor_objects)); return SUCCESS; } PHP_MINFO_FUNCTION(pear) { php_info_print_table_start(); php_info_print_table_header(2, "PEAR", " $Revision: 1.1 $"); php_info_print_table_end(); /* DISPLAY_INI_ENTRIES(); */ } PHP_FUNCTION(pear_constructor) { zval *this = getThis(); size_t len; char *dtorfunc; PEARLS_FETCH(); if (ZEND_NUM_ARGS() > 0) { WRONG_PARAM_COUNT; } len = this->value.obj.ce->name_length + 2; dtorfunc = emalloc(len); dtorfunc[0] = '_'; memcpy(dtorfunc + 1, this->value.obj.ce->name, len - 1); dtorfunc[len - 1] = '\0'; if (zend_hash_exists(&this->value.obj.ce->function_table, dtorfunc, len)) { zend_llist_add_element(&PEARG(destructor_objects), this); this->refcount++; /*php_printf("registered object on destructor list\n");*/ } efree(dtorfunc); } PHP_FUNCTION(pear_destructor) { /*php_printf("PEAR destructor called\n");*/ } /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * End: */ Index: pear/PEAR/php_pear.h +++ pear/PEAR/php_pear.h /* +----------------------------------------------------------------------+ | PHP version 4.0 | +----------------------------------------------------------------------+ | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 2.02 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available at through the world-wide-web at | | http://www.php.net/license/2_02.txt. | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [EMAIL PROTECTED] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: | | | +----------------------------------------------------------------------+ */ #ifndef PHP_PEAR_H #define PHP_PEAR_H extern zend_module_entry pear_module_entry; #define phpext_pear_ptr &pear_module_entry #ifdef PHP_WIN32 #define PHP_PEAR_API __declspec(dllexport) #else #define PHP_PEAR_API #endif PHP_MINIT_FUNCTION(pear); PHP_MSHUTDOWN_FUNCTION(pear); PHP_RINIT_FUNCTION(pear); PHP_RSHUTDOWN_FUNCTION(pear); PHP_MINFO_FUNCTION(pear); PHP_FUNCTION(pear_constructor); PHP_FUNCTION(pear_destructor); ZEND_BEGIN_MODULE_GLOBALS(pear) zend_llist destructor_objects; ZEND_END_MODULE_GLOBALS(pear) /* In every function that needs to use variables in php_pear_globals, do call PEARLS_FETCH(); after declaring other variables used by that function, and always refer to them as PEARG(variable). You are encouraged to rename these macros something shorter, see examples in any other php module directory. */ #ifdef ZTS #define PEARG(v) (pear_globals->v) #define PEARLS_FETCH() php_pear_globals *pear_globals = ts_resource(pear_globals_id) #else #define PEARG(v) (pear_globals.v) #define PEARLS_FETCH() #endif #endif /* PHP_PEAR_H */ /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * End: */
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]