Skip to content

Commit 68dd6cc

Browse files
committed
Control VCRT leak reporting via environment variable in debug builds
Formerly, this had to be enabled by passing the configuration flag `--enable-crt-debug`; now it can be enabled by setting the environment variable `PHP_WIN32_DEBUG_HEAP`. The advantage is that it is no longer necessary to do separate builds, at the cost of a very minor performance penalty during process startup.
1 parent c188797 commit 68dd6cc

File tree

6 files changed

+23
-22
lines changed

6 files changed

+23
-22
lines changed

UPGRADING.INTERNALS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ PHP 8.0 INTERNALS UPGRADE NOTES
135135

136136
c. Windows build system changes
137137

138+
- The configuration option --enable-crt-debug has been removed. The VC
139+
debug heap can now be enabled for debug builds by setting the environment
140+
variable PHP_WIN32_DEBUG_HEAP to a non-negative number before PHP process
141+
startup.
142+
138143
========================
139144
3. Module changes
140145
========================

Zend/zend_portability.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ extern "C++" {
613613
# define ZEND_PREFER_RELOAD
614614
#endif
615615

616-
#if defined(ZEND_WIN32) && defined(_DEBUG) && defined(PHP_WIN32_DEBUG_HEAP)
616+
#if defined(ZEND_WIN32) && defined(_DEBUG)
617617
# define ZEND_IGNORE_LEAKS_BEGIN() _CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) & ~_CRTDBG_ALLOC_MEM_DF)
618618
# define ZEND_IGNORE_LEAKS_END() _CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_ALLOC_MEM_DF)
619619
#else

ext/libxml/config.w32

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ if (PHP_LIBXML == "yes") {
1616
ADD_DEF_FILE("ext\\libxml\\php_libxml2.def");
1717
}
1818
PHP_INSTALL_HEADERS("ext/libxml/", "php_libxml.h");
19-
if (PHP_CRT_DEBUG == "yes") {
20-
ADD_FLAG("CFLAGS_LIBXML", "/D PHP_WIN32_DEBUG_HEAP");
21-
}
2219
} else {
2320
WARNING("libxml support can't be enabled, iconv or libxml are missing")
2421
PHP_LIBXML = "no"

sapi/cli/config.w32

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
// vim:ft=javascript
22

33
ARG_ENABLE('cli', 'Build CLI version of PHP', 'yes');
4-
ARG_ENABLE('crt-debug', 'Enable CRT memory dumps for debugging sent to STDERR', 'no');
54
ARG_ENABLE('cli-win32', 'Build console-less CLI version of PHP', 'no');
65

76
if (PHP_CLI == "yes") {
87
SAPI('cli', 'php_cli.c php_http_parser.c php_cli_server.c php_cli_process_title.c ps_title.c', 'php.exe', '/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1');
98
ADD_FLAG("LIBS_CLI", "ws2_32.lib");
109
ADD_FLAG("LIBS_CLI", "shell32.lib");
11-
if (PHP_CRT_DEBUG == "yes") {
12-
ADD_FLAG("CFLAGS_CLI", "/D PHP_WIN32_DEBUG_HEAP");
13-
}
1410
ADD_FLAG("LDFLAGS_CLI", "/stack:67108864");
1511

1612
if (CHECK_LIB("edit_a.lib;edit.lib", "cli", PHP_CLI) &&

sapi/cli/php_cli.c

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,20 +1184,23 @@ int main(int argc, char *argv[])
11841184

11851185
cli_sapi_module.additional_functions = additional_functions;
11861186

1187-
#if defined(PHP_WIN32) && defined(_DEBUG) && defined(PHP_WIN32_DEBUG_HEAP)
1187+
#if defined(PHP_WIN32) && defined(_DEBUG)
11881188
{
1189-
int tmp_flag;
1190-
_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
1191-
_CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
1192-
_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
1193-
_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
1194-
_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE);
1195-
_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
1196-
tmp_flag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
1197-
tmp_flag |= _CRTDBG_DELAY_FREE_MEM_DF;
1198-
tmp_flag |= _CRTDBG_LEAK_CHECK_DF;
1199-
1200-
_CrtSetDbgFlag(tmp_flag);
1189+
char *tmp = getenv("PHP_WIN32_DEBUG_HEAP");
1190+
if (tmp && zend_atoi(tmp, 0)) {
1191+
int tmp_flag;
1192+
_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
1193+
_CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
1194+
_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
1195+
_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
1196+
_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE);
1197+
_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
1198+
tmp_flag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
1199+
tmp_flag |= _CRTDBG_DELAY_FREE_MEM_DF;
1200+
tmp_flag |= _CRTDBG_LEAK_CHECK_DF;
1201+
1202+
_CrtSetDbgFlag(tmp_flag);
1203+
}
12011204
}
12021205
#endif
12031206

win32/build/confutils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ can be built that way. \
437437
}
438438

439439
var snapshot_build_exclusions = new Array(
440-
'debug', 'crt-debug', 'lzf-better-compression',
440+
'debug', 'lzf-better-compression',
441441
'php-build', 'snapshot-template', 'ereg',
442442
'pcre-regex', 'fastcgi', 'force-cgi-redirect',
443443
'path-info-check', 'zts', 'ipv6', 'memory-limit',

0 commit comments

Comments
 (0)