Skip to content

Commit d2285e1

Browse files
committed
Merge branch 'pull-request/2414'
* pull-request/2414: zend-test extension to house code that is required for testing internal APIs, but that we would not want to expose for regular builds
2 parents ea91c08 + b3ca0c2 commit d2285e1

File tree

14 files changed

+1236
-224
lines changed

14 files changed

+1236
-224
lines changed
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
--TEST--
22
Return type for internal functions
3-
43
--SKIPIF--
54
<?php
6-
if (!function_exists('zend_test_func')) {
7-
print 'skip';
8-
}
9-
5+
if (!function_exists('zend_test_array_return')) die('skip');
6+
// Internal function return types are only checked in debug builds
7+
if (!PHP_DEBUG) die('skip requires debug build');
8+
?>
109
--FILE--
1110
<?php
12-
zend_test_func();
11+
zend_test_array_return();
1312
?>
1413
--EXPECTF--
15-
Fatal error: Return value of zend_test_func() must be of the type array, null returned in %s on line %d
14+
Fatal error: Return value of zend_test_array_return() must be of the type array, null returned in %s on line %d
Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
--TEST--
22
Return type for internal functions 2
3-
43
--SKIPIF--
54
<?php
6-
if (!function_exists('zend_test_func2')) {
7-
print 'skip';
8-
}
9-
5+
if (!function_exists('zend_test_nullable_array_return')) die('skip');
106
--FILE--
117
<?php
12-
zend_test_func2();
13-
echo "==DONE==\n"
8+
zend_test_nullable_array_return();
149
?>
15-
--EXPECTF--
10+
==DONE==
11+
--EXPECT--
1612
==DONE==

Zend/zend_builtin_functions.c

Lines changed: 3 additions & 196 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,6 @@
2929
#include "zend_closures.h"
3030
#include "zend_generators.h"
3131

32-
#undef ZEND_TEST_EXCEPTIONS
33-
34-
#if ZEND_DEBUG
35-
static zend_class_entry *zend_test_interface;
36-
static zend_class_entry *zend_test_class;
37-
static zend_class_entry *zend_test_trait;
38-
static zend_object_handlers zend_test_class_handlers;
39-
#endif
40-
4132
static ZEND_FUNCTION(zend_version);
4233
static ZEND_FUNCTION(func_num_args);
4334
static ZEND_FUNCTION(func_get_arg);
@@ -61,13 +52,6 @@ static ZEND_FUNCTION(interface_exists);
6152
static ZEND_FUNCTION(trait_exists);
6253
static ZEND_FUNCTION(function_exists);
6354
static ZEND_FUNCTION(class_alias);
64-
#if ZEND_DEBUG
65-
static ZEND_FUNCTION(leak);
66-
static ZEND_FUNCTION(leak_variable);
67-
#ifdef ZEND_TEST_EXCEPTIONS
68-
static ZEND_FUNCTION(crash);
69-
#endif
70-
#endif
7155
static ZEND_FUNCTION(get_included_files);
7256
static ZEND_FUNCTION(is_subclass_of);
7357
static ZEND_FUNCTION(is_a);
@@ -93,13 +77,9 @@ static ZEND_FUNCTION(get_extension_funcs);
9377
static ZEND_FUNCTION(get_defined_constants);
9478
static ZEND_FUNCTION(debug_backtrace);
9579
static ZEND_FUNCTION(debug_print_backtrace);
96-
#if ZEND_DEBUG
97-
static ZEND_FUNCTION(zend_test_func);
98-
static ZEND_FUNCTION(zend_test_func2);
99-
#ifdef ZTS
80+
#if ZEND_DEBUG && defined(ZTS)
10081
static ZEND_FUNCTION(zend_thread_id);
10182
#endif
102-
#endif
10383
static ZEND_FUNCTION(gc_mem_caches);
10484
static ZEND_FUNCTION(gc_collect_cycles);
10585
static ZEND_FUNCTION(gc_enabled);
@@ -199,13 +179,6 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_alias, 0, 0, 2)
199179
ZEND_ARG_INFO(0, autoload)
200180
ZEND_END_ARG_INFO()
201181

202-
#if ZEND_DEBUG
203-
ZEND_BEGIN_ARG_INFO_EX(arginfo_leak_variable, 0, 0, 1)
204-
ZEND_ARG_INFO(0, variable)
205-
ZEND_ARG_INFO(0, leak_data)
206-
ZEND_END_ARG_INFO()
207-
#endif
208-
209182
ZEND_BEGIN_ARG_INFO_EX(arginfo_trigger_error, 0, 0, 1)
210183
ZEND_ARG_INFO(0, message)
211184
ZEND_ARG_INFO(0, error_type)
@@ -255,70 +228,8 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_extension_loaded, 0, 0, 1)
255228
ZEND_ARG_INFO(0, extension_name)
256229
ZEND_END_ARG_INFO()
257230

