Hi, In ubuntu we applied the upstream's fix at https://github.com/rlancaste/stellarsolver/pull/139. I adapted it to a patch that I attach here for fixing this FTBFS.
I am sending this for your consideration, and I hope it helps. Best, Miriam -- [image: Canonical-20th-anniversary] Miriam EspaƱa Acebal Software Engineer II - Ubuntu Public Cloud/Server Email: miriam.esp...@canonical.com Location: Spain (GMT+2) canonical.com ubuntu.com
Description: Fix qsort warning implicit function declarations The qsort_r function comes with different prototypes on different systems. There are some tests around NEED_DECLARE_QSORT_R and NEED_SWAP_QSORT_R that try to work around that. However, they only work with compilers which accept implicit function declarations. The qsort_r fix is backported from astrometry. Author: timsurber <https://github.com/timsurber> Origin: upstream, https://github.com/rlancaste/stellarsolver/pull/139 Bug: https://github.com/rlancaste/stellarsolver/issues/108 Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1066275 Bug-Ubuntu: https://bugs.launchpad.net/debian/+source/stellarsolver/+bug/2060959 Forwarded: not-needed Last-Update: 2024-04-11 --- This patch header follows DEP-3: http://dep.debian.net/deps/dep3/ --- a/stellarsolver/astrometry/include/astrometry/ioutils.h +++ b/stellarsolver/astrometry/include/astrometry/ioutils.h @@ -31,6 +31,15 @@ extern uint32_t ENDIAN_DETECTOR; +void QSORT_R(void* base, size_t nmembers, size_t member_size, + void* token, int (*compar)(void *, const void *, const void *)); + +/** + You should define the "comparison" function like this: + static int QSORT_COMPARISON_FUNCTION(my_comparison, void* token, const void* v1, const void* v2) { + */ +#define QSORT_COMPARISON_FUNCTION(func, thunk, v1, v2) func(thunk, v1, v2) + int copy_file(const char* infn, const char* outfn); int pad_fid(FILE* fid, size_t len, char pad); --- a/stellarsolver/astrometry/include/astrometry/os-features-config.h +++ b/stellarsolver/astrometry/include/astrometry/os-features-config.h @@ -1,4 +1,4 @@ -#define NEED_DECLARE_QSORT_R 0 -#define NEED_QSORT_R 1 +#define NEED_DECLARE_QSORT_R 1 +#define NEED_QSORT_R 0 #define NEED_SWAP_QSORT_R 0 #define HAVE_NETPBM 0 \ No newline at end of file --- a/stellarsolver/astrometry/include/astrometry/permutedsort.h +++ b/stellarsolver/astrometry/include/astrometry/permutedsort.h @@ -7,7 +7,7 @@ #define PERMUTED_SORT_H // for QSORT_COMPARISON_FUNCTION -#include "os-features.h" +#include "ioutils.h" /* Computes the permutation array that will cause the "realarray" to be --- a/stellarsolver/astrometry/os-features.h +++ b/stellarsolver/astrometry/os-features.h @@ -108,22 +108,6 @@ -Ubuntu 8.10 */ -#if NEED_DECLARE_QSORT_R -//// NOTE: this declaration must match os-features-test.c . -void qsort_r(void *base, size_t nmemb, size_t sz, - void *userdata, - int (*compar)(void *, const void *, const void *)); -#endif - -#if NEED_SWAP_QSORT_R -#define QSORT_R(a,b,c,d,e) qsort_r(a,b,c,e,d) -#define QSORT_COMPARISON_FUNCTION(func, thunk, v1, v2) func(v1, v2, thunk) - -#else -#define QSORT_R qsort_r -#define QSORT_COMPARISON_FUNCTION(func, thunk, v1, v2) func(thunk, v1, v2) - -#endif // As suggested in http://gcc.gnu.org/onlinedocs/gcc-4.3.0/gcc/Function-Names.html #if __STDC_VERSION__ < 199901L --- a/stellarsolver/astrometry/util/bl-sort.c +++ b/stellarsolver/astrometry/util/bl-sort.c @@ -3,6 +3,8 @@ # Licensed under a 3-clause BSD style license - see LICENSE */ +#include "ioutils.h" // for QSORT_R + #include "bl-sort.h" // for qsort_r #include "os-features.h" @@ -166,4 +168,3 @@ void pl_sort(pl* list, int (*compare)(const void* v1, const void* v2)) { bl_sort_with_userdata(list, sort_helper_pl, compare); } - --- a/stellarsolver/astrometry/util/fitstable.c +++ b/stellarsolver/astrometry/util/fitstable.c @@ -1227,7 +1227,11 @@ else { tab->fid = fopen(fn, mode); if (!tab->fid) { - SYSERROR("Couldn't open output file %s for writing", fn); + if (fn != NULL) { + SYSERROR("Couldn't open output file %s for writing", fn); + } else { + SYSERROR("Couldn't open output file because the filename is null"); + } goto bailout; } } --- a/stellarsolver/astrometry/util/ioutils.c +++ b/stellarsolver/astrometry/util/ioutils.c @@ -43,7 +43,7 @@ #include "os-features.h" #include "ioutils.h" -//#include "os-features.h" +#include "qsort_reentrant.c" #include "errors.h" #include "log.h" --- a/stellarsolver/astrometry/util/os-features-test.c +++ b/stellarsolver/astrometry/util/os-features-test.c @@ -14,63 +14,6 @@ } #endif -#ifdef TEST_QSORT_R -static int cmp(void* u, const void* a, const void* b) { - return 0; -} -int main() { - int array; - int baton; - qsort_r(&array, 1, sizeof(int), &baton, cmp); - //printf("#define NEED_QSORT_R 0\n"); - return 0; -} -#endif - -#ifdef TEST_DECLARE_QSORT_R -// Test whether just declaring qsort_r as we do causes a compile failure. - -void qsort_r(void *base, size_t nmemb, size_t sz, - void *userdata, - int (*compar)(void *, const void *, const void *)); - -int main() { - //printf("#define NEED_DECLARE_QSORT_R 1\n"); - return 0; -} -#endif - -#ifdef TEST_SWAP_QSORT_R -// Use the result of TEST_DECLARE_QSORT_R and TEST_NEED_QSORT_R, or else -// this test will fail with a warning about undefined qsort_r -// Include .c rather than .h because we test with: -// gcc -o (exec) os-features-test.c -// and if NEED_QSORT_R, os-features.c includes qsort_reentrant.c -#include "os-features-config.h.tmp" -#define DONT_INCLUDE_OS_FEATURES_CONFIG_H 1 -#include "os-features.c" -#undef DONT_INCLUDE_OS_FEATURES_CONFIG_H -// Test whether qsort_r works unswapped. (ie, qsort_r matches the definition of -// QSORT_R defined in the os-features.h documentation.) -static int sortfunc(void* thunk, const void* v1, const void* v2) { - const int* i1 = v1; - const int* i2 = v2; - if (*i1 < *i2) - return -1; - if (*i1 > *i2) - return 1; - return 0; -} -int main() { - int array[] = { 4, 17, 88, 34, 12, 12, 17 }; - int N = sizeof(array)/sizeof(int); - int mythunk = 42; - qsort_r(array, N, sizeof(int), &mythunk, sortfunc); - //printf("#define NEED_SWAP_QSORT_R 0\n"); - return 0; -} -#endif - #if defined(TEST_NETPBM) || defined(TEST_NETPBM_MAKE) #include <pam.h> int main(int argc, char** args) { --- a/stellarsolver/astrometry/util/os-features.c +++ b/stellarsolver/astrometry/util/os-features.c @@ -37,8 +37,4 @@ //int fdatasync(int fd) { // return fsync(fd); //} -//#endif - -#if NEED_QSORT_R -#include "qsort_reentrant.c" -#endif +//#endif \ No newline at end of file --- a/stellarsolver/astrometry/util/permutedsort.c +++ b/stellarsolver/astrometry/util/permutedsort.c @@ -17,7 +17,8 @@ #endif #include "permutedsort.h" -#include "os-features.h" // for qsort_r +#include "os-features.h" +#include "ioutils.h" int* permutation_init(int* perm, int N) { int i; --- a/stellarsolver/astrometry/util/qsort_reentrant.c +++ b/stellarsolver/astrometry/util/qsort_reentrant.c @@ -35,14 +35,14 @@ #endif //__FBSDID("$FreeBSD: src/sys/libkern/qsort.c,v 1.15 2004/07/15 23:58:23 glebius Exp $"); -// Astrometry: We want reentrant! -#define I_AM_QSORT_R -#ifdef I_AM_QSORT_R +// Astrometry.net: we lightly modified this file: +// - renamed qsort_r to QSORT_R to avoid clashes with system version +// - removed the preprocessor magic that support re-entrant and non- +// functions in the same source code. + typedef int cmp_t(void *, const void *, const void *); -#else -typedef int cmp_t(const void *, const void *); -#endif + static __inline char *med3(char *, char *, char *, cmp_t *, void *); static __inline void swapfunc(char *, char *, int, int); @@ -84,32 +84,17 @@ #define vecswap(a, b, n) if ((n) > 0) swapfunc(a, b, n, swaptype) -#ifdef I_AM_QSORT_R #define CMP(t, x, y) (cmp((t), (x), (y))) -#else -#define CMP(t, x, y) (cmp((x), (y))) -#endif static __inline char * -med3(char *a, char *b, char *c, cmp_t *cmp, void *thunk -#ifndef I_AM_QSORT_R -__unused -#endif -) +med3(char *a, char *b, char *c, cmp_t *cmp, void *thunk) { return CMP(thunk, a, b) < 0 ? (CMP(thunk, b, c) < 0 ? b : (CMP(thunk, a, c) < 0 ? c : a )) :(CMP(thunk, b, c) > 0 ? b : (CMP(thunk, a, c) < 0 ? a : c )); } -#ifdef I_AM_QSORT_R -void -qsort_r(void *a, size_t n, size_t es, void *thunk, cmp_t *cmp) -#else -#define thunk NULL -void -qsort(void *a, size_t n, size_t es, cmp_t *cmp) -#endif +void QSORT_R(void *a, size_t n, size_t es, void *thunk, cmp_t *cmp) { char *pa, *pb, *pc, *pd, *pl, *pm, *pn; int d, r, swaptype, swap_cnt; @@ -177,11 +162,7 @@ r = min(pd - pc, pn - pd - es); vecswap(pb, pn - r, r); if ((r = pb - pa) > es) -#ifdef I_AM_QSORT_R - qsort_r(a, r / es, es, thunk, cmp); -#else - qsort(a, r / es, es, cmp); -#endif + QSORT_R(a, r / es, es, thunk, cmp); if ((r = pd - pc) > es) { /* Iterate rather than recurse to save stack space */ a = pn - r;