Skip to content

Commit 5dd9b0d

Browse files
authored
Add php_build_provider() (#18168)
* Add `ZEND_ATTRIBUTE_CONST` to php_version() and php_version_id() * Add `php_build_provider()` * Use `php_build_provider()` internally
1 parent 3142193 commit 5dd9b0d

File tree

4 files changed

+37
-18
lines changed

4 files changed

+37
-18
lines changed

UPGRADING.INTERNALS

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ PHP 8.5 INTERNALS UPGRADE NOTES
2323
for fake closures.
2424
. Added smart_string_append_printf() matching smart_str_append_printf() for
2525
char* instead of zend_string*-based smart strings.
26+
. Added php_build_provider() to retrieve the value of PHP_BUILD_PROVIDER at
27+
runtime.
2628

2729
========================
2830
2. Build system changes

ext/standard/info.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -805,9 +805,9 @@ PHPAPI ZEND_COLD void php_print_info(int flag)
805805
#ifdef PHP_BUILD_SYSTEM
806806
php_info_print_table_row(2, "Build System", PHP_BUILD_SYSTEM);
807807
#endif
808-
#ifdef PHP_BUILD_PROVIDER
809-
php_info_print_table_row(2, "Build Provider", PHP_BUILD_PROVIDER);
810-
#endif
808+
if (php_build_provider()) {
809+
php_info_print_table_row(2, "Build Provider", php_build_provider());
810+
}
811811
#ifdef PHP_BUILD_COMPILER
812812
php_info_print_table_row(2, "Compiler", PHP_BUILD_COMPILER);
813813
#endif

main/main.c

+23-13
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
#include "zend_dtrace.h"
7575
#include "zend_observer.h"
7676
#include "zend_system_id.h"
77+
#include "zend_smart_string.h"
7778

7879
#include "php_content_types.h"
7980
#include "php_ticks.h"
@@ -99,20 +100,30 @@ PHPAPI size_t core_globals_offset;
99100

100101
const char php_build_date[] = __DATE__ " " __TIME__;
101102

102-
PHPAPI const char *php_version(void)
103+
ZEND_ATTRIBUTE_CONST PHPAPI const char *php_version(void)
103104
{
104105
return PHP_VERSION;
105106
}
106107

107-
PHPAPI unsigned int php_version_id(void)
108+
ZEND_ATTRIBUTE_CONST PHPAPI unsigned int php_version_id(void)
108109
{
109110
return PHP_VERSION_ID;
110111
}
111112

113+
ZEND_ATTRIBUTE_CONST PHPAPI const char *php_build_provider(void)
114+
{
115+
#ifdef PHP_BUILD_PROVIDER
116+
return PHP_BUILD_PROVIDER;
117+
#else
118+
return NULL;
119+
#endif
120+
}
121+
112122
PHPAPI char *php_get_version(sapi_module_struct *sapi_module)
113123
{
114-
char *version_info;
115-
spprintf(&version_info, 0, "PHP %s (%s) (built: %s) (%s)\nCopyright (c) The PHP Group\n%s%s",
124+
smart_string version_info = {0};
125+
smart_string_append_printf(&version_info,
126+
"PHP %s (%s) (built: %s) (%s)\n",
116127
PHP_VERSION, sapi_module->name, php_build_date,
117128
#ifdef ZTS
118129
"ZTS"
@@ -131,16 +142,15 @@ PHPAPI char *php_get_version(sapi_module_struct *sapi_module)
131142
#ifdef HAVE_GCOV
132143
" GCOV"
133144
#endif
134-
,
135-
#ifdef PHP_BUILD_PROVIDER
136-
"Built by " PHP_BUILD_PROVIDER "\n"
137-
#else
138-
""
139-
#endif
140-
,
141-
get_zend_version()
142145
);
143-
return version_info;
146+
smart_string_appends(&version_info, "Copyright (c) The PHP Group\n");
147+
if (php_build_provider()) {
148+
smart_string_append_printf(&version_info, "Built by %s\n", php_build_provider());
149+
}
150+
smart_string_appends(&version_info, get_zend_version());
151+
smart_string_0(&version_info);
152+
153+
return version_info.c;
144154
}
145155

146156
PHPAPI void php_print_version(sapi_module_struct *sapi_module)

main/php_main.h

+9-2
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,20 @@ BEGIN_EXTERN_C()
2828
* extensions which want to know the version of PHP at run-time, rather than
2929
* the version they were built with at compile-time.
3030
*/
31-
PHPAPI const char *php_version(void);
31+
ZEND_ATTRIBUTE_CONST PHPAPI const char *php_version(void);
3232

3333
/* Returns the PHP version id the engine was built with. This is useful for
3434
* extensions which want to know the version of PHP at run-time, rather than
3535
* the version they were built with at compile-time.
3636
*/
37-
PHPAPI unsigned int php_version_id(void);
37+
ZEND_ATTRIBUTE_CONST PHPAPI unsigned int php_version_id(void);
38+
39+
/* Returns the build provider specified at build time. NULL is returned if
40+
* no build provider was specified. This is useful for extensions which want
41+
* to know the origin of a PHP binary at run-time, for example to provide
42+
* statistics.
43+
*/
44+
ZEND_ATTRIBUTE_CONST PHPAPI const char *php_build_provider(void);
3845

3946
/* Prints the PHP version string for the -v option. It's in main/ so that
4047
* it can be shared between SAPIs.

0 commit comments

Comments
 (0)