258-
#if ZEND_DEBUG
259-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(arginfo_zend_test_func, IS_ARRAY, 0)
260-
ZEND_END_ARG_INFO()
261-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(arginfo_zend_test_func2, IS_ARRAY, 1)
262-
ZEND_END_ARG_INFO()
263-
#endif
264-
265-
/* }}} */
266-
267-
#if ZEND_DEBUG
268-
static zend_object *zend_test_class_new(zend_class_entry *class_type) /* {{{ */ {
269-
zend_object *obj = zend_objects_new(class_type);
270-
obj->handlers = &zend_test_class_handlers;
271-
return obj;
272-
}
273-
/* }}} */
274-
275-
static zend_function *zend_test_class_method_get(zend_object **object, zend_string *name, const zval *key) /* {{{ */ {
276-
zend_internal_function *fptr = emalloc(sizeof(zend_internal_function));
277-
fptr->type = ZEND_OVERLOADED_FUNCTION_TEMPORARY;
278-
fptr->num_args = 1;
279-
fptr->arg_info = NULL;
280-
fptr->scope = (*object)->ce;
281-
fptr->fn_flags = ZEND_ACC_CALL_VIA_HANDLER;
282-
fptr->function_name = zend_string_copy(name);
283-
fptr->handler = ZEND_FN(zend_test_func);
284-
zend_set_function_arg_flags((zend_function*)fptr);
285-
286-
return (zend_function*)fptr;
287-
}
288-
/* }}} */
289-
290-
static zend_function *zend_test_class_static_method_get(zend_class_entry *ce, zend_string *name) /* {{{ */ {
291-
zend_internal_function *fptr = emalloc(sizeof(zend_internal_function));
292-
fptr->type = ZEND_OVERLOADED_FUNCTION;
293-
fptr->num_args = 1;
294-
fptr->arg_info = NULL;
295-
fptr->scope = ce;
296-
fptr->fn_flags = ZEND_ACC_CALL_VIA_HANDLER|ZEND_ACC_STATIC;
297-
fptr->function_name = name;
298-
fptr->handler = ZEND_FN(zend_test_func);
299-
zend_set_function_arg_flags((zend_function*)fptr);
300-
301-
return (zend_function*)fptr;
302-
}
303-
/* }}} */
304-
305-
static int zend_test_class_call_method(zend_string *method, zend_object *object, INTERNAL_FUNCTION_PARAMETERS) /* {{{ */ {
306-
RETVAL_STR(zend_string_copy(method));
307-
return 0;
308-
}
309-
/* }}} */
310-
311-
static ZEND_METHOD(_ZendTestTrait, testMethod) /* {{{ */ {
312-
RETURN_TRUE;
313-
}
314231
/* }}} */
315232

