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
4 changes: 4 additions & 0 deletions UPGRADING.INTERNALS
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ PHP 8.7 INTERNALS UPGRADE NOTES
3. Module changes
========================

- Date:
. Added php_date_time_duration_create() to create Time\Duration objects
without going through the userland API.

- MySQLi:
. Removed the reverse API. The mysqlnd_reverse_api.h header, the
MYSQLND_REVERSE_API struct and the functions zval_to_mysqlnd(),
Expand Down
25 changes: 2 additions & 23 deletions ext/date/php_time.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,11 @@
# define PHP_DATE_TIME_H

# include "php.h"
# include "lib/timelib.h"

typedef struct php_date_time_duration {
timelib_duration duration;
zend_object std;
} php_date_time_duration;

# define php_date_time_duration_from_obj(obj) ZEND_CONTAINER_OF(obj, php_date_time_duration, std)

# define Z_DATE_TIME_DURATION_P(zv) php_date_time_duration_from_obj(Z_OBJ_P((zv)))

# define Z_PARAM_DATE_TIME_DURATION(d) { \
zend_object *__##d; \
Z_PARAM_OBJ_OF_CLASS(__##d, php_date_ce_time_duration); \
d = php_date_time_duration_from_obj(__##d); \
}

# define Z_PARAM_DATE_TIME_DURATION_OR_NULL(d) { \
zend_object *__##d; \
Z_PARAM_OBJ_OF_CLASS_OR_NULL(__##d, php_date_ce_time_duration); \
d = __##d ? php_date_time_duration_from_obj(__##d) : NULL; \
}
PHP_MINIT_FUNCTION(date_time);

PHPAPI extern zend_class_entry *php_date_ce_time_duration;
PHPAPI extern zend_class_entry *php_date_ce_time_timeexception;

PHP_MINIT_FUNCTION(date_time);
# include "time_duration.h"

#endif /* PHP_DATE_TIME_H */
17 changes: 9 additions & 8 deletions ext/date/time_duration.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "php_date.h"
#include "php_time.h"
#include "time_duration.h"

#define NANOS_IN_SEC 1000000000
#define NANOS_IN_MICRO 1000
Expand Down Expand Up @@ -113,7 +114,7 @@ ZEND_ATTRIBUTE_NODISCARD static inline zend_result sync_properties(php_date_time
return SUCCESS;
}

ZEND_ATTRIBUTE_NODISCARD static zend_result create_duration(zval *target, zend_ulong seconds, zend_ulong nanoseconds)
ZEND_ATTRIBUTE_NODISCARD PHPAPI zend_result php_date_time_duration_create(zval *target, zend_ulong seconds, zend_ulong nanoseconds)
{
ZEND_ASSERT(nanoseconds < NANOS_IN_SEC);

Expand Down Expand Up @@ -217,7 +218,7 @@ PHP_METHOD(Time_Duration, fromSeconds)
RETURN_THROWS();
}

if (create_duration(return_value, seconds, nanoseconds) == FAILURE) {
if (php_date_time_duration_create(return_value, seconds, nanoseconds) == FAILURE) {
RETURN_THROWS();
}
}
Expand All @@ -233,7 +234,7 @@ PHP_METHOD(Time_Duration, fromNanoseconds)
zend_ulong seconds = nanoseconds / NANOS_IN_SEC;
nanoseconds %= NANOS_IN_SEC;

if (create_duration(return_value, seconds, nanoseconds) == FAILURE) {
if (php_date_time_duration_create(return_value, seconds, nanoseconds) == FAILURE) {
RETURN_THROWS();
}
}
Expand All @@ -249,7 +250,7 @@ PHP_METHOD(Time_Duration, fromMicroseconds)
zend_ulong seconds = microseconds / MICROS_IN_SEC;
zend_ulong nanoseconds = (microseconds % MICROS_IN_SEC) * NANOS_IN_MICRO;

if (create_duration(return_value, seconds, nanoseconds) == FAILURE) {
if (php_date_time_duration_create(return_value, seconds, nanoseconds) == FAILURE) {
RETURN_THROWS();
}
}
Expand All @@ -265,7 +266,7 @@ PHP_METHOD(Time_Duration, fromMilliseconds)
zend_ulong seconds = milliseconds / MILLIS_IN_SEC;
zend_ulong nanoseconds = (milliseconds % MILLIS_IN_SEC) * NANOS_IN_MILLI;

if (create_duration(return_value, seconds, nanoseconds) == FAILURE) {
if (php_date_time_duration_create(return_value, seconds, nanoseconds) == FAILURE) {
RETURN_THROWS();
}
}
Expand All @@ -283,7 +284,7 @@ PHP_METHOD(Time_Duration, fromMinutes)
RETURN_THROWS();
}

