Skip to content

Commit d09edf7

Browse files
committed
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
1 parent fe5c8f2 commit d09edf7

File tree

2 files changed

+23
-26
lines changed

2 files changed

+23
-26
lines changed

ext/standard/dl.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ PHPAPI PHP_FUNCTION(dl)
8181
PHPAPI int php_load_extension(char *filename, int type, int start_now)
8282
{
8383
void *handle;
84-
char *libpath, *orig_libpath;
84+
char *libpath;
8585
zend_module_entry *module_entry;
8686
zend_module_entry *(*get_module)(void);
8787
int error_type, slash_suffix;
@@ -118,22 +118,20 @@ PHPAPI int php_load_extension(char *filename, int type, int start_now)
118118
}
119119
if (VCWD_ACCESS(libpath, F_OK)) {
120120
/* If file does not exist, consider as extension name and build file name */
121-
orig_libpath = libpath;
121+
const char *libpath_prefix = "";
122+
char *orig_libpath = libpath;
122123
#if PHP_WIN32
124+
libpath_prefix = "php_";
125+
#endif
123126
if (slash_suffix) {
124-
spprintf(&libpath, 0, "%sphp_%s." PHP_SHLIB_SUFFIX, extension_dir, filename); /* SAFE */
125-
} else {
126-
spprintf(&libpath, 0, "%s%cphp_%s." PHP_SHLIB_SUFFIX, extension_dir, DEFAULT_SLASH, filename); /* SAFE */
127-
}
128-
#else
129-
if (slash_suffix) {
130-
spprintf(&libpath, 0, "%s%s." PHP_SHLIB_SUFFIX, extension_dir, filename); /* SAFE */
127+
spprintf(&libpath, 0, "%s%s%s." PHP_SHLIB_SUFFIX, extension_dir, libpath_prefix, filename); /* SAFE */
131128
} else {
132-
spprintf(&libpath, 0, "%s%c%s." PHP_SHLIB_SUFFIX, extension_dir, DEFAULT_SLASH, filename); /* SAFE */
129+
spprintf(&libpath, 0, "%s%c%s%s." PHP_SHLIB_SUFFIX, extension_dir, DEFAULT_SLASH, libpath_prefix, filename); /* SAFE */
133130
}
134-
#endif
131+
135132
if (VCWD_ACCESS(libpath, F_OK)) {
136-
php_error_docref(NULL TSRMLS_CC, error_type, "Cannot access dynamic library '%s' (tried : %s, %s)", filename, orig_libpath, libpath);
133+
php_error(error_type, "Cannot access dynamic library '%s' (tried : %s, %s)",
134+
filename, orig_libpath, libpath);
137135
efree(orig_libpath);
138136
efree(libpath);
139137
return FAILURE;

main/php_ini.c

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ static void php_load_zend_extension_cb(void *arg)
362362
if (IS_ABSOLUTE_PATH(filename, length)) {
363363
zend_load_extension(filename);
364364
} else {
365-
char *libpath, *orig_libpath;
365+
char *libpath;
366366
char *extension_dir = INI_STR("extension_dir");
367367
int extension_dir_len = (int)strlen(extension_dir);
368368
int slash_suffix = IS_SLASH(extension_dir[extension_dir_len-1]);
@@ -372,30 +372,29 @@ static void php_load_zend_extension_cb(void *arg)
372372
} else {
373373
spprintf(&libpath, 0, "%s%c%s", extension_dir, DEFAULT_SLASH, filename); /* SAFE */
374374
}
375+
375376
if (VCWD_ACCESS(libpath, F_OK)) {
376377
/* If file does not exist, consider as extension name and build file name */
377-
orig_libpath = libpath;
378+
const char *libpath_prefix = "";
379+
char *orig_libpath = libpath;
378380
#if PHP_WIN32
381+
libpath_prefix = "php_";
382+
#endif
383+
379384
if (slash_suffix) {
380-
spprintf(&libpath, 0, "%sphp_%s." PHP_SHLIB_SUFFIX, extension_dir, filename); /* SAFE */
381-
} else {
382-
spprintf(&libpath, 0, "%s%cphp_%s." PHP_SHLIB_SUFFIX, extension_dir, DEFAULT_SLASH, filename); /* SAFE */
383-
}
384-
#else
385-
if (slash_suffix) {
386-
spprintf(&libpath, 0, "%s%s." PHP_SHLIB_SUFFIX, extension_dir, filename); /* SAFE */
385+
spprintf(&libpath, 0, "%s%s%s." PHP_SHLIB_SUFFIX, extension_dir, libpath_prefix, filename); /* SAFE */
387386
} else {
388-
spprintf(&libpath, 0, "%s%c%s." PHP_SHLIB_SUFFIX, extension_dir, DEFAULT_SLASH, filename); /* SAFE */
387+
spprintf(&libpath, 0, "%s%c%s%s." PHP_SHLIB_SUFFIX, extension_dir, DEFAULT_SLASH, libpath_prefix, filename); /* SAFE */
389388
}
390-
#endif
389+
391390
if (VCWD_ACCESS(libpath, F_OK)) {
392-
fprintf(stderr, "Cannot access Zend extension %s (Tried: %s, %s)\n", filename, orig_libpath, libpath);
393-
/* See http://support.microsoft.com/kb/190351 */
394-
fflush(stderr);
391+
php_error(E_CORE_WARNING, "Cannot access Zend extension %s (Tried: %s, %s)\n",
392+
filename, orig_libpath, libpath);
395393
efree(orig_libpath);
396394
efree(libpath);
397395
return;
398396
}
397+
399398
efree(orig_libpath);
400399
}
401400

0 commit comments

Comments
 (0)