Skip to content

Commit cb44e9c

Browse files
committed
Fix bug #65106: PHP fails to compile ext/fileinfo on memory-limited machines
Create on-the-fly a data_file_string.c alternative to data_string.c, which uses drastically less resources (CPU and RAM) with some compilers (notably GCC and Clang). Use this alternative when one of the aforementioned compilers is detected (see php#10422 (comment)).
1 parent f8f7fd2 commit cb44e9c

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

build/Makefile.global

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ clean:
122122
rm -f ext/opcache/jit/zend_jit_x86.c
123123
rm -f ext/opcache/jit/zend_jit_arm64.c
124124
rm -f ext/opcache/minilua
125+
rm -f ext/fileinfo/data_file_string.c
125126

126127
distclean: clean
127128
rm -f Makefile config.cache config.log config.status Makefile.objects Makefile.fragments libtool main/php_config.h main/internal_functions_cli.c main/internal_functions.c Zend/zend_dtrace_gen.h Zend/zend_dtrace_gen.h.bak Zend/zend_config.h

ext/fileinfo/Makefile.frag

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
$(builddir)/libmagic/apprentice.lo: $(srcdir)/data_file.c
1+
$(builddir)/libmagic/apprentice.lo: $(srcdir)/data_file.c $(srcdir)/data_file_string.c
2+
3+
# Optimized version of data_file.c (preferred by at least GCC and Clang).
4+
# If unable to generate it, fallback to including data_file.c.
5+
$(srcdir)/data_file_string.c: $(srcdir)/data_file.c
6+
@$(SED) -e 's#^0x#"\\x#' -e 's#, 0x#\\x#g' -e 's#, *$$#"#' -e 's#{ *$$##' -e 's#}##' -e 's#, *;#";#' < $(srcdir)/data_file.c > $@ || echo '#include "data_file.c"' > $@

ext/fileinfo/libmagic.patch

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,15 @@ diff -u libmagic.orig/apprentice.c libmagic/apprentice.c
2222
private void apprentice_unmap(struct magic_map *);
2323
private int apprentice_compile(struct magic_set *, struct magic_map *,
2424
const char *);
25-
@@ -186,6 +185,8 @@
25+
@@ -186,6 +185,12 @@
2626
{ NULL, 0, NULL }
2727
};
2828

29+
+#if !defined(PHP_WIN32) && (defined(__GNUC__) || defined(__clang__))
30+
+#include "../data_file_string.c"
31+
+#else
2932
+#include "../data_file.c"
33+
+#endif
3034
+
3135
#ifdef COMPILE_ONLY
3236

ext/fileinfo/libmagic/apprentice.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,11 @@ private struct {
185185
{ NULL, 0, NULL }
186186
};
187187

188+
#if !defined(PHP_WIN32) && (defined(__GNUC__) || defined(__clang__))
189+
#include "../data_file_string.c"
190+
#else
188191
#include "../data_file.c"
192+
#endif
189193

190194
#ifdef COMPILE_ONLY
191195

0 commit comments

Comments
 (0)