316-
static zend_function_entry zend_test_trait_methods[] = {
317-
ZEND_ME(_ZendTestTrait, testMethod, arginfo_zend__void, ZEND_ACC_PUBLIC)
318-
ZEND_FE_END
319-
};
320-
#endif
321-
322233
static const zend_function_entry builtin_functions[] = { /* {{{ */
323234
ZEND_FE(zend_version, arginfo_zend__void)
324235
ZEND_FE(func_num_args, arginfo_zend__void)
@@ -343,13 +254,6 @@ static const zend_function_entry builtin_functions[] = { /* {{{ */
343254
ZEND_FE(trait_exists, arginfo_trait_exists)
344255
ZEND_FE(function_exists, arginfo_function_exists)
345256
ZEND_FE(class_alias, arginfo_class_alias)
346-
#if ZEND_DEBUG
347-
ZEND_FE(leak, NULL)
348-
ZEND_FE(leak_variable, arginfo_leak_variable)
349-
#ifdef ZEND_TEST_EXCEPTIONS
350-
ZEND_FE(crash, NULL)
351-
#endif
352-
#endif
353257
ZEND_FE(get_included_files, arginfo_zend__void)
354258
ZEND_FALIAS(get_required_files, get_included_files, arginfo_zend__void)
355259
ZEND_FE(is_subclass_of, arginfo_is_subclass_of)
@@ -377,12 +281,8 @@ static const zend_function_entry builtin_functions[] = { /* {{{ */
377281
ZEND_FE(get_defined_constants, arginfo_get_defined_constants)
378282
ZEND_FE(debug_backtrace, arginfo_debug_backtrace)
379283
ZEND_FE(debug_print_backtrace, arginfo_debug_print_backtrace)
380-
#if ZEND_DEBUG
381-
ZEND_FE(zend_test_func, arginfo_zend_test_func)
382-
ZEND_FE(zend_test_func2, arginfo_zend_test_func2)
383-
#ifdef ZTS
284+
#if ZEND_DEBUG && defined(ZTS)
384285
ZEND_FE(zend_thread_id, NULL)
385-
#endif
386286
#endif
387287
ZEND_FE(gc_mem_caches, arginfo_zend__void)
388288
ZEND_FE(gc_collect_cycles, arginfo_zend__void)
@@ -401,26 +301,6 @@ ZEND_MINIT_FUNCTION(core) { /* {{{ */
401301

402302
zend_register_default_classes();
403303

404-
#if ZEND_DEBUG
405-
INIT_CLASS_ENTRY(class_entry, "_ZendTestInterface", NULL);
406-
zend_test_interface = zend_register_internal_interface(&class_entry);
407-
zend_declare_class_constant_long(zend_test_interface, ZEND_STRL("DUMMY"), 0);
408-
INIT_CLASS_ENTRY(class_entry, "_ZendTestClass", NULL);
409-
zend_test_class = zend_register_internal_class_ex(&class_entry, NULL);
410-
zend_class_implements(zend_test_class, 1, zend_test_interface);
411-
zend_test_class->create_object = zend_test_class_new;
412-
zend_test_class->get_static_method = zend_test_class_static_method_get;
413-
414-
memcpy(&zend_test_class_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
415-
zend_test_class_handlers.get_method = zend_test_class_method_get;
416-
zend_test_class_handlers.call_method = zend_test_class_call_method;
417-
418-
INIT_CLASS_ENTRY(class_entry, "_ZendTestTrait", zend_test_trait_methods);
419-
zend_test_trait = zend_register_internal_class(&class_entry);
420-
zend_test_trait->ce_flags |= ZEND_ACC_TRAIT;
421-
zend_declare_property_null(zend_test_trait, "testProp", sizeof("testProp")-1, ZEND_ACC_PUBLIC);
422-
#endif
423-
424304
return SUCCESS;
425305
}
426306
/* }}} */
@@ -1653,63 +1533,6 @@ ZEND_FUNCTION(class_alias)
16531533
}
16541534
/* }}} */
16551535

1656-
#if ZEND_DEBUG
1657-
/* {{{ proto void leak([int num_bytes])
1658-
Cause an intentional memory leak, for testing/debugging purposes */
1659-
ZEND_FUNCTION(leak)
1660-
{
1661-
zend_long leakbytes = 3;
1662-
1663-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &leakbytes) == FAILURE) {
1664-
return;
1665-
}
1666-
1667-
emalloc(leakbytes);
1668-
}
1669-
/* }}} */
1670-
1671-
/* {{{ proto void leak_variable(mixed variable [, bool leak_data])
1672-
Leak a variable that is a resource or an object */
1673-
ZEND_FUNCTION(leak_variable)
1674-
{
1675-
zval *zv;
1676-
zend_bool leak_data = 0;
1677-
1678-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|b", &zv, &leak_data) == FAILURE) {
1679-
return;
1680-
}
1681-
1682-
if (!leak_data) {
1683-
Z_ADDREF_P(zv);
1684-
} else if (Z_TYPE_P(zv) == IS_RESOURCE) {
1685-
Z_ADDREF_P(zv);
1686-
} else if (Z_TYPE_P(zv) == IS_OBJECT) {
1687-
Z_ADDREF_P(zv);
1688-
} else {
1689-
zend_error(E_WARNING, "Leaking non-zval data is only applicable to resources and objects");
1690-
}
1691-
}
1692-
/* }}} */
1693-
1694-
1695-
#ifdef ZEND_TEST_EXCEPTIONS
1696-
/* {{{ proto void crash(void)
1697-
Crash the script */
1698-
ZEND_FUNCTION(crash)
1699-
{
1700-
char *nowhere = NULL;
1701-
1702-
if (zend_parse_parameters_none() == FAILURE) {
1703-
return;
1704-
}
1705-
1706-
memcpy(nowhere, "something", sizeof("something"));
1707-
}
1708-
/* }}} */
1709-
#endif
1710-
1711-
#endif /* ZEND_DEBUG */
1712-
17131536
/* {{{ proto array get_included_files(void)
17141537
Returns an array with the file names that were include_once()'d */
17151538
ZEND_FUNCTION(get_included_files)
@@ -2095,28 +1918,12 @@ ZEND_FUNCTION(create_function)
20951918
}
20961919
/* }}} */
20971920

