Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch strtotime() to return float() to support more dates than 32bit integers WASM uses by default #181

Closed
wants to merge 1 commit into from
Closed
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
77 changes: 77 additions & 0 deletions packages/php-wasm/compile/build-assets/php5.6.patch
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,80 @@ index 0603a7212b..2c191bc8be 100644
}
# endif

diff --git a/php-src/ext/date/lib/timelib_structs.h b/php-src/ext/date/lib/timelib_structs.h
index 91fcac9119..12cd932f7f 100644
--- a/php-src/ext/date/lib/timelib_structs.h
+++ b/php-src/ext/date/lib/timelib_structs.h
@@ -125,7 +125,7 @@ typedef unsigned __int64 uint64_t;
#include <strings.h>
#endif

-#if (defined(__x86_64__) || defined(__LP64__) || defined(_LP64) || defined(_WIN64)) && !defined(TIMELIB_FORCE_LONG32)
+#if true
typedef int64_t timelib_long;
typedef uint64_t timelib_ulong;
# define TIMELIB_LONG_MAX INT64_MAX
@@ -143,10 +143,10 @@ typedef uint32_t timelib_ulong;
# define TIMELIB_ULONG_FMT "%" PRIu32
#endif

-#if defined(_MSC_VER)
+#if true
typedef uint64_t timelib_ull;
typedef int64_t timelib_sll;
-# define TIMELIB_LL_CONST(n) n ## i64
+# define TIMELIB_LL_CONST(n) n ## ll
#else
typedef unsigned long long timelib_ull;
typedef signed long long timelib_sll;
diff --git a/php-src/ext/date/php_date.c b/php-src/ext/date/php_date.c
index 801208d714..640b8a8c33 100644
--- a/php-src/ext/date/php_date.c
+++ b/php-src/ext/date/php_date.c
@@ -1454,9 +1454,11 @@ PHP_FUNCTION(strtotime)
char *times, *initial_ts;
int time_len, error1, error2;
struct timelib_error_container *error;
- long preset_ts = 0, ts;
+ long preset_ts = 0;
+ double ts;
+ double t;

- timelib_time *t, *now;
+ timelib_time *now;
timelib_tzinfo *tzi;

tzi = get_timezone_info(TSRMLS_C);
@@ -1467,7 +1469,7 @@ PHP_FUNCTION(strtotime)

initial_ts = emalloc(25);
snprintf(initial_ts, 24, "@%ld UTC", preset_ts);
- t = timelib_strtotime(initial_ts, strlen(initial_ts), NULL, DATE_TIMEZONEDB, php_date_parse_tzfile_wrapper); /* we ignore the error here, as this should never fail */
+ t = (double)timelib_strtotime(initial_ts, strlen(initial_ts), NULL, DATE_TIMEZONEDB, php_date_parse_tzfile_wrapper); /* we ignore the error here, as this should never fail */
timelib_update_ts(t, tzi);
now->tz_info = tzi;
now->zone_type = TIMELIB_ZONETYPE_ID;
@@ -1489,12 +1491,12 @@ PHP_FUNCTION(strtotime)
RETURN_FALSE;
}

- t = timelib_strtotime(times, time_len, &error, DATE_TIMEZONEDB, php_date_parse_tzfile_wrapper);
+ t = (double)timelib_strtotime(times, time_len, &error, DATE_TIMEZONEDB, php_date_parse_tzfile_wrapper);
error1 = error->error_count;
timelib_error_container_dtor(error);
timelib_fill_holes(t, now, TIMELIB_NO_CLONE);
timelib_update_ts(t, tzi);
- ts = timelib_date_to_int(t, &error2);
+ ts = (double)timelib_date_to_int(t, &error2);

