Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ PHP NEWS
. pg_connect checks if connection_string contains any null byte,
pg_close_stmt check if the statement contains any null byte.
(David Carlier)
. Added pg_service to get the connection current service identifier.
(David Carlier)

- POSIX:
. Added POSIX_SC_OPEN_MAX constant to get the number of file descriptors
Expand Down
1 change: 1 addition & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ PHP 8.5 UPGRADE NOTES
. pg_close_stmt offers an alternative way to close a prepared
statement from the DEALLOCATE sql command in that we can reuse
its name afterwards.
. pg_service returns the ongoing service name of the connection.

- Reflection:
. ReflectionConstant::getFileName() was introduced.
Expand Down
3 changes: 3 additions & 0 deletions ext/pgsql/config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ if test "$PHP_PGSQL" != "no"; then
PHP_CHECK_LIBRARY([pq], [PQclosePrepared],
[AC_DEFINE([HAVE_PG_CLOSE_STMT], [1], [PostgreSQL 17 or later])],,
[$PGSQL_LIBS])
PHP_CHECK_LIBRARY([pq], [PQservice],
[AC_DEFINE([HAVE_PG_SERVICE], [1], [PostgreSQL 18 or later])],,
[$PGSQL_LIBS])

old_CFLAGS=$CFLAGS
CFLAGS="$CFLAGS $PGSQL_CFLAGS"
Expand Down
14 changes: 14 additions & 0 deletions ext/pgsql/pgsql.c
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,7 @@ PHP_FUNCTION(pg_close)
#define PHP_PG_HOST 6
#define PHP_PG_VERSION 7
#define PHP_PG_JIT 8
#define PHP_PG_SERVICE 9

/* php_pgsql_get_link_info */
static void php_pgsql_get_link_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type)
Expand Down Expand Up @@ -991,6 +992,12 @@ static void php_pgsql_get_link_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type
PQclear(res);
return;
}
#if defined(HAVE_PG_SERVICE)
case PHP_PG_SERVICE: {
result = PQservice(pgsql);
break;
}
#endif
EMPTY_SWITCH_DEFAULT_CASE()
}
if (result) {
Expand Down Expand Up @@ -1047,6 +1054,13 @@ PHP_FUNCTION(pg_jit)
php_pgsql_get_link_info(INTERNAL_FUNCTION_PARAM_PASSTHRU,PHP_PG_JIT);
}

#if defined(HAVE_PG_SERVICE)
PHP_FUNCTION(pg_service)
{
php_pgsql_get_link_info(INTERNAL_FUNCTION_PARAM_PASSTHRU,PHP_PG_SERVICE);
}
#endif

/* Returns the value of a server parameter */
PHP_FUNCTION(pg_parameter_status)
{
Expand Down
3 changes: 3 additions & 0 deletions ext/pgsql/pgsql.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,9 @@ function pg_version(?PgSql\Connection $connection = null): array {}
*/
function pg_jit(?PgSql\Connection $connection = null): array {}

#ifdef HAVE_PG_SERVICE
function pg_service(?PgSql\Connection $connection = null): string {}
#endif
/**
* @param PgSql\Connection|string $connection
* @refcount 1
Expand Down
14 changes: 13 additions & 1 deletion ext/pgsql/pgsql_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions ext/pgsql/tests/pg_service.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
PostgreSQL connection service field support
--EXTENSIONS--
pgsql
--SKIPIF--
<?php
include("inc/skipif.inc");
if (!function_exists("pg_service")) die("skip pg_service unsupported");
?>
--FILE--
<?php
include('inc/config.inc');

$db = pg_connect($conn_str);
var_dump(pg_service($db));
pg_close($db);
?>
--EXPECTF--
string(%d) "%A"
33 changes: 20 additions & 13 deletions ext/spl/spl_fixedarray.c
Original file line number Diff line number Diff line change
Expand Up @@ -733,22 +733,29 @@ PHP_METHOD(SplFixedArray, fromArray)
zend_ulong num_index, max_index = 0;
zend_long tmp;

ZEND_HASH_FOREACH_KEY(Z_ARRVAL_P(data), num_index, str_index) {
if (str_index != NULL || (zend_long)num_index < 0) {
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "array must contain only positive integer keys");
if (HT_IS_PACKED(Z_ARRVAL_P(data))) {
/* If there are no holes, then nNumUsed is the number of elements.
* If there are holes, then nNumUsed is the index of the last element. */
tmp = Z_ARRVAL_P(data)->nNumUsed;
} else {
ZEND_HASH_MAP_FOREACH_KEY(Z_ARRVAL_P(data), num_index, str_index) {
if (str_index != NULL || (zend_long)num_index < 0) {
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "array must contain only positive integer keys");
RETURN_THROWS();
}

if (num_index > max_index) {
max_index = num_index;
}
} ZEND_HASH_FOREACH_END();

