Skip to content

Commit

Permalink
Avoid using E_CORE_* errorlevels in any place which is not in the glo…
Browse files Browse the repository at this point in the history
…bal startup sequence
  • Loading branch information
zsuraski committed Jun 12, 2000
1 parent 2c5c26f commit fce92e3
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 50 deletions.
21 changes: 14 additions & 7 deletions Zend/zend_API.c
Expand Up @@ -188,7 +188,7 @@ ZEND_API inline int _array_init(zval *arg ZEND_FILE_LINE_DC)
ALLOC_HASHTABLE_REL(arg->value.ht);

if (!arg->value.ht || zend_hash_init(arg->value.ht, 0, NULL, ZVAL_PTR_DTOR, 0)) {
zend_error(E_CORE_ERROR, "Cannot allocate memory for array");
zend_error(E_ERROR, "Cannot allocate memory for array");
return FAILURE;
}
arg->type = IS_ARRAY;
Expand Down Expand Up @@ -707,15 +707,22 @@ ZEND_API int zend_startup_module(zend_module_entry *module)


/* registers all functions in *library_functions in the function hash */
int zend_register_functions(zend_function_entry *functions, HashTable *function_table)
int zend_register_functions(zend_function_entry *functions, HashTable *function_table, int type)
{
zend_function_entry *ptr = functions;
zend_function function;
zend_internal_function *internal_function = (zend_internal_function *)&function;
int count=0,unload=0;
HashTable *target_function_table = function_table;
int error_type;
CLS_FETCH();

if (type==MODULE_PERSISTENT) {
error_type = E_CORE_WARNING;
} else {
error_type = E_WARNING;
}

if (!target_function_table) {
target_function_table = CG(function_table);
}
Expand All @@ -726,7 +733,7 @@ int zend_register_functions(zend_function_entry *functions, HashTable *function_
internal_function->arg_types = ptr->func_arg_types;
internal_function->function_name = ptr->fname;
if (!internal_function->handler) {
zend_error(E_CORE_WARNING,"Null function defined as active function");
zend_error(error_type, "Null function defined as active function");
zend_unregister_functions(functions, count, target_function_table);
return FAILURE;
}
Expand All @@ -740,7 +747,7 @@ int zend_register_functions(zend_function_entry *functions, HashTable *function_
if (unload) { /* before unloading, display all remaining bad function in the module */
while (ptr->fname) {
if (zend_hash_exists(target_function_table, ptr->fname, strlen(ptr->fname)+1)) {
zend_error(E_CORE_WARNING, "Function registration failed - duplicate name - %s",ptr->fname);
zend_error(error_type, "Function registration failed - duplicate name - %s",ptr->fname);
}
ptr++;
}
Expand Down Expand Up @@ -782,7 +789,7 @@ ZEND_API int zend_register_module(zend_module_entry *module)
#if 0
zend_printf("%s: Registering module %d\n",module->name, module->module_number);
#endif
if (module->functions && zend_register_functions(module->functions, NULL)==FAILURE) {
if (module->functions && zend_register_functions(module->functions, NULL, module->type)==FAILURE) {
zend_error(E_CORE_WARNING,"%s: Unable to register functions, unable to load",module->name);
return FAILURE;
}
Expand Down Expand Up @@ -908,7 +915,7 @@ ZEND_API zend_class_entry *zend_register_internal_class(zend_class_entry *class_


if (class_entry->builtin_functions) {
zend_register_functions(class_entry->builtin_functions, &class_entry->function_table);
zend_register_functions(class_entry->builtin_functions, &class_entry->function_table, MODULE_PERSISTENT);
}

zend_hash_update(CG(class_table), lowercase_name, class_entry->name_length+1, class_entry, sizeof(zend_class_entry), (void **) &register_class);
Expand Down Expand Up @@ -973,5 +980,5 @@ ZEND_API int zend_disable_function(char *function_name, uint function_name_lengt
return FAILURE;
}
disabled_function[0].fname = function_name;
return zend_register_functions(disabled_function, CG(function_table));
return zend_register_functions(disabled_function, CG(function_table), MODULE_PERSISTENT);
}
2 changes: 1 addition & 1 deletion Zend/zend_API.h
Expand Up @@ -108,7 +108,7 @@ ZEND_API int zend_get_parameters_array_ex(int param_count, zval ***argument_arra

ZEND_API int ParameterPassedByReference(int ht, uint n);

int zend_register_functions(zend_function_entry *functions, HashTable *function_table);
int zend_register_functions(zend_function_entry *functions, HashTable *function_table, int type);
void zend_unregister_functions(zend_function_entry *functions, int count, HashTable *function_table);
ZEND_API int zend_register_module(zend_module_entry *module_entry);

Expand Down
2 changes: 1 addition & 1 deletion Zend/zend_builtin_functions.c
Expand Up @@ -107,7 +107,7 @@ static zend_function_entry builtin_functions[] = {

int zend_startup_builtin_functions()
{
return zend_register_functions(builtin_functions, NULL);
return zend_register_functions(builtin_functions, NULL, MODULE_PERSISTENT);
}


Expand Down
45 changes: 21 additions & 24 deletions ext/standard/dl.c
Expand Up @@ -35,12 +35,15 @@
#ifdef PHP_WIN32
#include "win32/param.h"
#include "win32/winutil.h"
#define GET_DL_ERROR() php_win_err()
#else
#include <sys/param.h>
#define GET_DL_ERROR() dlerror()
#endif

#endif


/* {{{ proto int dl(string extension_filename)
Load a PHP extension at runtime */
PHP_FUNCTION(dl)
Expand All @@ -60,7 +63,7 @@ PHP_FUNCTION(dl)
} else if (PG(safe_mode)) {
php_error(E_ERROR, "Dynamically loaded extensions aren't allowed when running in SAFE MODE.");
} else {
php_dl(*file,MODULE_TEMPORARY,return_value);
php_dl(*file, MODULE_TEMPORARY, return_value);
}
}

Expand All @@ -78,15 +81,22 @@ PHP_FUNCTION(dl)
#define IS_SLASH(c) \
(((c)=='/') || ((c)=='\\'))

void php_dl(pval *file,int type,pval *return_value)
void php_dl(pval *file, int type, pval *return_value)
{
void *handle;
char *libpath;
zend_module_entry *module_entry,*tmp;
zend_module_entry *(*get_module)(void);
int error_type;
PLS_FETCH();
ELS_FETCH();

if (type==MODULE_TEMPORARY) {
error_type = E_WARNING;
} else {
error_type = E_CORE_WARNING;
}

if (PG(extension_dir) && PG(extension_dir)[0]){
int extension_dir_len = strlen(PG(extension_dir));

Expand All @@ -104,21 +114,8 @@ void php_dl(pval *file,int type,pval *return_value)
/* load dynamic symbol */
handle = DL_LOAD(libpath);
if (!handle) {
int error_type;

if (type==MODULE_TEMPORARY) {
error_type = E_ERROR;
} else {
error_type = E_CORE_ERROR;
}
#ifdef PHP_WIN32
php_error(error_type,"Unable to load dynamic library '%s'<br>\n%s",libpath,php_win_err());
#else
php_error(error_type,"Unable to load dynamic library '%s' - %s",libpath,dlerror());
#endif

php_error(error_type, "Unable to load dynamic library '%s' - %s", libpath, GET_DL_ERROR());
efree(libpath);

RETURN_FALSE;
}

Expand All @@ -138,13 +135,13 @@ void php_dl(pval *file,int type,pval *return_value)

if (!get_module) {
DL_UNLOAD(handle);
php_error(E_CORE_WARNING,"Invalid library (maybe not a PHP library) '%s' ",file->value.str.val);
php_error(error_type, "Invalid library (maybe not a PHP library) '%s' ", file->value.str.val);
RETURN_FALSE;
}
module_entry = get_module();
if ((module_entry->zend_debug != ZEND_DEBUG) || (module_entry->zts != USING_ZTS)
|| (module_entry->zend_api != ZEND_MODULE_API_NO)) {
php_error(E_CORE_WARNING,
php_error(error_type,
"%s: Unable to initialize module\n"
"Module compiled with debug=%d, thread-safety=%d module API=%d\n"
"PHP compiled with debug=%d, thread-safety=%d module API=%d\n"
Expand All @@ -158,7 +155,7 @@ void php_dl(pval *file,int type,pval *return_value)
module_entry->module_number = zend_next_free_module();
if (module_entry->module_startup_func) {
if (module_entry->module_startup_func(type, module_entry->module_number ELS_CC)==FAILURE) {
php_error(E_CORE_WARNING,"%s: Unable to initialize module",module_entry->name);
php_error(error_type, "%s: Unable to initialize module", module_entry->name);
DL_UNLOAD(handle);
RETURN_FALSE;
}
Expand All @@ -167,15 +164,15 @@ void php_dl(pval *file,int type,pval *return_value)

if ((type == MODULE_TEMPORARY) && module_entry->request_startup_func) {
if (module_entry->request_startup_func(type, module_entry->module_number ELS_CC)) {
php_error(E_CORE_WARNING,"%s: Unable to initialize module",module_entry->name);
php_error(error_type, "%s: Unable to initialize module", module_entry->name);
DL_UNLOAD(handle);
RETURN_FALSE;
}
}

/* update the .request_started property... */
if (zend_hash_find(&module_registry,module_entry->name,strlen(module_entry->name)+1,(void **) &tmp)==FAILURE) {
php_error(E_ERROR,"%s: Loaded module got lost",module_entry->name);
if (zend_hash_find(&module_registry, module_entry->name, strlen(module_entry->name)+1,(void **) &tmp)==FAILURE) {
php_error(error_type,"%s: Loaded module got lost", module_entry->name);
RETURN_FALSE;
}
tmp->handle = handle;
Expand All @@ -191,9 +188,9 @@ PHP_MINFO_FUNCTION(dl)

#else

void php_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);
php_error(E_WARNING,"Cannot dynamically load %s - dynamic modules are not supported", file->value.str.val);
RETURN_FALSE;
}

Expand Down
2 changes: 1 addition & 1 deletion main/fopen_wrappers.c
Expand Up @@ -361,7 +361,7 @@ PHPAPI FILE *php_fopen_primary_script(void)
fp = NULL;
}
if (!fp) {
php_error(E_CORE_ERROR, "Unable to open %s", fn);
php_error(E_ERROR, "Unable to open %s", fn);
STR_FREE(SG(request_info).path_translated); /* for same reason as above */
return NULL;
}
Expand Down
30 changes: 14 additions & 16 deletions main/main.c
Expand Up @@ -364,29 +364,27 @@ static void php_error_cb(int type, const char *error_filename, const uint error_
va_end(args);
buffer[sizeof(buffer) - 1] = 0;

if (PG(log_errors) || (!module_initialized)) {
if (!module_initialized || PG(log_errors)) {
char log_buffer[1024];

#ifdef PHP_WIN32
if (type==E_CORE_ERROR || type==E_CORE_WARNING) {
MessageBox(NULL, buffer, error_type_str, MB_OK);
}
#endif
snprintf(log_buffer, 1024, "PHP %s: %s in %s on line %d", error_type_str, buffer, error_filename, error_lineno);
php_log_err(log_buffer);
}
if (PG(display_errors)) {
if (module_initialized && PG(display_errors)) {
char *prepend_string = INI_STR("error_prepend_string");
char *append_string = INI_STR("error_append_string");

#ifdef PHP_WIN32
if (type==E_CORE_ERROR || type==E_CORE_WARNING)
MessageBox(NULL, buffer, error_type_str, MB_OK);
else
#endif
{
if (prepend_string) {
PUTS(prepend_string);
}
php_printf("<br>\n<b>%s</b>: %s in <b>%s</b> on line <b>%d</b><br>\n", error_type_str, buffer, error_filename, error_lineno);
if (append_string) {
PUTS(append_string);
}
if (prepend_string) {
PUTS(prepend_string);
}
php_printf("<br>\n<b>%s</b>: %s in <b>%s</b> on line <b>%d</b><br>\n", error_type_str, buffer, error_filename, error_lineno);
if (append_string) {
PUTS(append_string);
}
}
#if ZEND_DEBUG
Expand Down Expand Up @@ -1034,7 +1032,7 @@ static int php_hash_environment(ELS_D SLS_DC PLS_DC)
if (have_variables_order) {
php_import_environment_variables(ELS_C PLS_CC);
} else {
php_error(E_CORE_WARNING, "Unsupported 'e' element (environment) used in gpc_order - use variables_order instead");
php_error(E_WARNING, "Unsupported 'e' element (environment) used in gpc_order - use variables_order instead");
}
break;
case 's':
Expand Down

0 comments on commit fce92e3

Please sign in to comment.