Ticket #56083: leptonica-fstatat.patch

File leptonica-fstatat.patch, 7.8 KB (added by Ionic (Mihai Moldovan), 7 years ago)

Proposed patch to replace fstatat with stat on older platforms. Includes patches as sent upstream as well. v5.

  • graphics/leptonica/Portfile

    commit 6726823b9cb34efd8898a09d84b4619b1d576d47
    Author: Mihai Moldovan <ionic@ionic.de>
    Date:   Sat Mar 17 10:55:32 2018 +0100
    
        graphics/leptonica: fix builds on OS X 10.9-.
        
        fstatat() is not available on older platforms, but the code doesn't rely
        upon fstatat()-specific behavior anyway, so just replace the call with
        stat() where not supported.
        
        Fixes: https://trac.macports.org/ticket/56083
    
    diff --git a/graphics/leptonica/Portfile b/graphics/leptonica/Portfile
    index c500242987..fa2bee7288 100644
    a b master_sites http://www.leptonica.com/source/ 
    2020checksums           rmd160  006ced964c7d9125c5b728bf8b717849c7dda21a \
    2121                    sha256  a00f8fb06829ca6c8262bec8f78a6f985e049786f7c872a37b72fd7051ea087a
    2222
     23# fstatat series:
     24#   - https://github.com/DanBloomberg/leptonica/issues/327
     25#   - https://github.com/DanBloomberg/leptonica/pull/328
     26#   - https://trac.macports.org/ticket/56083
     27patchfiles          patch-conf-fstatat.diff \
     28                    patch-fallback-fstatat-stat.diff
     29
    2330depends_build       port:pkgconfig
    2431
    2532depends_lib         port:tiff \
    depends_lib port:tiff \ 
    3037                    port:giflib \
    3138                    port:webp
    3239
     40use_autoreconf      yes
     41
    3342configure.args      --disable-silent-rules
    3443
    3544# ${prefix}/bin/fileinfo
  • new file graphics/leptonica/files/patch-conf-fstatat.diff

    diff --git a/graphics/leptonica/files/patch-conf-fstatat.diff b/graphics/leptonica/files/patch-conf-fstatat.diff
    new file mode 100644
    index 0000000000..01371c4265
    - +  
     1--- README.html.old     2018-02-15 18:46:13.000000000 +0100
     2+++ README.html 2018-03-18 01:21:37.000000000 +0100
     3@@ -499,7 +499,18 @@ that you are using the static makefiles
     4    If you're building with the autoconf programs, these two functions are
     5    automatically enabled if available.
     6 
     7-3. Typedefs
     8+3. Runtime functions not available on all platforms
     9+
     10+   Some functions are not available on all systems.  One example of such a
     11+   function is fstatat().  If possible, such functions will be replaced by
     12+   wrappers, stubs or behavioral equivalent functions.  By default, such
     13+   functions are disabled; enable them by setting #define HAVE_FUNC  1 (in
     14+   environ.h).
     15+
     16+   If you're building with the autoconf or cmake programs, these functions are
     17+   automatically enabled if available.
     18+
     19+4. Typedefs
     20 
     21    A deficiency of C is that no standard has been universally
     22    adopted for typedefs of the built-in types.  As a result,
     23@@ -542,7 +553,7 @@ that you are using the static makefiles
     24    necessary we use the typedefs in stdint.h to specify the pointer
     25    size (either 4 or 8 byte).
     26 
     27-4. Compile-time control over stderr output (see environ.h)
     28+5. Compile-time control over stderr output (see environ.h)
     29 
     30    Leptonica provides both compile-time and run-time control over
     31    messages and debug output (thanks to Dave Bryan).  Both compile-time
     32@@ -553,7 +564,7 @@ that you are using the static makefiles
     33    NO_CONSOLE_IO is defined on the compile line.  For production code
     34    where no output is to go to stderr, compile with -DNO_CONSOLE_IO.
     35 
     36-5. In-memory raster format (Pix)
     37+6. In-memory raster format (Pix)
     38 
     39    Unlike many other open source packages, Leptonica uses packed
     40    data for images with all bit/pixel (bpp) depths, allowing us
     41@@ -574,7 +585,7 @@ that you are using the static makefiles
     42    and a DPix is provided for 2D arrays of doubles.  Converters
     43    between these and the Pix are given.
     44 
     45-6. Conversion between Pix and other in-memory raster formats
     46+7. Conversion between Pix and other in-memory raster formats
     47 
     48  . If you use Leptonica with other imaging libraries, you will need
     49    functions to convert between the Pix and other image data
     50@@ -583,7 +594,7 @@ that you are using the static makefiles
     51    ordering and byte ordering on raster lines.  See the file pix.h
     52    for the specification of image data in the pix.
     53 
     54-7. Custom memory management
     55+8. Custom memory management
     56 
     57    Leptonica allows you to use custom memory management (allocator,
     58    deallocator).  For Pix, which tend to be large, the alloc/dealloc
     59Only in leptonica-1.75.3: README.html.orig
     60--- cmake/Configure.cmake.old   2017-11-03 19:35:52.000000000 +0100
     61+++ cmake/Configure.cmake       2018-03-18 01:21:37.000000000 +0100
     62@@ -73,6 +73,7 @@ check_includes(include_files_list)
     63 
     64 set(functions_list
     65     fmemopen
     66+    fstatat
     67 )
     68 check_functions(functions_list)
     69 
     70--- configure.ac.old    2018-02-13 00:08:33.000000000 +0100
     71+++ configure.ac        2018-03-18 01:21:37.000000000 +0100
     72@@ -223,6 +223,7 @@ AC_LINK_IFELSE([AC_LANG_PROGRAM()],
     73 
     74 # Checks for library functions.
     75 AC_CHECK_FUNCS([fmemopen])
     76+AC_CHECK_FUNC([fstatat])
     77 
     78 AC_CONFIG_FILES([Makefile src/endianness.h src/Makefile prog/Makefile lept.pc])
     79 AC_OUTPUT
     80--- cppan.yml.old       2017-03-10 20:57:34.000000000 +0100
     81+++ cppan.yml   2018-03-18 01:21:37.000000000 +0100
     82@@ -6,7 +6,9 @@ files:
     83 include_directories:
     84     public: src
     85 
     86-check_function_exists: fmemopen
     87+check_function_exists:
     88+  - fmemopen
     89+  - fstatat
     90 
     91 check_include_exists:
     92   - dlfcn.h
     93--- src/environ.h.old   2018-01-16 00:30:21.000000000 +0100
     94+++ src/environ.h       2018-03-18 01:21:37.000000000 +0100
     95@@ -127,6 +127,15 @@ typedef uintptr_t l_uintptr_t;
     96 #define  HAVE_FMEMOPEN    1
     97 #endif  /* ! HAVE_CONFIG_H etc. */
     98 
     99+/*
     100+ * fstatat() is defined by POSIX, but some systems do not support it.
     101+ * One example is older macOS systems (pre-10.10).
     102+ * Play it safe and set the default value to 0.
     103+ */
     104+#if !defined(HAVE_CONFIG_H)
     105+#define  HAVE_FSTATAT     0
     106+#endif /* ! HAVE_CONFIG_H */
     107+
     108 
     109 /*--------------------------------------------------------------------*
     110  * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*
     111--- src/makefile.static.old     2018-02-13 02:40:04.000000000 +0100
     112+++ src/makefile.static 2018-03-18 01:21:37.000000000 +0100
     113@@ -49,6 +49,11 @@
     114 #   The default is not to use, because they only work on linux.
     115 #   To use these, #define HAVE_FMEMOPEN to 1 in environ.h.
     116 #
     117+#   Customization for POSIX-compliant function fstatat().
     118+#   The default is not to use, because some systems do not
     119+#   support it.
     120+#   To use this, #define HAVE_FSTATAT to 1 in environ.h.
     121+#
     122 #   Customization for Cygwin:
     123 #   (1) Use the appropriate $CC
     124 #
     125--- sw.cpp.old  2017-11-20 18:50:09.000000000 +0100
     126+++ sw.cpp      2018-03-18 01:21:37.000000000 +0100
     127@@ -56,6 +56,7 @@ void check(Checker &c)
     128 {
     129     auto &s = c.addSet("leptonica");
     130     s.checkFunctionExists("fmemopen");
     131+    s.checkFunctionExists("fstatat");
     132     s.checkIncludeExists("dlfcn.h");
     133     s.checkIncludeExists("inttypes.h");
     134     s.checkIncludeExists("memory.h");
  • new file graphics/leptonica/files/patch-fallback-fstatat-stat.diff

    diff --git a/graphics/leptonica/files/patch-fallback-fstatat-stat.diff b/graphics/leptonica/files/patch-fallback-fstatat-stat.diff
    new file mode 100644
    index 0000000000..e7bb2e9f8c
    - +  
     1--- src/sarray1.c.old   2018-01-31 16:57:06.000000000 +0100
     2+++ src/sarray1.c       2018-03-18 01:22:45.000000000 +0100
     3@@ -1855,7 +1855,7 @@ l_int32         len;
     4 SARRAY         *safiles;
     5 DIR            *pdir;
     6 struct dirent  *pdirentry;
     7-int             dfd;
     8+int             dfd, stat_ret;
     9 struct stat     st;
     10 
     11     PROCNAME("getFilenamesInDirectory");
     12@@ -1871,9 +1871,14 @@ struct stat     st;
     13     safiles = sarrayCreate(0);
     14     dfd = dirfd(pdir);
     15     while ((pdirentry = readdir(pdir))) {
     16+#if HAVE_FSTATAT
     17+      stat_ret = fstatat(dfd, pdirentry->d_name, &st, 0);
     18+#else
     19+      stat_ret = stat(pdirentry->d_name, &st);
     20+#endif
     21 
     22         /* It's nice to ignore directories.  */
     23-      if ((0 == fstatat(dfd, pdirentry->d_name, &st, 0))
     24+      if ((0 == stat_ret)
     25           && S_ISDIR(st.st_mode)) {
     26             continue;
     27       }