Skip to content

Commit ba63cee

Browse files
committed
PHPC-544: Use phongo_long in UTCDateTime ctor
This ensures that we properly check for 64-bit support in PHP 7. Additionally, we relocate variable declarations and consolidate the conditionals so that "milliseconds" is only declared when used.
1 parent 6bcba59 commit ba63cee

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

src/BSON/UTCDateTime.c

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,30 +52,36 @@ PHP_METHOD(UTCDateTime, __construct)
5252
{
5353
php_phongo_utcdatetime_t *intern;
5454
zend_error_handling error_handling;
55-
long milliseconds;
56-
#if SIZEOF_LONG == 4
57-
char *s_milliseconds;
58-
int s_milliseconds_len;
59-
#endif
6055

6156

6257
zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling TSRMLS_CC);
6358
intern = Z_UTCDATETIME_OBJ_P(getThis());
6459

65-
#if SIZEOF_LONG == 4
66-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &s_milliseconds, &s_milliseconds_len) == FAILURE) {
67-
zend_restore_error_handling(&error_handling TSRMLS_CC);
68-
return;
69-
}
60+
#if SIZEOF_PHONGO_LONG == 8
61+
{
62+
phongo_long milliseconds;
7063

71-
intern->milliseconds = STRTOLL(s_milliseconds);
72-
#else
73-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &milliseconds) == FAILURE) {
74-
zend_restore_error_handling(&error_handling TSRMLS_CC);
75-
return;
64+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &milliseconds) == FAILURE) {
65+
zend_restore_error_handling(&error_handling TSRMLS_CC);
66+
return;
67+
}
68+
69+
intern->milliseconds = milliseconds;
7670
}
71+
#elif SIZEOF_PHONGO_LONG == 4
72+
{
73+
char *s_milliseconds;
74+
phongo_zpp_char_len s_milliseconds_len;
7775

78-
intern->milliseconds = milliseconds;
76+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &s_milliseconds, &s_milliseconds_len) == FAILURE) {
77+
zend_restore_error_handling(&error_handling TSRMLS_CC);
78+
return;
79+
}
80+
81+
intern->milliseconds = STRTOLL(s_milliseconds);
82+
}
83+
#else
84+
# error Unsupported architecture (integers are neither 32-bit nor 64-bit)
7985
#endif
8086

8187
zend_restore_error_handling(&error_handling TSRMLS_CC);

0 commit comments

Comments
 (0)