Skip to content

Commit 51b2b00

Browse files
committed
Fix bug #65106: PHP fails to compile ext/fileinfo on memory-limited machines
Use a list of longs instead of a list of chars: this uses less resources (CPU and RAM) with some compilers (notably GCC and Clang).
1 parent f8f7fd2 commit 51b2b00

File tree

2 files changed

+497196
-497197
lines changed

2 files changed

+497196
-497197
lines changed

ext/fileinfo/create_data_file.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@
44
<?php
55
$dta = file_get_contents( $argv[1] );
66
$dta_l = strlen($dta);
7-
$j = 0;
87

9-
echo "const unsigned char php_magic_database[$dta_l] = {\n";
10-
for ($i = 0; $i < $dta_l; $i++) {
11-
printf("0x%02X, ", ord($dta[$i]));
12-
if ($j % 16 == 15) {
8+
echo "const uint32_t php_magic_database[" . ($dta_l / 4) . "] = {\n";
9+
for ($i = 0; $i < $dta_l; $i += 4) {
10+
// We are byte-by-byte reading a file of uint32_t stored as little endian (if run on Intel), so swap bytes.
11+
printf("0x%02X%02X%02X%02X, ", ord($dta[$i + 3]), ord($dta[$i + 2]), ord($dta[$i + 1]), ord($dta[$i]));
12+
if ($i % 16 == 12) {
1313
echo "\n";
1414
}
15-
$j++;
1615
}
1716
echo "};\n";
1817
?>

0 commit comments

Comments
 (0)