if (create_duration(return_value, minutes * 60, /* nanoseconds */ 0) == FAILURE) {
if (php_date_time_duration_create(return_value, minutes * 60, /* nanoseconds */ 0) == FAILURE) {
RETURN_THROWS();
}
}
Expand All @@ -301,7 +302,7 @@ PHP_METHOD(Time_Duration, fromHours)
RETURN_THROWS();
}

if (create_duration(return_value, hours * 3600, /* nanoseconds */ 0) == FAILURE) {
if (php_date_time_duration_create(return_value, hours * 3600, /* nanoseconds */ 0) == FAILURE) {
RETURN_THROWS();
}
}
Expand Down Expand Up @@ -359,7 +360,7 @@ PHP_METHOD(Time_Duration, absolute)
RETURN_COPY(ZEND_THIS);
}

if (create_duration(return_value, original->duration.seconds, original->duration.nanoseconds) == FAILURE) {
if (php_date_time_duration_create(return_value, original->duration.seconds, original->duration.nanoseconds) == FAILURE) {
RETURN_THROWS();
}
}
Expand Down
47 changes: 47 additions & 0 deletions ext/date/time_duration.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
+----------------------------------------------------------------------+
| Copyright © The PHP Group and Contributors. |
+----------------------------------------------------------------------+
| This source file is subject to the Modified BSD License that is |
| bundled with this package in the file LICENSE, and is available |
| through the World Wide Web at <https://www.php.net/license/>. |
| |
| SPDX-License-Identifier: BSD-3-Clause |
+----------------------------------------------------------------------+
| Authors: Derick Rethans <derick@derickrethans.nl> |
| Tim Düsterhus <timwolla@php.net> |
+----------------------------------------------------------------------+
*/

#ifndef PHP_DATE_TIME_DURATION_H
# define PHP_DATE_TIME_DURATION_H

# include "php.h"
# include "lib/timelib.h"

PHPAPI extern zend_class_entry *php_date_ce_time_duration;

typedef struct php_date_time_duration {
timelib_duration duration;
zend_object std;
} php_date_time_duration;

# define php_date_time_duration_from_obj(obj) ZEND_CONTAINER_OF(obj, php_date_time_duration, std)

# define Z_DATE_TIME_DURATION_P(zv) php_date_time_duration_from_obj(Z_OBJ_P((zv)))

# define Z_PARAM_DATE_TIME_DURATION(d) { \
zend_object *__##d; \
Z_PARAM_OBJ_OF_CLASS(__##d, php_date_ce_time_duration); \
d = php_date_time_duration_from_obj(__##d); \
}

# define Z_PARAM_DATE_TIME_DURATION_OR_NULL(d) { \
zend_object *__##d; \
Z_PARAM_OBJ_OF_CLASS_OR_NULL(__##d, php_date_ce_time_duration); \
d = __##d ? php_date_time_duration_from_obj(__##d) : NULL; \
}

ZEND_ATTRIBUTE_NODISCARD PHPAPI zend_result php_date_time_duration_create(zval *target, zend_ulong seconds, zend_ulong nanoseconds);

#endif /* PHP_DATE_TIME_DURATION_H */
2 changes: 1 addition & 1 deletion ext/standard/io_poll.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "io_poll.h"
#include "io_poll_arginfo.h"
#include "io_poll_decl.h"
#include "ext/date/php_time.h"
#include "ext/date/time_duration.h"

/* Class entries */
static zend_class_entry *php_io_poll_backend_class_entry;
Expand Down
Loading