bitwiseworks / libc

LIBC Next (kLIBC fork)
9 stars 4 forks source link

Prototypes of some functions mismatches with POSIX #142

Open komh opened 1 month ago

komh commented 1 month ago

Hi/2.

Some functions are declared differently POSIX. And some codes such as GNULIB test-suites require exact function declarations. Worse is that GCC14 now treats this as errors. So these should be solved.

1.putenv() and _putenv()

LIBCn declares like: https://github.com/bitwiseworks/libc/blob/7a15da98a2c81aeb6341859bf5409586eea19241/src/emx/include/stdlib.h#L207

POSIX requires:

int putenv(char *string);

See https://pubs.opengroup.org/onlinepubs/9799919799/functions/putenv.html.

_putenv() should be considered, too.

The following is errors from GNULIB test-suites:

In file included from test-putenv.c:24:
test-putenv.c:25:18: error: initialization of 'int (*)(char *)' from incompatible pointer type 'int (*)(const char *)' [-Wincompatible-pointer-types]
   25 | SIGNATURE_CHECK (putenv, int, (char *));
      |                  ^~~~~~
signature.h:46:57: note: in definition of macro 'SIGNATURE_CHECK2'
   46 |   _GL_UNUSED static ret (*signature_check ## id) args = fn
      |                                                         ^~
signature.h:39:3: note: in expansion of macro 'SIGNATURE_CHECK1'
   39 |   SIGNATURE_CHECK1 (fn, ret, args, __LINE__)
      |   ^~~~~~~~~~~~~~~~
test-putenv.c:25:1: note: in expansion of macro 'SIGNATURE_CHECK'
   25 | SIGNATURE_CHECK (putenv, int, (char *));
      | ^~~~~~~~~~~~~~~
  1. initstate() and srandom()

LIBCn declares like: https://github.com/bitwiseworks/libc/blob/7a15da98a2c81aeb6341859bf5409586eea19241/src/emx/include/stdlib.h#L190 https://github.com/bitwiseworks/libc/blob/7a15da98a2c81aeb6341859bf5409586eea19241/src/emx/include/stdlib.h#L218

POSIX requires:

char *initstate(unsigned seed, char *state, size_t size);
void srandom(unsigned seed);

The following is errors from GNULIB test-suites:

In file included from test-random.c:21:
test-random.c:22:18: error: initialization of 'void (*)(unsigned int)' from incompatible pointer type 'void (*)(long unsigned int)' [-Wincompatible-pointer-types]
   22 | SIGNATURE_CHECK (srandom, void, (unsigned int));
      |                  ^~~~~~~
signature.h:46:57: note: in definition of macro 'SIGNATURE_CHECK2'
   46 |   _GL_UNUSED static ret (*signature_check ## id) args = fn
      |                                                         ^~
signature.h:39:3: note: in expansion of macro 'SIGNATURE_CHECK1'
   39 |   SIGNATURE_CHECK1 (fn, ret, args, __LINE__)
      |   ^~~~~~~~~~~~~~~~
test-random.c:22:1: note: in expansion of macro 'SIGNATURE_CHECK'
   22 | SIGNATURE_CHECK (srandom, void, (unsigned int));
      | ^~~~~~~~~~~~~~~
test-random.c:23:18: error: initialization of 'char * (*)(unsigned int,  char *, size_t)' {aka 'char * (*)(unsigned int,  char *, unsigned int)'} from incompatible pointer type 'char * (*)(long unsigned int,  char *, long int)' [-Wincompatible-pointer-types]
   23 | SIGNATURE_CHECK (initstate, char *, (unsigned int, char *, size_t));
      |                  ^~~~~~~~~
signature.h:46:57: note: in definition of macro 'SIGNATURE_CHECK2'
   46 |   _GL_UNUSED static ret (*signature_check ## id) args = fn
      |                                                         ^~
signature.h:39:3: note: in expansion of macro 'SIGNATURE_CHECK1'
   39 |   SIGNATURE_CHECK1 (fn, ret, args, __LINE__)
      |   ^~~~~~~~~~~~~~~~
test-random.c:23:1: note: in expansion of macro 'SIGNATURE_CHECK'
   23 | SIGNATURE_CHECK (initstate, char *, (unsigned int, char *, size_t));
      | ^~~~~~~~~~~~~~~
komh commented 1 month ago
  1. iconv()

LIBCn declares like: https://github.com/bitwiseworks/libc/blob/7a15da98a2c81aeb6341859bf5409586eea19241/src/emx/include/iconv.h#L37

POSIX requires:

size_t iconv(iconv_t cd, char **restrict inbuf, size_t *restrict inbytesleft, char **restrict outbuf, size_t *restrict outbytesleft);

See https://pubs.opengroup.org/onlinepubs/9699919799.2013edition/functions/iconv.html.

The following is errors from MPlayer:

gcc -MMD -MP -Wundef -W -Wall -Wall -Wno-switch -Wno-parentheses -Wpointer-arith -Wredundant-decls -Werror=format-security -Wstrict-prototypes -Wmissing-prototypes -Wdisabled-optimization -Wno-pointer-sign -Wdeclaration-after-statement -std=c11 -Werror-implicit-function-declaration -D_ISOC99_SOURCE -I. -Iffmpeg -O2 -march=i586 -mtune=i586 -pipe -g -fno-tree-vectorize -fno-asynchronous-unwind-tables -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -D_EMX_SOURCE -I/usr/local/include -I/usr/local/include -I/usr/local/include/freetype2 -I/usr/local/include -I/usr/local/include/libpng16 -I/usr/local/include -I/usr/local/include/freetype2 -I/usr/local/include -I/usr/local/include/libpng16 -I/usr/local/include -I/usr/local/include/freetype2 -I/usr/local/include -I/usr/local/include/libpng16 -DZLIB_CONST -I/usr/local/include/libxml2 -I/usr/local/include -c -o mp_msg.o mp_msg.c
mp_msg.c: In function 'mp_msg_va':
mp_msg.c:236:30: error: passing argument 2 of 'iconv' from incompatible pointer type [-Wincompatible-pointer-types]
  236 |       while (iconv(msgiconv, &in, &inlen, &out, &outlen) == -1) {
      |                              ^~~
      |                              |
      |                              char **
In file included from mp_msg.c:29:
g:/usr/include/iconv.h:37:31: note: expected 'const char **' but argument is of type 'char **'
   37 | extern size_t iconv (iconv_t, const char **, size_t *, char **, size_t *);
      |                               ^~~~~~~~~~~~~
mp_msg.c:236:58: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'unsigned int'} and 'int' [-Wsign-compare]
  236 |       while (iconv(msgiconv, &in, &inlen, &out, &outlen) == -1) {
      |                                                          ^~

In addition, all the many feature tests of iconv() of configure fail due to this when using GCC14.