Skip to content

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

Merged
merged 5 commits into from
Feb 29, 2016

Conversation

jmikola
Copy link
Member

@jmikola jmikola commented Feb 24, 2016

@jmikola jmikola force-pushed the phpc-544 branch 3 times, most recently from f1c7be8 to 5c8e6e1 Compare February 25, 2016 18:21
@jmikola jmikola changed the title [WIP] PHPC-544: Unexpected 64-bit integer truncation [WIP] PHPC-544, PHPC-592: 64-bit platform detection and integer truncation Feb 25, 2016
@jmikola jmikola changed the title [WIP] PHPC-544, PHPC-592: 64-bit platform detection and integer truncation PHPC-544, PHPC-592: 64-bit platform detection and integer truncation Feb 25, 2016
@@ -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)
Copy link
Member Author

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
Copy link
Member Author

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.

@jmikola jmikola force-pushed the phpc-544 branch 2 times, most recently from df3f1c6 to f4f906e Compare February 26, 2016 18:44
@@ -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)
Copy link
Member Author

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.

@derickr
Copy link
Contributor

derickr commented Feb 29, 2016

LGTM - tests work for HHVM too.

jmikola added a commit that referenced this pull request Feb 29, 2016
jmikola added a commit that referenced this pull request Feb 29, 2016
This reverts commit f5edbe2, reversing
changes made to 6aaa45d.
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.
@jmikola jmikola merged commit dcd4a6d into mongodb:master Feb 29, 2016
jmikola added a commit that referenced this pull request Feb 29, 2016
@jmikola jmikola deleted the phpc-544 branch February 29, 2016 17:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants