mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
Minor refactor of load extension by name impl
Minimize the #ifdef surface area Localize orig_libpath to retry scope Send errors to php_error() rathern than stderr
This commit is contained in:
parent
fe5c8f2b80
commit
d09edf7b34
2 changed files with 27 additions and 30 deletions
|
@ -81,7 +81,7 @@ PHPAPI PHP_FUNCTION(dl)
|
|||
PHPAPI int php_load_extension(char *filename, int type, int start_now)
|
||||
{
|
||||
void *handle;
|
||||
char *libpath, *orig_libpath;
|
||||
char *libpath;
|
||||
zend_module_entry *module_entry;
|
||||
zend_module_entry *(*get_module)(void);
|
||||
int error_type, slash_suffix;
|
||||
|
@ -118,22 +118,20 @@ PHPAPI int php_load_extension(char *filename, int type, int start_now)
|
|||
}
|
||||
if (VCWD_ACCESS(libpath, F_OK)) {
|
||||
/* If file does not exist, consider as extension name and build file name */
|
||||
orig_libpath = libpath;
|
||||
const char *libpath_prefix = "";
|
||||
char *orig_libpath = libpath;
|
||||
#if PHP_WIN32
|
||||
if (slash_suffix) {
|
||||
spprintf(&libpath, 0, "%sphp_%s." PHP_SHLIB_SUFFIX, extension_dir, filename); /* SAFE */
|
||||
} else {
|
||||
spprintf(&libpath, 0, "%s%cphp_%s." PHP_SHLIB_SUFFIX, extension_dir, DEFAULT_SLASH, filename); /* SAFE */
|
||||
}
|
||||
#else
|
||||
if (slash_suffix) {
|
||||
spprintf(&libpath, 0, "%s%s." PHP_SHLIB_SUFFIX, extension_dir, filename); /* SAFE */
|
||||
} else {
|
||||
spprintf(&libpath, 0, "%s%c%s." PHP_SHLIB_SUFFIX, extension_dir, DEFAULT_SLASH, filename); /* SAFE */
|
||||
}
|
||||
libpath_prefix = "php_";
|
||||
#endif
|
||||
if (slash_suffix) {
|
||||
spprintf(&libpath, 0, "%s%s%s." PHP_SHLIB_SUFFIX, extension_dir, libpath_prefix, filename); /* SAFE */
|
||||
} else {
|
||||
spprintf(&libpath, 0, "%s%c%s%s." PHP_SHLIB_SUFFIX, extension_dir, DEFAULT_SLASH, libpath_prefix, filename); /* SAFE */
|
||||
}
|
||||
|
||||
if (VCWD_ACCESS(libpath, F_OK)) {
|
||||
php_error_docref(NULL TSRMLS_CC, error_type, "Cannot access dynamic library '%s' (tried : %s, %s)", filename, orig_libpath, libpath);
|
||||
php_error(error_type, "Cannot access dynamic library '%s' (tried : %s, %s)",
|
||||
filename, orig_libpath, libpath);
|
||||
efree(orig_libpath);
|
||||
efree(libpath);
|
||||
return FAILURE;
|
||||
|
|
|
@ -362,7 +362,7 @@ static void php_load_zend_extension_cb(void *arg)
|
|||
if (IS_ABSOLUTE_PATH(filename, length)) {
|
||||
zend_load_extension(filename);
|
||||
} else {
|
||||
char *libpath, *orig_libpath;
|
||||
char *libpath;
|
||||
char *extension_dir = INI_STR("extension_dir");
|
||||
int extension_dir_len = (int)strlen(extension_dir);
|
||||
int slash_suffix = IS_SLASH(extension_dir[extension_dir_len-1]);
|
||||
|
@ -372,30 +372,29 @@ static void php_load_zend_extension_cb(void *arg)
|
|||
} else {
|
||||
spprintf(&libpath, 0, "%s%c%s", extension_dir, DEFAULT_SLASH, filename); /* SAFE */
|
||||
}
|
||||
|
||||
if (VCWD_ACCESS(libpath, F_OK)) {
|
||||
/* If file does not exist, consider as extension name and build file name */
|
||||
orig_libpath = libpath;
|
||||
const char *libpath_prefix = "";
|
||||
char *orig_libpath = libpath;
|
||||
#if PHP_WIN32
|
||||
if (slash_suffix) {
|
||||
spprintf(&libpath, 0, "%sphp_%s." PHP_SHLIB_SUFFIX, extension_dir, filename); /* SAFE */
|
||||
} else {
|
||||
spprintf(&libpath, 0, "%s%cphp_%s." PHP_SHLIB_SUFFIX, extension_dir, DEFAULT_SLASH, filename); /* SAFE */
|
||||
}
|
||||
#else
|
||||
if (slash_suffix) {
|
||||
spprintf(&libpath, 0, "%s%s." PHP_SHLIB_SUFFIX, extension_dir, filename); /* SAFE */
|
||||
} else {
|
||||
spprintf(&libpath, 0, "%s%c%s." PHP_SHLIB_SUFFIX, extension_dir, DEFAULT_SLASH, filename); /* SAFE */
|
||||
}
|
||||
libpath_prefix = "php_";
|
||||
#endif
|
||||
|
||||
if (slash_suffix) {
|
||||
spprintf(&libpath, 0, "%s%s%s." PHP_SHLIB_SUFFIX, extension_dir, libpath_prefix, filename); /* SAFE */
|
||||
} else {
|
||||
spprintf(&libpath, 0, "%s%c%s%s." PHP_SHLIB_SUFFIX, extension_dir, DEFAULT_SLASH, libpath_prefix, filename); /* SAFE */
|
||||
}
|
||||
|
||||
if (VCWD_ACCESS(libpath, F_OK)) {
|
||||
fprintf(stderr, "Cannot access Zend extension %s (Tried: %s, %s)\n", filename, orig_libpath, libpath);
|
||||
/* See http://support.microsoft.com/kb/190351 */
|
||||
fflush(stderr);
|
||||
php_error(E_CORE_WARNING, "Cannot access Zend extension %s (Tried: %s, %s)\n",
|
||||
filename, orig_libpath, libpath);
|
||||
efree(orig_libpath);
|
||||
efree(libpath);
|
||||
return;
|
||||
}
|
||||
|
||||
efree(orig_libpath);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue