bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gnulib bugs on OSX & C++


From: Jarno Rajahalme
Subject: gnulib bugs on OSX & C++
Date: Wed, 7 Apr 2010 21:50:34 -0700

Here is a simple program to demonstrate two problems with current gnulib:

file main.cc:

// config.h defines GNULIB_NAMESPACE as gnulib
#include <config.h>
#include <string.h>
#include <unistd.h>
#include <stdio.h>

int main()
{
  char * dir = gnulib::strndup(gnulib::getcwd(NULL, 32), 
gnulib::strnlen("Hello!", 5));
  int fd = gnulib::open("hopefully non-existent file", O_RDONLY);
  gnulib::fprintf(stdout, "Current Working Directory truncated to 5 characters: 
%s\n", dir);
  gnulib::close(fd);
  return 0;
}


Compiling this with GCC 4.4.3 on OSX 10.6.3 produces two problems:

1. compiling main.cc fails:

g++-mp-4.4 -DHAVE_CONFIG_H -I. -I..  -I../lib -g  -g -O2 -MT main.o -MD -MP -MF 
.deps/main.Tpo -c -o main.o main.cc
In file included from main.cc:4:
../lib/unistd.h:730: error: 'fchownat' was not declared in this scope
../lib/unistd.h:730: error: invalid type in declaration before ';' token


This can be fixed by modifying the lib/unistd.in.h as follows:

*** lib/unistd.in.h~    Wed Apr  7 13:30:09 2010
--- lib/unistd.in.h     Wed Apr  7 14:18:50 2010
***************
*** 459,465 ****
--- 459,467 ----
  _GL_CXXALIAS_SYS (fchownat, int, (int fd, char const *file,
                                    uid_t owner, gid_t group, int flag));
  # endif
+ # if @HAVE_FCHOWNAT@
  _GL_CXXALIASWARN (fchownat);
+ # endif
  #elif defined GNULIB_POSIXCHECK
  # undef fchownat
  # if HAVE_RAW_DECL_FCHOWNAT

The changed code produces the warning only if the system actually has a 
fchownat() that could be accidentally called.


2. After fixing the above, compilation is successful, but gives warnings due to 
the _GL_CXXALIASWARN macro:

Compile:
g++-mp-4.4 -DHAVE_CONFIG_H -I. -I..  -I../lib -g  -g -O2 -MT main.o -MD -MP -MF 
.deps/main.Tpo -c -o main.o main.cc
main.cc: In function 'int main()':
main.cc:9: warning: call to 'rpl_strnlen' declared with attribute warning: The 
symbol ::rpl_strnlen refers to the system function. Use gnulib::rpl_strnlen 
instead.
main.cc:9: warning: call to 'strndup' declared with attribute warning: The 
symbol ::strndup refers to the system function. Use gnulib::strndup instead.
main.cc:12: warning: call to 'close' declared with attribute warning: The 
symbol ::close refers to the system function. Use gnulib::close instead.

Note: These warnings do not appear when no optimization is specified (-O0).

There are a couple of weird things about this:

- strndup is defined as a macro (rpl_strnlen) in config.h, while there is no 
conflict, as OSX does not have strnlen. However, strndup is not defined as a 
macro, even though it is also missing.
- warnings are given about both rpl_strnlen and strndup, even though the system 
does not even have conflicting functions.
- open() does not trigger a warning, while close() does.

And finally:

- I also had the program crash on malloc error when I accidentally had the 
fprintf format string containing "%S" (apparently expecting wide character 
input, while not getting it) instead of "%s".

Regards,

  Jarno Rajahalme





reply via email to

[Prev in Thread] Current Thread [Next in Thread]