2098-
#if ZEND_DEBUG
2099-
ZEND_FUNCTION(zend_test_func)
2100-
{
2101-
zval *arg1, *arg2;
2102-
2103-
zend_parse_parameters(ZEND_NUM_ARGS(), "|zz", &arg1, &arg2);
2104-
}
2105-
2106-
ZEND_FUNCTION(zend_test_func2)
2107-
{
2108-
zval *arg1, *arg2;
2109-
2110-
zend_parse_parameters(ZEND_NUM_ARGS(), "|zz", &arg1, &arg2);
2111-
}
2112-
2113-
#ifdef ZTS
1921+
#if ZEND_DEBUG && defined(ZTS)
21141922
ZEND_FUNCTION(zend_thread_id)
21151923
{
21161924
RETURN_LONG((zend_long)tsrm_thread_id());
21171925
}
21181926
#endif
2119-
#endif
21201927

21211928
/* {{{ proto string get_resource_type(resource res)
21221929
Get the resource type name for a given resource */

appveyor/build_task.bat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ call configure.bat ^
3939
--enable-object-out-dir=%PHP_BUILD_OBJ_DIR% ^
4040
--with-php-build=%DEPS_DIR% ^
4141
%ADD_CONF% ^
42+
--enable-zend-test ^
4243
--with-test-ini-ext-exclude=%EXT_EXCLUDE_FROM_TEST%
4344
if %errorlevel% neq 0 exit /b 3
4445

ext/sockets/tests/socket_export_stream-5.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@ socket_export_stream: effects of leaked handles
55
if (!extension_loaded('sockets')) {
66
die('SKIP sockets extension not available.');
77
}
8-
if (!function_exists('leak_variable'))
8+
if (!function_exists('zend_leak_variable'))
99
die('SKIP only for debug builds');
1010
--FILE--
1111
<?php
1212

1313
$sock0 = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
1414
socket_bind($sock0, '0.0.0.0', 58380);
1515
$stream0 = socket_export_stream($sock0);
16-
leak_variable($stream0, true);
16+
zend_leak_variable($stream0);
1717

1818
$sock1 = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
1919
socket_bind($sock1, '0.0.0.0', 58381);
2020
$stream1 = socket_export_stream($sock1);
21-
leak_variable($sock1, true);
21+
zend_leak_variable($sock1);
2222

2323
echo "Done.\n";
2424
--EXPECT--

ext/sockets/tests/socket_import_stream-5.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ socket_import_stream: effects of leaked handles
55
if (!extension_loaded('sockets')) {
66
die('SKIP sockets extension not available.');
77
}
8-
if (!function_exists('leak_variable'))
8+
if (!function_exists('zend_leak_variable'))
99
die('SKIP only for debug builds');
1010
--FILE--
1111
<?php
1212

1313
$stream0 = stream_socket_server("udp://0.0.0.0:58380", $errno, $errstr, STREAM_SERVER_BIND);
1414
$sock0 = socket_import_stream($stream0);
15-
leak_variable($stream0, true);
15+
zend_leak_variable($stream0);
1616

1717
$stream1 = stream_socket_server("udp://0.0.0.0:58381", $errno, $errstr, STREAM_SERVER_BIND);
1818
$sock1 = socket_import_stream($stream1);
19-
leak_variable($sock1, true);
19+
zend_leak_variable($sock1);
2020

2121
echo "Done.\n";
2222
--EXPECT--

ext/standard/tests/file/bug52820.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Bug #52820 (writes to fopencookie FILE* not committed when seeking the stream)
33
--SKIPIF--
44
<?php
5-
if (!function_exists('leak_variable'))
5+
if (!function_exists('zend_leak_variable'))
66
die("skip only for debug builds");
77
/* unfortunately no standard function does a cast to FILE*, so we need
88
* curl to test this */
@@ -33,10 +33,10 @@ echo "\nmemory stream (close after):\n";
3333
fclose(do_stuff("php://memory"));
3434

3535
echo "\ntemp stream (leak):\n";
36-
leak_variable(do_stuff("php://temp"), true);
36+
zend_leak_variable(do_stuff("php://temp"));
3737

3838
echo "\nmemory stream (leak):\n";
39-
leak_variable(do_stuff("php://memory"), true);
39+
zend_leak_variable(do_stuff("php://memory"));
4040

4141
echo "\nDone.\n";
4242
--EXPECTF--

0 commit comments

Comments
 (0)