summaryrefslogtreecommitdiff
path: root/compat/obstack.c
AgeCommit message (Collapse)Author
2019-01-17compat/obstack: fix -Wcast-function-type warningsSZEDER Gábor
GCC 8 introduced the new -Wcast-function-type warning, which is implied by -Wextra (which, in turn is enabled in our DEVELOPER flags). When building Git with GCC 8 and this warning enabled on a non-glibc platform [1], one is greeted with a screenful of compiler warnings/errors: compat/obstack.c: In function '_obstack_begin': compat/obstack.c:162:17: error: cast between incompatible function types from 'void * (*)(long int)' to 'struct _obstack_chunk * (*)(void *, long int)' [-Werror=cast-function-type] h->chunkfun = (struct _obstack_chunk * (*)(void *, long)) chunkfun; ^ compat/obstack.c:163:16: error: cast between incompatible function types from 'void (*)(void *)' to 'void (*)(void *, struct _obstack_chunk *)' [-Werror=cast-function-type] h->freefun = (void (*) (void *, struct _obstack_chunk *)) freefun; ^ compat/obstack.c:116:8: error: cast between incompatible function types from 'struct _obstack_chunk * (*)(void *, long int)' to 'struct _obstack_chunk * (*)(long int)' [-Werror=cast-function-type] : (*(struct _obstack_chunk *(*) (long)) (h)->chunkfun) ((size))) ^ compat/obstack.c:168:22: note: in expansion of macro 'CALL_CHUNKFUN' chunk = h->chunk = CALL_CHUNKFUN (h, h -> chunk_size); ^~~~~~~~~~~~~ <snip> 'struct obstack' stores pointers to two functions to allocate and free "chunks", and depending on how obstack is used, these functions take either one parameter (like standard malloc() and free() do; this is how we use it in 'kwset.c') or two parameters. Presumably to reduce memory footprint, a single field is used to store the function pointer for both signatures, and then it's casted to the appropriate signature when the function pointer is accessed. These casts between function pointers with different number of parameters are what trigger those compiler errors. Modify 'struct obstack' to use unions to store function pointers with different signatures, and then use the union member with the appropriate signature when accessing these function pointers. This eliminates the need for those casts, and thus avoids this compiler error. [1] Compiling 'compat/obstack.c' on a platform with glibc is sort of a noop, see the comment before '# define ELIDE_CODE', so this is not an issue on common Linux distros. Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-11-09Replace Free Software Foundation address in license noticesTodd Zullinger
The mailing address for the FSF has changed over the years. Rather than updating the address across all files, refer readers to gnu.org, as the GNU GPL documentation now suggests for license notices. The mailing address is retained in the full license files (COPYING and LGPL-2.1). The old address is still present in t/diff-lib/COPYING. This is intentional, as the file is used in tests and the contents are not expected to change. Signed-off-by: Todd Zullinger <tmz@pobox.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-09-11obstack.c: Fix some sparse warningsRamsay Jones
In particular, sparse issues the following warnings: compat/obstack.c:176:17: warning: Using plain integer as NULL pointer compat/obstack.c:224:17: warning: Using plain integer as NULL pointer compat/obstack.c:324:16: warning: Using plain integer as NULL pointer compat/obstack.c:329:16: warning: Using plain integer as NULL pointer compat/obstack.c:347:16: warning: Using plain integer as NULL pointer compat/obstack.c:362:19: warning: Using plain integer as NULL pointer compat/obstack.c:379:29: warning: Using plain integer as NULL pointer compat/obstack.c:399:1: error: symbol 'print_and_abort' redeclared with \ different type (originally declared at compat/obstack.c:95) \ - different modifiers Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-08-29obstack: Fix portability issuesFredrik Kuivinen
i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1, SunOS 5.10, and possibly others do not have exit.h and exitfail.h. Remove the use of these in obstack.c. The __block variable was renamed to block to avoid a gcc error: compat/obstack.h:190: error: __block attribute can be specified on variables only Initial-patch-by: David Aguilar <davvid@gmail.com> Reported-by: Brian Gernhardt <brian@gernhardtsoftware.com> Signed-off-by: Fredrik Kuivinen <frekui@gmail.com> Acked-by: David Aguilar <davvid@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-08-21Add obstack.[ch] from EGLIBC 2.10Fredrik Kuivinen
Signed-off-by: Fredrik Kuivinen <frekui@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>