timelib_time_dtor(now);
timelib_time_dtor(t);
@@ -1502,7 +1504,7 @@ PHP_FUNCTION(strtotime)
if (error1 || error2) {
RETURN_FALSE;
} else {
- RETURN_LONG(ts);
+ RETURN_DOUBLE(ts);
}
}
/* }}} */
58 changes: 58 additions & 0 deletions packages/php-wasm/compile/build-assets/php7.0.patch
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,61 @@ diff --git a/php-src/main/streams/cast.c b/php-src/main/streams/cast.c
}
# endif

diff --git a/php-src/ext/date/lib/timelib.h b/php-src/ext/date/lib/timelib.h
index c9b3928799..97bbccc232 100644
--- a/php-src/ext/date/lib/timelib.h
+++ b/php-src/ext/date/lib/timelib.h
@@ -103,7 +103,7 @@ typedef unsigned __int64 uint64_t;
# endif
#endif

-#if (defined(__x86_64__) || defined(__LP64__) || defined(_LP64) || defined(_WIN64)) && !defined(TIMELIB_FORCE_LONG32)
+#if true
typedef int64_t timelib_long;
typedef uint64_t timelib_ulong;
# define TIMELIB_LONG_MAX INT64_MAX
@@ -121,10 +121,10 @@ typedef uint32_t timelib_ulong;
# define TIMELIB_ULONG_FMT "%" PRIu32
#endif

-#if defined(_MSC_VER)
+#if true
typedef uint64_t timelib_ull;
typedef int64_t timelib_sll;
-# define TIMELIB_LL_CONST(n) n ## i64
+# define TIMELIB_LL_CONST(n) n ## ll
#else
typedef unsigned long long timelib_ull;
typedef signed long long timelib_sll;
diff --git a/php-src/ext/date/php_date.c b/php-src/ext/date/php_date.c
index fdf84f6056..a94b1958c3 100644
--- a/php-src/ext/date/php_date.c
+++ b/php-src/ext/date/php_date.c
@@ -1502,7 +1502,8 @@ PHP_FUNCTION(strtotime)
zend_string *times;
int error1, error2;
timelib_error_container *error;
- zend_long preset_ts = 0, ts;
+ zend_long preset_ts = 0;
+ double ts;
timelib_time *t, *now;
timelib_tzinfo *tzi;

@@ -1526,7 +1527,7 @@ PHP_FUNCTION(strtotime)
timelib_error_container_dtor(error);
timelib_fill_holes(t, now, TIMELIB_NO_CLONE);
timelib_update_ts(t, tzi);
- ts = timelib_date_to_int(t, &error2);
+ ts = (double)timelib_date_to_int(t, &error2);

timelib_time_dtor(now);
timelib_time_dtor(t);
@@ -1534,7 +1535,7 @@ PHP_FUNCTION(strtotime)
if (error1 || error2) {
RETURN_FALSE;
} else {
- RETURN_LONG(ts);
+ RETURN_DOUBLE(ts);
}
}
/* }}} */
58 changes: 58 additions & 0 deletions packages/php-wasm/compile/build-assets/php7.1.patch
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,61 @@ diff --git a/php-src/main/streams/cast.c b/php-src/main/streams/cast.c
}
# endif

diff --git a/php-src/ext/date/lib/timelib.h b/php-src/ext/date/lib/timelib.h
index c9b3928799..97bbccc232 100644
--- a/php-src/ext/date/lib/timelib.h
+++ b/php-src/ext/date/lib/timelib.h
@@ -103,7 +103,7 @@ typedef unsigned __int64 uint64_t;
# endif
#endif

-#if (defined(__x86_64__) || defined(__LP64__) || defined(_LP64) || defined(_WIN64)) && !defined(TIMELIB_FORCE_LONG32)
+#if true
typedef int64_t timelib_long;
typedef uint64_t timelib_ulong;
# define TIMELIB_LONG_MAX INT64_MAX
@@ -121,10 +121,10 @@ typedef uint32_t timelib_ulong;
# define TIMELIB_ULONG_FMT "%" PRIu32
#endif

