|
41 | 41 | #include "php_phongo.h" |
42 | 42 | #include "php_bson.h" |
43 | 43 |
|
| 44 | + |
| 45 | +#define BSON_APPEND_INT32(b,key,val) \ |
| 46 | + bson_append_int32 (b, key, (int) strlen (key), val) |
| 47 | + |
| 48 | +#if SIZEOF_LONG == 8 |
| 49 | +# define BSON_APPEND_INT(b, key, keylen, val) \ |
| 50 | + if (val > INT_MAX || val < INT_MIN) { \ |
| 51 | + bson_append_int64(b, key, keylen, val); \ |
| 52 | + } else { \ |
| 53 | + bson_append_int32(b, key, keylen, val); \ |
| 54 | + } |
| 55 | +#elif SIZEOF_LONG == 4 |
| 56 | +# define BSON_APPEND_INT(b, key, keylen, val) \ |
| 57 | + bson_append_int32(b, key, keylen, val); |
| 58 | +#endif |
| 59 | + |
44 | 60 | #undef MONGOC_LOG_DOMAIN |
45 | 61 | #define MONGOC_LOG_DOMAIN "PHONGO-BSON" |
46 | 62 |
|
@@ -989,17 +1005,7 @@ static void phongo_bson_append(bson_t *bson, php_phongo_bson_flags_t flags, cons |
989 | 1005 | #endif |
990 | 1006 |
|
991 | 1007 | case IS_LONG: |
992 | | -#if SIZEOF_LONG == 8 || (PHP_VERSION_ID >= 70000 && SIZEOF_ZEND_LONG == 8) |
993 | | - if (val > INT_MAX || val < INT_MIN) { |
994 | | - bson_append_int64(bson, key, keylen, Z_LVAL_P(entry)); |
995 | | - } else { |
996 | | - bson_append_int32(bson, key, keylen, Z_LVAL_P(entry)); |
997 | | - } |
998 | | -#elif SIZEOF_LONG == 4 || (PHP_VERSION_ID >= 70000 && SIZEOF_ZEND_LONG == 4) |
999 | | - bson_append_int32(bson, key, keylen, Z_LVAL_P(entry)); |
1000 | | -#else |
1001 | | -#error Need fix for this architecture |
1002 | | -#endif |
| 1008 | + BSON_APPEND_INT(bson, key, key_len, Z_LVAL_P(entry)); |
1003 | 1009 | break; |
1004 | 1010 |
|
1005 | 1011 | case IS_DOUBLE: |
|
0 commit comments