tmp = max_index + 1;
if (tmp <= 0) {
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "integer overflow detected");
RETURN_THROWS();
}

if (num_index > max_index) {
max_index = num_index;
}
} ZEND_HASH_FOREACH_END();

tmp = max_index + 1;
if (tmp <= 0) {
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "integer overflow detected");
RETURN_THROWS();
}

spl_fixedarray_init(&array, tmp);

ZEND_HASH_FOREACH_NUM_KEY_VAL(Z_ARRVAL_P(data), num_index, element) {
Expand Down
1 change: 0 additions & 1 deletion ext/standard/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ PHPAPI PHP_FUNCTION(fpassthru);

PHP_MINIT_FUNCTION(user_streams);

PHPAPI int php_le_stream_context(void);
PHPAPI zend_result php_copy_file(const char *src, const char *dest);
PHPAPI zend_result php_copy_file_ex(const char *src, const char *dest, int src_flags);
PHPAPI zend_result php_copy_file_ctx(const char *src, const char *dest, int src_flags, php_stream_context *ctx);
Expand Down
4 changes: 4 additions & 0 deletions main/php_streams.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,10 @@ END_EXTERN_C()
#define php_stream_from_res_no_verify(xstr, pzval) (xstr) = (php_stream*)zend_fetch_resource2((res), "stream", php_file_le_stream(), php_file_le_pstream())
#define php_stream_from_zval_no_verify(xstr, pzval) (xstr) = (php_stream*)zend_fetch_resource2_ex((pzval), "stream", php_file_le_stream(), php_file_le_pstream())

static zend_always_inline php_stream* php_stream_from_zval_no_verify_no_error(zval *zval) {
return (php_stream*)zend_fetch_resource2_ex(zval, NULL, php_file_le_stream(), php_file_le_pstream());
}

BEGIN_EXTERN_C()

static zend_always_inline bool php_stream_zend_parse_arg_into_stream(
Expand Down
10 changes: 7 additions & 3 deletions main/streams/php_stream_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@ typedef void (*php_stream_notification_func)(php_stream_context *context,

#define PHP_STREAM_NOTIFIER_PROGRESS 1

/* TODO: Remove dependence on ext/standard/file.h for the default context global */
#define php_stream_context_get_default(without_context) \
(without_context) ? NULL : FG(default_context) ? FG(default_context) : \
(FG(default_context) = php_stream_context_alloc())

/* Attempt to fetch context from the zval passed,
If no context was passed, use the default context
The default context has not yet been created, do it now. */
#define php_stream_context_from_zval(zcontext, nocontext) ( \
(zcontext) ? zend_fetch_resource_ex(zcontext, "Stream-Context", php_le_stream_context()) : \
(nocontext) ? NULL : \
FG(default_context) ? FG(default_context) : \
(FG(default_context) = php_stream_context_alloc()) )
php_stream_context_get_default(nocontext))

#define php_stream_context_to_zval(context, zval) { ZVAL_RES(zval, (context)->res); GC_ADDREF((context)->res); }

Expand All @@ -53,6 +56,7 @@ struct _php_stream_context {
};

BEGIN_EXTERN_C()
PHPAPI int php_le_stream_context(void);
PHPAPI void php_stream_context_free(php_stream_context *context);
PHPAPI php_stream_context *php_stream_context_alloc(void);
PHPAPI zval *php_stream_context_get_option(php_stream_context *context,
Expand Down
Loading