-#if defined(_MSC_VER)
+#if true
typedef uint64_t timelib_ull;
typedef int64_t timelib_sll;
-# define TIMELIB_LL_CONST(n) n ## i64
+# define TIMELIB_LL_CONST(n) n ## ll
#else
typedef unsigned long long timelib_ull;
typedef signed long long timelib_sll;
diff --git a/php-src/ext/date/php_date.c b/php-src/ext/date/php_date.c
index fdf84f6056..a94b1958c3 100644
--- a/php-src/ext/date/php_date.c
+++ b/php-src/ext/date/php_date.c
@@ -1502,7 +1502,8 @@ PHP_FUNCTION(strtotime)
zend_string *times;
int error1, error2;
timelib_error_container *error;
- zend_long preset_ts = 0, ts;
+ zend_long preset_ts = 0;
+ double ts;
timelib_time *t, *now;
timelib_tzinfo *tzi;

@@ -1526,7 +1527,7 @@ PHP_FUNCTION(strtotime)
timelib_error_container_dtor(error);
timelib_fill_holes(t, now, TIMELIB_NO_CLONE);
timelib_update_ts(t, tzi);
- ts = timelib_date_to_int(t, &error2);
+ ts = (double)timelib_date_to_int(t, &error2);

timelib_time_dtor(now);
timelib_time_dtor(t);
@@ -1534,7 +1535,7 @@ PHP_FUNCTION(strtotime)
if (error1 || error2) {
RETURN_FALSE;
} else {
- RETURN_LONG(ts);
+ RETURN_DOUBLE(ts);
}
}
/* }}} */
70 changes: 56 additions & 14 deletions packages/php-wasm/compile/build-assets/php7.2.patch
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,61 @@ diff --git a/php-src/ext/standard/file.c b/php-src/ext/standard/file.c
php_error_docref(NULL, E_WARNING, "The first argument to copy() function cannot be a directory");
return FAILURE;
}
diff --git a/php-src/main/streams/cast.c b/php-src/main/streams/cast.c
--- a/php-src/main/streams/cast.c
+++ b/php-src/main/streams/cast.c
@@ -113,10 +113,10 @@ static int stream_cookie_seeker(void *cookie, __off64_t *position, int whence)
return 0;
}
# else
-static int stream_cookie_seeker(void *cookie, zend_off_t position, int whence)
+static int stream_cookie_seeker(void *cookie, long long *position, int whence)
{

- return php_stream_seek((php_stream *)cookie, position, whence);
+ return php_stream_seek((php_stream *)cookie, *position, whence);
}
diff --git a/php-src/ext/date/lib/timelib.h b/php-src/ext/date/lib/timelib.h
index c9b3928799..97bbccc232 100644
--- a/php-src/ext/date/lib/timelib.h
+++ b/php-src/ext/date/lib/timelib.h
@@ -103,7 +103,7 @@ typedef unsigned __int64 uint64_t;
# endif
#endif

-#if (defined(__x86_64__) || defined(__LP64__) || defined(_LP64) || defined(_WIN64)) && !defined(TIMELIB_FORCE_LONG32)
+#if true
typedef int64_t timelib_long;
typedef uint64_t timelib_ulong;
# define TIMELIB_LONG_MAX INT64_MAX
@@ -121,10 +121,10 @@ typedef uint32_t timelib_ulong;
# define TIMELIB_ULONG_FMT "%" PRIu32
#endif

