Re: PKG_LIB_DIR/PKGMODULEDIR expansion issues

"Matsumura, George" <[email protected]> Sat, 17 Dec 2022 23:02:20 -0500
Newsgroups gmane.linux.printing.gimp-print.devel
Message-ID <[email protected]>
On 7/20/22 17:34, Robert Krawitz wrote:
> I'll take a look at it.

I apologize for the noise, but is there anything I could do to improve
these changes or aid with their review? I have re-attached the most
recent versions of the patches to this email, please let me know if you
have any questions.

Thank you,
    George

_______________________________________________
Gimp-print-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gimp-print-devel
0002-core-Use-correct-function-to-find-printer-list-lengt.patch (text/x-patch, 1.1 KB)
From 120dc9f802d6bf0199b6890f744f7519e86da28c Mon Sep 17 00:00:00 2001
From: George Matsumura <[email protected]>
Date: Sat, 16 Jul 2022 21:41:37 -0600
Subject: [PATCH 2/2] core: Use correct function to find printer list length

By using stp_printer_model_count instead of stp_list_get_length,
the list is created in the case when no modules were found and the
list did not exist before. This prevents a segfault and prints a
helpful warning message.
---
 src/main/printers.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/main/printers.c b/src/main/printers.c
index 0a35ca08..597d6e3d 100644
--- a/src/main/printers.c
+++ b/src/main/printers.c
@@ -966,7 +966,9 @@ compare_names(const void *n1, const void *n2)
 void
 stpi_find_duplicate_printers(void)
 {
-  size_t nelts = stp_list_get_length(printer_list);
+  size_t nelts = stp_printer_model_count();
+  if (nelts == 0)
+    return;
   const char **str_data = stp_zalloc(sizeof(const char *) * nelts);
   stp_list_item_t *printer_item = stp_list_get_start(printer_list);
   size_t i = 0;
-- 
2.37.1
0001-build-Move-expansion-of-pathnames-to-build-time.patch (text/x-patch, 6.1 KB)
From 3c1857afdd56448572c8043d63c76af6c4b065c0 Mon Sep 17 00:00:00 2001
From: George Matsumura <[email protected]>
Date: Sat, 16 Jul 2022 21:41:13 -0600
Subject: [PATCH 1/2] build: Move expansion of pathnames to build time

This corrects errors in expansion encountered under the previous
scheme, and is in line with autoconf recommendations.
---
 configure.ac      | 84 +++++++----------------------------------------
 scripts/global.mk |  2 +-
 2 files changed, 13 insertions(+), 73 deletions(-)

diff --git a/configure.ac b/configure.ac
index 2b1cd098..93f3e7b7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -671,81 +671,17 @@ GUTENPRINT_BASE_VERSION=${GUTENPRINT_MAJOR_VERSION}.${GUTENPRINT_MINOR_VERSION}.
 AH_TEMPLATE(GUTENPRINT_BASE_VERSION,, [Gutenprint base version])
 AC_DEFINE_UNQUOTED(GUTENPRINT_BASE_VERSION, "${GUTENPRINT_BASE_VERSION}")
 
-dnl Set PACKAGE_LOCALE_DIR in config.h
-AH_TEMPLATE(PACKAGE_LOCALE_DIR,, [Package locale directory])
-if test "x${prefix}" = "xNONE"; then
-  AC_DEFINE_UNQUOTED(PACKAGE_LOCALE_DIR, ["${ac_default_prefix}/share/locale"])
-else
-  AC_DEFINE_UNQUOTED(PACKAGE_LOCALE_DIR, ["${prefix}/share/locale"])
-fi
+PACKAGE_LOCALE_DIR='${prefix}/share/locale'
 
-dnl Set PACKAGE_DATA_DIR in config.h.
-AH_TEMPLATE(PACKAGE_DATA_DIR,, [Package data directory])
-if test "x${datadir}" = 'x${prefix}/share'; then
-  if test "x${prefix}" = "xNONE"; then
-    PACKAGE_DATA_DIR="${ac_default_prefix}/share/${PACKAGE}"
-  else
-    PACKAGE_DATA_DIR="${prefix}/share/${PACKAGE}"
-  fi
-elif test "x${datadir}" = 'x${datarootdir}'; then
-  if test "x${datarootdir}" = 'x${prefix}/share'; then
-    if test "x${prefix}" = "xNONE"; then
-      PACKAGE_DATA_DIR="${ac_default_prefix}/share/${PACKAGE}"
-    else
-      PACKAGE_DATA_DIR="${prefix}/share/${PACKAGE}"
-    fi
-  else
-    PACKAGE_DATA_DIR="${datarootdir}/${PACKAGE}"
-  fi
-else
-  PACKAGE_DATA_DIR="${datadir}/${PACKAGE}"
-fi
+PACKAGE_DATA_DIR="${datadir}/${PACKAGE}"
 
-AC_DEFINE_UNQUOTED(PACKAGE_DATA_DIR, "${PACKAGE_DATA_DIR}")
-
-dnl Set PACKAGE_LIB_DIR in config.h.
-AH_TEMPLATE(PACKAGE_LIB_DIR,, [Package lib directory])
-if test "x${libdir}" = 'x${exec_prefix}/lib'; then
-  if test "x${exec_prefix}" = "xNONE"; then
-    if test "x${prefix}" = "xNONE"; then
-      PACKAGE_LIB_DIR="${ac_default_prefix}/lib/${PACKAGE}"
-    else
-      PACKAGE_LIB_DIR="${prefix}/lib/${PACKAGE}"
-    fi
-  else
-    PACKAGE_LIB_DIR="${exec_prefix}/lib/${PACKAGE}"
-  fi
-else
-  PACKAGE_LIB_DIR="${libdir}/${PACKAGE}"
-fi
-
-AC_DEFINE_UNQUOTED(PACKAGE_LIB_DIR, ["${PACKAGE_LIB_DIR}"])
-
-dnl Set PACKAGE_BIN_DIR in config.h.
-AH_TEMPLATE(PACKAGE_BIN_DIR,, [Package bin directory])
-if test "x${bindir}" = 'x${exec_prefix}/bin'; then
-  if test "x${exec_prefix}" = "xNONE"; then
-    if test "x${prefix}" = "xNONE"; then
-      PACKAGE_BIN_DIR="${ac_default_prefix}/bin"
-    else
-      PACKAGE_BIN_DIR="${prefix}/bin"
-    fi
-  else
-    PACKAGE_BIN_DIR="${exec_prefix}/bin"
-  fi
-else
-  PACKAGE_BIN_DIR="${bindir}"
-fi
+PACKAGE_LIB_DIR="${libdir}/${PACKAGE}"
 
-AC_DEFINE_UNQUOTED(PACKAGE_BIN_DIR, ["${PACKAGE_BIN_DIR}"])
+PACKAGE_BIN_DIR="${bindir}"
 
-AH_TEMPLATE(PKGXMLDATADIR,, [Package XML data directory])
 PKGXMLDATADIR="${PACKAGE_DATA_DIR}/${GUTENPRINT_RELEASE_VERSION}/xml"
-AC_DEFINE_UNQUOTED(PKGXMLDATADIR, ["$PKGXMLDATADIR"], )
 
-AH_TEMPLATE(PKGMODULEDIR,, [Package module directory])
 PKGMODULEDIR="${PACKAGE_LIB_DIR}/${GUTENPRINT_RELEASE_VERSION}/modules"
-AC_DEFINE_UNQUOTED(PKGMODULEDIR, ["$PKGMODULEDIR"])
 
 dnl Compiler flags
 if test x$ac_compiler_gnu = "xyes"; then
@@ -1064,8 +1000,6 @@ RM='rm'
 PKGROOT=`pwd`
 
 dnl Substitutions
-AC_SUBST(prefix)
-AC_SUBST(exec_prefix)
 AC_SUBST(cups_prefix)
 AC_SUBST(cups_exec_prefix)
 AC_SUBST(cups_bindir)
@@ -1107,6 +1041,12 @@ AC_SUBST(GUTENPRINT_RELEASE_VERSION)
 AC_SUBST(LIBUSB_BACKEND_LIBDEPS)
 AC_SUBST(PKGROOT)
 AC_SUBST(MINIMAL_PRINTERS_TO_TEST)
+AC_SUBST(PACKAGE_LOCALE_DIR)
+AC_SUBST(PACKAGE_DATA_DIR)
+AC_SUBST(PACKAGE_LIB_DIR)
+AC_SUBST(PACKAGE_BIN_DIR)
+AC_SUBST(PKGXMLDATADIR)
+AC_SUBST(PKGMODULEDIR)
 
 dnl Optional architecture options to be applied after all autoconf tests
 dnl are done...
@@ -1252,10 +1192,10 @@ echo "    Installation prefix:                        $prefix" |tee -a config.su
 # Configure intentionally does not expand exec_prefix to allow make
 # to do so.
 echo "    Exec prefix:                                `eval eval echo $exec_prefix` ($exec_prefix)" |tee -a config.summary
-echo "    Data directory:                             $PACKAGE_DATA_DIR" |tee -a config.summary
+echo "    Data directory:                             `eval eval echo $PACKAGE_DATA_DIR` ($PACKAGE_DATA_DIR)" |tee -a config.summary
 echo "    Library directory:                          `eval eval echo $PACKAGE_LIB_DIR` ($PACKAGE_LIB_DIR)" |tee -a config.summary
 echo "    Executable directory:                       `eval eval echo $PACKAGE_BIN_DIR` ($PACKAGE_BIN_DIR)" |tee -a config.summary
-echo "    XML data directory:                         $PKGXMLDATADIR" |tee -a config.summary
+echo "    XML data directory:                         `eval eval echo $PKGXMLDATADIR` ($PKGXMLDATADIR)" |tee -a config.summary
 echo "    Module directory:                           `eval eval echo $PKGMODULEDIR` ($PKGMODULEDIR)" |tee -a config.summary
 echo "    Install sample images:                      $INSTALL_SAMPLES" |tee -a config.summary
 echo |tee -a config.summary
diff --git a/scripts/global.mk b/scripts/global.mk
index c4054826..792b8b0d 100644
--- a/scripts/global.mk
+++ b/scripts/global.mk
@@ -6,7 +6,7 @@
 #export STP_MODULE_PATH = $(top_builddir)/src/main/.libs:$(top_builddir)/src/main
 #export STP_DATA_PATH = $(top_srcdir)/src/xml
 
-AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/include $(LOCAL_CPPFLAGS) $(GNUCFLAGS)
+AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/include $(LOCAL_CPPFLAGS) $(GNUCFLAGS) -DPACKAGE_LOCALE_DIR=\"$(PACKAGE_LOCALE_DIR)\" -DPACKAGE_DATA_DIR=\"$(PACKAGE_DATA_DIR)\" -DPACKAGE_LIB_DIR=\"$(PACKAGE_LIB_DIR)\" -DPACKAGE_BIN_DIR=\"$(PACKAGE_BIN_DIR)\" -DPKGMODULEDIR=\"$(PKGMODULEDIR)\" -DPKGXMLDATADIR=\"$(PKGXMLDATADIR)\"
 
 LIBS = $(INTLLIBS) @LIBS@
 
-- 
2.37.1