Skip to content

Commit e51a184

Browse files
committed
Merged pull request #737
2 parents 78073a8 + d0d3cc7 commit e51a184

23 files changed

+88
-47
lines changed

phongo_compat.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -143,22 +143,22 @@
143143
# define ADD_ASSOC_INT64(zval, key, value) add_assoc_long(zval, key, value)
144144
#elif SIZEOF_PHONGO_LONG == 4
145145
# define ADD_INDEX_INT64(zval, index, value) \
146-
if (value > INT32_MAX || value < INT32_MIN) { \
147-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Integer overflow detected on your platform: %lld", value); \
146+
if ((value) > INT32_MAX || (value) < INT32_MIN) { \
147+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Integer overflow detected on your platform: %lld", (value)); \
148148
} else { \
149-
add_index_long(zval, index, value); \
149+
add_index_long(zval, index, (value)); \
150150
}
151151
# define ADD_NEXT_INDEX_INT64(zval, value) \
152-
if (value > INT32_MAX || value < INT32_MIN) { \
153-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Integer overflow detected on your platform: %lld", value); \
152+
if ((value) > INT32_MAX || (value) < INT32_MIN) { \
153+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Integer overflow detected on your platform: %lld", (value)); \
154154
} else { \
155-
add_next_index_long(zval, value); \
155+
add_next_index_long(zval, (value)); \
156156
}
157157
# define ADD_ASSOC_INT64(zval, key, value) \
158-
if (value > INT32_MAX || value < INT32_MIN) { \
159-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Integer overflow detected on your platform: %lld", value); \
158+
if ((value) > INT32_MAX || (value) < INT32_MIN) { \
159+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Integer overflow detected on your platform: %lld", (value)); \
160160
} else { \
161-
add_assoc_long(zval, key, value); \
161+
add_assoc_long(zval, key, (value)); \
162162
}
163163
#else
164164
# error Unsupported architecture (integers are neither 32-bit nor 64-bit)

php_phongo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ static void php_phongo_log(mongoc_log_level_t log_level, const char *log_domain,
230230

231231
dt = php_format_date((char *) ZEND_STRL("Y-m-d\\TH:i:s"), t, 0 TSRMLS_CC);
232232

233-
fprintf(MONGODB_G(debug_fd), "[%s.%06lu+00:00] %10s: %-8s> %s\n", ZSTR_VAL(dt), tu, log_domain, mongoc_log_level_str(log_level), message);
233+
fprintf(MONGODB_G(debug_fd), "[%s.%06" PHONGO_LONG_FORMAT "+00:00] %10s: %-8s> %s\n", ZSTR_VAL(dt), tu, log_domain, mongoc_log_level_str(log_level), message);
234234
fflush(MONGODB_G(debug_fd));
235235
efree(dt);
236236
}

scripts/convert-bson-corpus-tests.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
'Top-level document validity: Bad $date (number, not string or hash)' => 'Legacy extended JSON $date syntax uses numbers (CDRIVER-2223)',
1515
];
1616

17+
$for64bitOnly = [
18+
'Int64 type: MinValue' => "Can't represent 64-bit ints on a 32-bit platform",
19+
'Int64 type: MaxValue' => "Can't represent 64-bit ints on a 32-bit platform",
20+
];
21+
1722
$outputPath = realpath(__DIR__ . '/../tests') . '/bson-corpus/';
1823

1924
if ( ! is_dir($outputPath) && ! mkdir($outputPath, 0755, true)) {
@@ -42,7 +47,7 @@
4247
foreach ($test['valid'] as $i => $case) {
4348
$outputFile = sprintf('%s-valid-%03d.phpt', pathinfo($inputFile, PATHINFO_FILENAME), $i + 1);
4449
try {
45-
$output = renderPhpt(getParamsForValid($test, $case), $expectedFailures);
50+
$output = renderPhpt(getParamsForValid($test, $case), $expectedFailures, $for64bitOnly);
4651
} catch (Exception $e) {
4752
printf("Error processing valid[%d] in %s: %s\n", $i, $inputFile, $e->getMessage());
4853
continue;
@@ -59,7 +64,7 @@
5964
foreach ($test['decodeErrors'] as $i => $case) {
6065
$outputFile = sprintf('%s-decodeError-%03d.phpt', pathinfo($inputFile, PATHINFO_FILENAME), $i + 1);
6166
try {
62-
$output = renderPhpt(getParamsForDecodeError($test, $case), $expectedFailures);
67+
$output = renderPhpt(getParamsForDecodeError($test, $case), $expectedFailures, $for64bitOnly);
6368
} catch (Exception $e) {
6469
printf("Error processing decodeErrors[%d] in %s: %s\n", $i, $inputFile, $e->getMessage());
6570
continue;
@@ -76,7 +81,7 @@
7681
foreach ($test['parseErrors'] as $i => $case) {
7782
$outputFile = sprintf('%s-parseError-%03d.phpt', pathinfo($inputFile, PATHINFO_FILENAME), $i + 1);
7883
try {
79-
$output = renderPhpt(getParamsForParseError($test, $case), $expectedFailures);
84+
$output = renderPhpt(getParamsForParseError($test, $case), $expectedFailures, $for64bitOnly);
8085
} catch (Exception $e) {
8186
printf("Error processing parseErrors[%d] in %s: %s\n", $i, $inputFile, $e->getMessage());
8287
continue;
@@ -263,16 +268,19 @@ function getParamsForParseError(array $test, array $case)
263268
];
264269
}
265270

266-
function renderPhpt(array $params, array $expectedFailures)
271+
function renderPhpt(array $params, array $expectedFailures, array $for64bitOnly)
267272
{
268273
$params['%XFAIL%'] = isset($expectedFailures[$params['%NAME%']])
269274
? "--XFAIL--\n" . $expectedFailures[$params['%NAME%']] . "\n"
270275
: '';
276+
$params['%SKIPIF%'] = isset($for64bitOnly[$params['%NAME%']])
277+
? "--SKIPIF--\n" . "<?php if (PHP_INT_SIZE !== 8) { die(\"skip {$for64bitOnly[$params['%NAME%']]}\"); } ?>" . "\n"
278+
: '';
271279

272280
$template = <<< 'TEMPLATE'
273281
--TEST--
274282
%NAME%
275-
%XFAIL%--DESCRIPTION--
283+
%XFAIL%%SKIPIF%--DESCRIPTION--
276284
Generated by scripts/convert-bson-corpus-tests.php
277285
278286
DO NOT EDIT THIS FILE

src/MongoDB/Monitoring/CommandFailedEvent.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ static HashTable *php_phongo_commandfailedevent_get_debug_info(zval *object, int
214214
array_init_size(&retval, 6);
215215

216216
ADD_ASSOC_STRING(&retval, "commandName", intern->command_name);
217-
ADD_ASSOC_INT64(&retval, "durationMicros", intern->duration_micros);
217+
ADD_ASSOC_INT64(&retval, "durationMicros", (int64_t) intern->duration_micros);
218218

219219
#if PHP_VERSION_ID >= 70000
220220
ADD_ASSOC_ZVAL_EX(&retval, "error", &intern->z_error);

src/MongoDB/Monitoring/CommandSucceededEvent.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ static HashTable *php_phongo_commandsucceededevent_get_debug_info(zval *object,
216216
array_init_size(&retval, 6);
217217

218218
ADD_ASSOC_STRING(&retval, "commandName", intern->command_name);
219-
ADD_ASSOC_INT64(&retval, "durationMicros", intern->duration_micros);
219+
ADD_ASSOC_INT64(&retval, "durationMicros", (int64_t) intern->duration_micros);
220220

221221
sprintf(operation_id, "%" PHONGO_LONG_FORMAT, intern->operation_id);
222222
ADD_ASSOC_STRING(&retval, "operationId", operation_id);

tests/bson-corpus/int64-valid-001.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
--TEST--
22
Int64 type: MinValue
3+
--SKIPIF--
4+
<?php if (PHP_INT_SIZE !== 8) { die("skip Can't represent 64-bit ints on a 32-bit platform"); } ?>
35
--DESCRIPTION--
46
Generated by scripts/convert-bson-corpus-tests.php
57

tests/bson-corpus/int64-valid-002.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
--TEST--
22
Int64 type: MaxValue
3+
--SKIPIF--
4+
<?php if (PHP_INT_SIZE !== 8) { die("skip Can't represent 64-bit ints on a 32-bit platform"); } ?>
35
--DESCRIPTION--
46
Generated by scripts/convert-bson-corpus-tests.php
57

tests/bson/bson-timestamp_error-003.phpt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,18 @@ echo throws(function() {
1010
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n";
1111

1212
echo throws(function() {
13-
new MongoDB\BSON\Timestamp(-2147483648, 0);
13+
/* I realise that "-2147483647 - 1" could be written as "-2147483648", *however*, PHP considers
14+
* the latter a floating point number, as it parses "-" and "2147483648" separately, and
15+
* "2147483648" doesn't fit in the 32-bit signed range. */
16+
new MongoDB\BSON\Timestamp(-2147483647 - 1, 0);
1417
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n";
1518

1619
echo throws(function() {
1720
new MongoDB\BSON\Timestamp(0, -1);
1821
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n";
1922

2023
echo throws(function() {
21-
new MongoDB\BSON\Timestamp(0, -2147483648);
24+
new MongoDB\BSON\Timestamp(0, -2147483647 - 1);
2225
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n";
2326

2427
?>

tests/causal-consistency/causal-consistency-011.phpt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
--TEST--
22
Causal consistency: $clusterTime is not sent in commands to unsupported deployments
33
--SKIPIF--
4-
<?php if (getenv("TRAVIS")) exit("skip This currently fails on Travis because it doesn't run 3.6 yet"); ?>
54
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
6-
<?php NEEDS('STANDALONE'); ?>
5+
<?php NEEDS('STANDALONE'); NEEDS_ATLEAST_MONGODB_VERSION(STANDALONE, "3.6"); ?>
76
--FILE--
87
<?php
98
require_once __DIR__ . "/../utils/basic.inc";

tests/cursor/cursor-destruct-001.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
--TEST--
22
MongoDB\Driver\Cursor destruct should kill a live cursor
33
--SKIPIF--
4+
<?php if (PHP_INT_SIZE !== 8) { die('skip Only for 64-bit platform'); } ?>
45
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
56
<?php NEEDS('STANDALONE'); CLEANUP(STANDALONE); ?>
67
--FILE--

0 commit comments

Comments
 (0)