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
This commit is contained in:
Tim Düsterhus 2025-03-29 13:29:40 +01:00 committed by GitHub
parent 314219387e
commit 5dd9b0dcef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 37 additions and 18 deletions

View file

@ -23,6 +23,8 @@ PHP 8.5 INTERNALS UPGRADE NOTES
for fake closures.
. Added smart_string_append_printf() matching smart_str_append_printf() for
char* instead of zend_string*-based smart strings.
. Added php_build_provider() to retrieve the value of PHP_BUILD_PROVIDER at
runtime.
========================
2. Build system changes

View file

@ -805,9 +805,9 @@ PHPAPI ZEND_COLD void php_print_info(int flag)
#ifdef PHP_BUILD_SYSTEM
php_info_print_table_row(2, "Build System", PHP_BUILD_SYSTEM);
#endif
#ifdef PHP_BUILD_PROVIDER
php_info_print_table_row(2, "Build Provider", PHP_BUILD_PROVIDER);
#endif
if (php_build_provider()) {
php_info_print_table_row(2, "Build Provider", php_build_provider());
}
#ifdef PHP_BUILD_COMPILER
php_info_print_table_row(2, "Compiler", PHP_BUILD_COMPILER);
#endif

View file

@ -74,6 +74,7 @@
#include "zend_dtrace.h"
#include "zend_observer.h"
#include "zend_system_id.h"
#include "zend_smart_string.h"
#include "php_content_types.h"
#include "php_ticks.h"
@ -99,20 +100,30 @@ PHPAPI size_t core_globals_offset;
const char php_build_date[] = __DATE__ " " __TIME__;
PHPAPI const char *php_version(void)
ZEND_ATTRIBUTE_CONST PHPAPI const char *php_version(void)
{
return PHP_VERSION;
}
PHPAPI unsigned int php_version_id(void)
ZEND_ATTRIBUTE_CONST PHPAPI unsigned int php_version_id(void)
{
return PHP_VERSION_ID;
}
ZEND_ATTRIBUTE_CONST PHPAPI const char *php_build_provider(void)
{
#ifdef PHP_BUILD_PROVIDER
return PHP_BUILD_PROVIDER;
#else
return NULL;
#endif
}
PHPAPI char *php_get_version(sapi_module_struct *sapi_module)
{
char *version_info;
spprintf(&version_info, 0, "PHP %s (%s) (built: %s) (%s)\nCopyright (c) The PHP Group\n%s%s",
smart_string version_info = {0};
smart_string_append_printf(&version_info,
"PHP %s (%s) (built: %s) (%s)\n",
PHP_VERSION, sapi_module->name, php_build_date,
#ifdef ZTS
"ZTS"
@ -131,16 +142,15 @@ PHPAPI char *php_get_version(sapi_module_struct *sapi_module)
#ifdef HAVE_GCOV
" GCOV"
#endif
,
#ifdef PHP_BUILD_PROVIDER
"Built by " PHP_BUILD_PROVIDER "\n"
#else
""
#endif
,
get_zend_version()
);
return version_info;
smart_string_appends(&version_info, "Copyright (c) The PHP Group\n");
if (php_build_provider()) {
smart_string_append_printf(&version_info, "Built by %s\n", php_build_provider());
}
smart_string_appends(&version_info, get_zend_version());
smart_string_0(&version_info);
return version_info.c;
}
PHPAPI void php_print_version(sapi_module_struct *sapi_module)

View file

@ -28,13 +28,20 @@ BEGIN_EXTERN_C()
* extensions which want to know the version of PHP at run-time, rather than
* the version they were built with at compile-time.
*/
PHPAPI const char *php_version(void);
ZEND_ATTRIBUTE_CONST PHPAPI const char *php_version(void);
/* Returns the PHP version id the engine was built with. This is useful for
* extensions which want to know the version of PHP at run-time, rather than
* the version they were built with at compile-time.
*/
PHPAPI unsigned int php_version_id(void);
ZEND_ATTRIBUTE_CONST PHPAPI unsigned int php_version_id(void);
/* Returns the build provider specified at build time. NULL is returned if
* no build provider was specified. This is useful for extensions which want
* to know the origin of a PHP binary at run-time, for example to provide
* statistics.
*/
ZEND_ATTRIBUTE_CONST PHPAPI const char *php_build_provider(void);
/* Prints the PHP version string for the -v option. It's in main/ so that
* it can be shared between SAPIs.