From ea12386a04768db37927098b4ecd8e43e3226d41 Mon Sep 17 00:00:00 2001 From: Samuli Suominen Date: Sat, 22 Aug 2009 12:16:57 +0000 Subject: Backport maxmem sysconf() patch from jpeg-6b patchset. Package-Manager: portage-2.2_rc38/cvs/Linux x86_64 --- media-libs/jpeg/files/jpeg-7-maxmem_sysconf.patch | 50 +++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 media-libs/jpeg/files/jpeg-7-maxmem_sysconf.patch (limited to 'media-libs/jpeg/files') diff --git a/media-libs/jpeg/files/jpeg-7-maxmem_sysconf.patch b/media-libs/jpeg/files/jpeg-7-maxmem_sysconf.patch new file mode 100644 index 000000000000..95c207b09d36 --- /dev/null +++ b/media-libs/jpeg/files/jpeg-7-maxmem_sysconf.patch @@ -0,0 +1,50 @@ +# Make a reasonable guess about memory limits using sysconf(). +# includes 5% slop factor as suggested in documentation. + +diff -ur jpeg-7.orig/jmemansi.c jpeg-7/jmemansi.c +--- jpeg-7.orig/jmemansi.c 1996-01-06 19:29:46.000000000 +0200 ++++ jpeg-7/jmemansi.c 2009-08-22 14:47:35.000000000 +0300 +@@ -12,6 +12,15 @@ + * is shoved onto the user. + */ + ++#include ++ ++#ifdef __FreeBSD__ ++# include ++# include ++# include ++# include ++#endif ++ + #define JPEG_INTERNALS + #include "jinclude.h" + #include "jpeglib.h" +@@ -157,7 +166,26 @@ + GLOBAL(long) + jpeg_mem_init (j_common_ptr cinfo) + { +- return DEFAULT_MAX_MEM; /* default for max_memory_to_use */ ++#ifdef _SC_AVPHYS_PAGES ++ long phys_size; ++ ++ if ((phys_size = sysconf(_SC_AVPHYS_PAGES)) == -1) ++ return DEFAULT_MAX_MEM; /* default for max_memory_to_use */ ++ if ((phys_size *= sysconf(_SC_PAGESIZE)) < 0) ++ return DEFAULT_MAX_MEM; ++ return (long) (phys_size * 0.95); ++#elif defined(HAVE_SYSCTL) && defined(HW_PHYSMEM) ++ /* This works on *bsd and darwin. */ ++ unsigned int physmem; ++ size_t len = sizeof physmem; ++ static int mib[2] = { CTL_HW, HW_PHYSMEM }; ++ ++ if (sysctl (mib, ARRAY_SIZE (mib), &physmem, &len, NULL, 0) == 0 ++ && len == sizeof (physmem)) ++ return (long) (physmem * 0.95); ++#endif ++ ++ return DEFAULT_MAX_MEM; + } + + GLOBAL(void) -- cgit v1.2.3-65-gdbad