-
Notifications
You must be signed in to change notification settings - Fork 208
PHPC-544, PHPC-592: 64-bit platform detection and integer truncation #241
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
Conversation
f1c7be8
to
5c8e6e1
Compare
@@ -41,20 +41,18 @@ | |||
#include "php_phongo.h" | |||
#include "php_bson.h" | |||
|
|||
|
|||
#define BSON_APPEND_INT32(b,key,val) \ | |||
bson_append_int32 (b, key, (int) strlen (key), val) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This macro wasn't used at all, and it was actually already defined in libbson.
} | ||
|
||
Test { "x": { "$numberLong": "4294967295" }} | ||
[%s] PHONGO-BSON: WARNING > ENTRY: Integer overflow detected on your platform: 4294967295 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't able to create a 64-bit Windows executable due to some DLL issues, so I can't confirm wjether the expected output for this test is accurate. We may need to revise.
df3f1c6
to
f4f906e
Compare
@@ -206,6 +182,35 @@ | |||
# define PHP_STREAM_CONTEXT(stream) ((php_stream_context*) (stream)->context) | |||
#endif | |||
|
|||
#if SIZEOF_PHONGO_LONG == 8 | |||
# define ADD_INDEX_INT64(zval, index, value) add_index_long(zval, index, value) | |||
# define ADD_ASSOC_INT64(zval, key, value) add_assoc_long(zval, key, value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These definitions were moved up to be consistent with bson.c
, where we check for 64-bit platforms first. Additionally, I removed the trailing semi-colon from ADD_ASSOC_INT64()
's definition for consistency.
LGTM - tests work for HHVM too. |
The previous macro uses ZEND_STRL(), which calculates the string length via sizeof() and makes it suitable only for string literals. Since this code is utilized by php_phongo_bson_visit_int64(), we must rely on strlen() to compute the field name length.
Define phongo_long and SIZEOF_PHONGO_LONG in compatibility header. On PHP 7, this will ensure we use zend_long and SIZEOF_ZEND_LONG instead of relying on long and SIZEOF_LONG. Additionally, this adds an else condition to report a build error if the architecture is neither 32-bit nor 64-bit.
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.
https://jira.mongodb.org/browse/PHPC-544
https://jira.mongodb.org/browse/PHPC-592