Skip to content

Commit 171352b

Browse files
committed
feat: first-class hybrid extensions
1 parent 031b4c6 commit 171352b

File tree

5 files changed

+220
-151
lines changed

5 files changed

+220
-151
lines changed

Zend/zend_extensions.c

Lines changed: 49 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ zend_result zend_load_extension(const char *path)
6060
#endif
6161
}
6262

63-
zend_result zend_load_extension_handle(DL_HANDLE handle, const char *path)
63+
zend_result zend_load_extension_handle_ex(DL_HANDLE handle, const char *path, bool unload_on_failure, bool silent)
6464
{
6565
#if ZEND_EXTENSIONS_SUPPORT
6666
zend_extension *new_extension;
@@ -74,63 +74,83 @@ zend_result zend_load_extension_handle(DL_HANDLE handle, const char *path)
7474
new_extension = (zend_extension *) DL_FETCH_SYMBOL(handle, "_zend_extension_entry");
7575
}
7676
if (!extension_version_info || !new_extension) {
77-
fprintf(stderr, "%s doesn't appear to be a valid Zend extension\n", path);
77+
if (!silent) {
78+
fprintf(stderr, "%s doesn't appear to be a valid Zend extension\n", path);
79+
}
7880
/* See http://support.microsoft.com/kb/190351 */
7981
#ifdef ZEND_WIN32
8082
fflush(stderr);
8183
#endif
82-
DL_UNLOAD(handle);
84+
if (unload_on_failure) {
85+
DL_UNLOAD(handle);
86+
}
8387
return FAILURE;
8488
}
8589

8690
/* allow extension to proclaim compatibility with any Zend version */
8791
if (extension_version_info->zend_extension_api_no != ZEND_EXTENSION_API_NO &&(!new_extension->api_no_check || new_extension->api_no_check(ZEND_EXTENSION_API_NO) != SUCCESS)) {
8892
if (extension_version_info->zend_extension_api_no > ZEND_EXTENSION_API_NO) {
89-
fprintf(stderr, "%s requires Zend Engine API version %d.\n"
90-
"The Zend Engine API version %d which is installed, is outdated.\n\n",
91-
new_extension->name,
92-
extension_version_info->zend_extension_api_no,
93-
ZEND_EXTENSION_API_NO);
93+
if (!silent) {
94+
fprintf(stderr, "%s requires Zend Engine API version %d.\n"
95+
"The Zend Engine API version %d which is installed, is outdated.\n\n",
96+
new_extension->name,
97+
extension_version_info->zend_extension_api_no,
98+
ZEND_EXTENSION_API_NO);
99+
}
94100
/* See http://support.microsoft.com/kb/190351 */
95101
#ifdef ZEND_WIN32
96102
fflush(stderr);
97103
#endif
98-
DL_UNLOAD(handle);
104+
if (unload_on_failure) {
105+
DL_UNLOAD(handle);
106+
}
99107
return FAILURE;
100108
} else if (extension_version_info->zend_extension_api_no < ZEND_EXTENSION_API_NO) {
101-
fprintf(stderr, "%s requires Zend Engine API version %d.\n"
102-
"The Zend Engine API version %d which is installed, is newer.\n"
103-
"Contact %s at %s for a later version of %s.\n\n",
104-
new_extension->name,
105-
extension_version_info->zend_extension_api_no,
106-
ZEND_EXTENSION_API_NO,
107-
new_extension->author,
108-
new_extension->URL,
109-
new_extension->name);
109+
if (!silent) {
110+
fprintf(stderr, "%s requires Zend Engine API version %d.\n"
111+
"The Zend Engine API version %d which is installed, is newer.\n"
112+
"Contact %s at %s for a later version of %s.\n\n",
113+
new_extension->name,
114+
extension_version_info->zend_extension_api_no,
115+
ZEND_EXTENSION_API_NO,
116+
new_extension->author,
117+
new_extension->URL,
118+
new_extension->name);
119+
}
110120
/* See http://support.microsoft.com/kb/190351 */
111121
#ifdef ZEND_WIN32
112122
fflush(stderr);
113123
#endif
114-
DL_UNLOAD(handle);
124+
if (unload_on_failure) {
125+
DL_UNLOAD(handle);
126+
}
115127
return FAILURE;
116128
}
117129
} else if (strcmp(ZEND_EXTENSION_BUILD_ID, extension_version_info->build_id) &&
118130
(!new_extension->build_id_check || new_extension->build_id_check(ZEND_EXTENSION_BUILD_ID) != SUCCESS)) {
119-
fprintf(stderr, "Cannot load %s - it was built with configuration %s, whereas running engine is %s\n",
120-
new_extension->name, extension_version_info->build_id, ZEND_EXTENSION_BUILD_ID);
131+
if (!silent) {
132+
fprintf(stderr, "Cannot load %s - it was built with configuration %s, whereas running engine is %s\n",
133+
new_extension->name, extension_version_info->build_id, ZEND_EXTENSION_BUILD_ID);
134+
}
121135
/* See http://support.microsoft.com/kb/190351 */
122136
#ifdef ZEND_WIN32
123137
fflush(stderr);
124138
#endif
125-
DL_UNLOAD(handle);
139+
if (unload_on_failure) {
140+
DL_UNLOAD(handle);
141+
}
126142
return FAILURE;
127143
} else if (zend_get_extension(new_extension->name)) {
128-
fprintf(stderr, "Cannot load %s - it was already loaded\n", new_extension->name);
144+
if (!silent) {
145+
fprintf(stderr, "Cannot load %s - it was already loaded\n", new_extension->name);
146+
}
129147
/* See http://support.microsoft.com/kb/190351 */
130148
#ifdef ZEND_WIN32
131149
fflush(stderr);
132150
#endif
133-
DL_UNLOAD(handle);
151+
if (unload_on_failure) {
152+
DL_UNLOAD(handle);
153+
}
134154
return FAILURE;
135155
}
136156

@@ -146,6 +166,11 @@ zend_result zend_load_extension_handle(DL_HANDLE handle, const char *path)
146166
#endif
147167
}
148168

169+
zend_result zend_load_extension_handle(DL_HANDLE handle, const char *path)
170+
{
171+
return zend_load_extension_handle_ex(handle, path, true, false);
172+
}
173+
149174

150175
void zend_register_extension(zend_extension *new_extension, DL_HANDLE handle)
151176
{

Zend/zend_extensions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ ZEND_API void zend_reset_internal_run_time_cache(void);
153153

154154
BEGIN_EXTERN_C()
155155
ZEND_API zend_result zend_load_extension(const char *path);
156+
ZEND_API zend_result zend_load_extension_handle_ex(DL_HANDLE handle, const char *path, bool unload_on_failure, bool silent);
156157
ZEND_API zend_result zend_load_extension_handle(DL_HANDLE handle, const char *path);
157158
ZEND_API void zend_register_extension(zend_extension *new_extension, DL_HANDLE handle);
158159
ZEND_API zend_extension *zend_get_extension(const char *extension_name);

0 commit comments

Comments
 (0)