Skip to content

Commit 5eb4db5

Browse files
committed
- Ensure that stderr output are not buffered, portability for tests
1 parent d0ab704 commit 5eb4db5

File tree

5 files changed

+68
-0
lines changed

5 files changed

+68
-0
lines changed

Zend/zend_alloc.c

+32
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ static void zend_mm_panic(const char *message) __attribute__ ((noreturn));
8484
static void zend_mm_panic(const char *message)
8585
{
8686
fprintf(stderr, "%s\n", message);
87+
/* See http://support.microsoft.com/kb/190351 */
88+
#ifdef PHP_WIN32
89+
fflush(stderr);
90+
#endif
8791
#if ZEND_DEBUG && defined(HAVE_KILL) && defined(HAVE_GETPID)
8892
kill(getpid(), SIGSEGV);
8993
#endif
@@ -1031,11 +1035,19 @@ ZEND_API zend_mm_heap *zend_mm_startup_ex(const zend_mm_mem_handlers *handlers,
10311035

10321036
if (zend_mm_low_bit(block_size) != zend_mm_high_bit(block_size)) {
10331037
fprintf(stderr, "'block_size' must be a power of two\n");
1038+
/* See http://support.microsoft.com/kb/190351 */
1039+
#ifdef PHP_WIN32
1040+
fflush(stderr);
1041+
#endif
10341042
exit(255);
10351043
}
10361044
storage = handlers->init(params);
10371045
if (!storage) {
10381046
fprintf(stderr, "Cannot initialize zend_mm storage [%s]\n", handlers->name);
1047+
/* See http://support.microsoft.com/kb/190351 */
1048+
#ifdef PHP_WIN32
1049+
fflush(stderr);
1050+
#endif
10391051
exit(255);
10401052
}
10411053
storage->handlers = handlers;
@@ -1118,9 +1130,17 @@ ZEND_API zend_mm_heap *zend_mm_startup(void)
11181130
if (!mem_handlers[i].name) {
11191131
fprintf(stderr, "Wrong or unsupported zend_mm storage type '%s'\n", mem_type);
11201132
fprintf(stderr, " supported types:\n");
1133+
/* See http://support.microsoft.com/kb/190351 */
1134+
#ifdef PHP_WIN32
1135+
fflush(stderr);
1136+
#endif
11211137
for (i = 0; mem_handlers[i].name; i++) {
11221138
fprintf(stderr, " '%s'\n", mem_handlers[i].name);
11231139
}
1140+
/* See http://support.microsoft.com/kb/190351 */
1141+
#ifdef PHP_WIN32
1142+
fflush(stderr);
1143+
#endif
11241144
exit(255);
11251145
}
11261146
}
@@ -1131,9 +1151,17 @@ ZEND_API zend_mm_heap *zend_mm_startup(void)
11311151
seg_size = zend_atoi(tmp, 0);
11321152
if (zend_mm_low_bit(seg_size) != zend_mm_high_bit(seg_size)) {
11331153
fprintf(stderr, "ZEND_MM_SEG_SIZE must be a power of two\n");
1154+
/* See http://support.microsoft.com/kb/190351 */
1155+
#ifdef PHP_WIN32
1156+
fflush(stderr);
1157+
#endif
11341158
exit(255);
11351159
} else if (seg_size < ZEND_MM_ALIGNED_SEGMENT_SIZE + ZEND_MM_ALIGNED_HEADER_SIZE) {
11361160
fprintf(stderr, "ZEND_MM_SEG_SIZE is too small\n");
1161+
/* See http://support.microsoft.com/kb/190351 */
1162+
#ifdef PHP_WIN32
1163+
fflush(stderr);
1164+
#endif
11371165
exit(255);
11381166
}
11391167
} else {
@@ -1672,6 +1700,10 @@ static void zend_mm_safe_error(zend_mm_heap *heap,
16721700
size);
16731701
fprintf(stderr, " in %s on line %d\n", error_filename, error_lineno);
16741702
}
1703+
/* See http://support.microsoft.com/kb/190351 */
1704+
#ifdef PHP_WIN32
1705+
fflush(stderr);
1706+
#endif
16751707
} zend_end_try();
16761708
} else {
16771709
heap->overflow = 2;

Zend/zend_execute.c

+4
Original file line numberDiff line numberDiff line change
@@ -1232,6 +1232,10 @@ static int zend_check_symbol(zval **pz TSRMLS_DC)
12321232
{
12331233
if (Z_TYPE_PP(pz) > 9) {
12341234
fprintf(stderr, "Warning! %x has invalid type!\n", *pz);
1235+
/* See http://support.microsoft.com/kb/190351 */
1236+
#ifdef PHP_WIN32
1237+
fflush(stderr);
1238+
#endif
12351239
} else if (Z_TYPE_PP(pz) == IS_ARRAY) {
12361240
zend_hash_apply(Z_ARRVAL_PP(pz), (apply_func_t) zend_check_symbol TSRMLS_CC);
12371241
} else if (Z_TYPE_PP(pz) == IS_OBJECT) {

Zend/zend_execute_API.c

+4
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ static void zend_handle_sigsegv(int dummy) /* {{{ */
7474
get_active_function_name(TSRMLS_C),
7575
zend_get_executed_filename(TSRMLS_C),
7676
zend_get_executed_lineno(TSRMLS_C));
77+
/* See http://support.microsoft.com/kb/190351 */
78+
#ifdef PHP_WIN32
79+
fflush(stderr);
80+
#endif
7781
}
7882
if (original_sigsegv_handler!=zend_handle_sigsegv) {
7983
original_sigsegv_handler(dummy);

Zend/zend_extensions.c

+24
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ int zend_load_extension(const char *path)
3535
if (!handle) {
3636
#ifndef ZEND_WIN32
3737
fprintf(stderr, "Failed loading %s: %s\n", path, DL_ERROR());
38+
/* See http://support.microsoft.com/kb/190351 */
39+
#ifdef PHP_WIN32
40+
fflush(stderr);
41+
#endif
3842
#else
3943
fprintf(stderr, "Failed loading %s\n", path);
4044
#endif
@@ -51,6 +55,10 @@ int zend_load_extension(const char *path)
5155
}
5256
if (!extension_version_info || !new_extension) {
5357
fprintf(stderr, "%s doesn't appear to be a valid Zend extension\n", path);
58+
/* See http://support.microsoft.com/kb/190351 */
59+
#ifdef PHP_WIN32
60+
fflush(stderr);
61+
#endif
5462
DL_UNLOAD(handle);
5563
return FAILURE;
5664
}
@@ -64,6 +72,10 @@ int zend_load_extension(const char *path)
6472
new_extension->name,
6573
extension_version_info->zend_extension_api_no,
6674
ZEND_EXTENSION_API_NO);
75+
/* See http://support.microsoft.com/kb/190351 */
76+
#ifdef PHP_WIN32
77+
fflush(stderr);
78+
#endif
6779
DL_UNLOAD(handle);
6880
return FAILURE;
6981
} else if (extension_version_info->zend_extension_api_no < ZEND_EXTENSION_API_NO) {
@@ -76,20 +88,32 @@ int zend_load_extension(const char *path)
7688
new_extension->author,
7789
new_extension->URL,
7890
new_extension->name);
91+
/* See http://support.microsoft.com/kb/190351 */
92+
#ifdef PHP_WIN32
93+
fflush(stderr);
94+
#endif
7995
DL_UNLOAD(handle);
8096
return FAILURE;
8197
}
8298
} else if (strcmp(ZEND_EXTENSION_BUILD_ID, extension_version_info->build_id) &&
8399
(!new_extension->build_id_check || new_extension->build_id_check(ZEND_EXTENSION_BUILD_ID) != SUCCESS)) {
84100
fprintf(stderr, "Cannot load %s - it was built with configuration %s, whereas running engine is %s\n",
85101
new_extension->name, extension_version_info->build_id, ZEND_EXTENSION_BUILD_ID);
102+
/* See http://support.microsoft.com/kb/190351 */
103+
#ifdef PHP_WIN32
104+
fflush(stderr);
105+
#endif
86106
DL_UNLOAD(handle);
87107
return FAILURE;
88108
}
89109

90110
return zend_register_extension(new_extension, handle);
91111
#else
92112
fprintf(stderr, "Extensions are not supported on this platform.\n");
113+
/* See http://support.microsoft.com/kb/190351 */
114+
#ifdef PHP_WIN32
115+
fflush(stderr);
116+
#endif
93117
return FAILURE;
94118
#endif
95119
}

main/output.c

+4
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ php_output_globals output_globals;
5050
PHPAPI int php_default_output_func(const char *str, uint str_len TSRMLS_DC)
5151
{
5252
fwrite(str, 1, str_len, stderr);
53+
/* See http://support.microsoft.com/kb/190351 */
54+
#ifdef PHP_WIN32
55+
fflush(stderr);
56+
#endif
5357
return str_len;
5458
}
5559
/* }}} */

0 commit comments

Comments
 (0)