-#if defined(_MSC_VER)
+#if true
typedef uint64_t timelib_ull;
typedef int64_t timelib_sll;
-# define TIMELIB_LL_CONST(n) n ## i64
+# define TIMELIB_LL_CONST(n) n ## ll
#else
typedef unsigned long long timelib_ull;
typedef signed long long timelib_sll;
diff --git a/php-src/ext/date/php_date.c b/php-src/ext/date/php_date.c
index fdf84f6056..a94b1958c3 100644
--- a/php-src/ext/date/php_date.c
+++ b/php-src/ext/date/php_date.c
@@ -1502,7 +1502,8 @@ PHP_FUNCTION(strtotime)
zend_string *times;
int error1, error2;
timelib_error_container *error;
- zend_long preset_ts = 0, ts;
+ zend_long preset_ts = 0;
+ double ts;
timelib_time *t, *now;
timelib_tzinfo *tzi;

@@ -1526,7 +1527,7 @@ PHP_FUNCTION(strtotime)
timelib_error_container_dtor(error);
timelib_fill_holes(t, now, TIMELIB_NO_CLONE);
timelib_update_ts(t, tzi);
- ts = timelib_date_to_int(t, &error2);
+ ts = (double)timelib_date_to_int(t, &error2);

timelib_time_dtor(now);
timelib_time_dtor(t);
@@ -1534,7 +1535,7 @@ PHP_FUNCTION(strtotime)
if (error1 || error2) {
RETURN_FALSE;
} else {
- RETURN_LONG(ts);
+ RETURN_DOUBLE(ts);
}
}
/* }}} */
58 changes: 58 additions & 0 deletions packages/php-wasm/compile/build-assets/php7.3.patch
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,61 @@ diff --git a/php-src/main/streams/cast.c b/php-src/main/streams/cast.c
}
# endif

diff --git a/php-src/ext/date/lib/timelib.h b/php-src/ext/date/lib/timelib.h
index 29e95e5e87..4328aa81d5 100644
--- a/php-src/ext/date/lib/timelib.h
+++ b/php-src/ext/date/lib/timelib.h
@@ -105,7 +105,7 @@ typedef unsigned __int64 uint64_t;
# endif
#endif

-#if (defined(__x86_64__) || defined(__LP64__) || defined(_LP64) || defined(_WIN64)) && !defined(TIMELIB_FORCE_LONG32)
+#if true
typedef int64_t timelib_long;
typedef uint64_t timelib_ulong;
# define TIMELIB_LONG_MAX INT64_MAX
@@ -123,10 +123,10 @@ typedef uint32_t timelib_ulong;
# define TIMELIB_ULONG_FMT "%" PRIu32
#endif

-#if defined(_MSC_VER)
+#if true
typedef uint64_t timelib_ull;
typedef int64_t timelib_sll;
-# define TIMELIB_LL_CONST(n) n ## i64
+# define TIMELIB_LL_CONST(n) n ## ll
#else
typedef unsigned long long timelib_ull;
typedef signed long long timelib_sll;
diff --git a/php-src/ext/date/php_date.c b/php-src/ext/date/php_date.c
index e1a427c5ca..cd48ff2633 100644
--- a/php-src/ext/date/php_date.c
+++ b/php-src/ext/date/php_date.c
@@ -1509,7 +1509,8 @@ PHP_FUNCTION(strtotime)
zend_string *times;
int error1, error2;
timelib_error_container *error;
- zend_long preset_ts = 0, ts;
+ zend_long preset_ts = 0;
+ double ts;
timelib_time *t, *now;
timelib_tzinfo *tzi;

@@ -1533,7 +1534,7 @@ PHP_FUNCTION(strtotime)
timelib_error_container_dtor(error);
timelib_fill_holes(t, now, TIMELIB_NO_CLONE);
timelib_update_ts(t, tzi);
- ts = timelib_date_to_int(t, &error2);
+ ts = (double)timelib_date_to_int(t, &error2);

timelib_time_dtor(now);
timelib_time_dtor(t);
@@ -1541,7 +1542,7 @@ PHP_FUNCTION(strtotime)
if (error1 || error2) {
RETURN_FALSE;
} else {
- RETURN_LONG(ts);
+ RETURN_DOUBLE(ts);
}
}
/* }}} */
Loading