[Freeciv-Dev] (PR#39849) strcasestr warning

2007-11-08 Thread Jason Dorje Short

http://bugs.freeciv.org/Ticket/Display.html?id=39849 >

ruleset.c: In function 'load_city_name_list':
ruleset.c:2289: warning: implicit declaration of function 'strcasestr'
ruleset.c:2289: warning: comparison between pointer and integer

Now I'm not sure why I get this warning, since string.h is included and 
that should contain strcasestr.  Perhaps I have some -pedantic parameter 
or something.

But, strcasestr is a nonstandard glibc extension.  To be portable we 
need to use mystrcasestr and have a configure-time check or just 
implement it ourselves.  Or avoid using it, of course.

-jason



___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev


[Freeciv-Dev] (PR#39849) strcasestr warning

2007-11-27 Thread Jason Short

http://bugs.freeciv.org/Ticket/Display.html?id=39849 >

> [EMAIL PROTECTED] - Tue Nov 27 17:48:50 2007]:
> 
> On 27/11/2007, Marko Lindqvist wrote:
> >  Now I got this same error in Ubuntu system.
> >
> >  It seems that user has to define "_GNU_SOURCE" for "__USE_GNU" to
> be defined.
> >
> >  No idea how it always gets set at configure time.
> 
>  Patch to define it both configure and compile time.

This *can't* be the right fix.

First of all, why is configure finding the function when it can't be
found by gcc later?

Secondly, _GNU_SOURCE? Is this a real define or just something internal
to glibc?  Why would strcasestr not be presented to the user by default
as the manual indicated?

Honestly this looks like a glibc bug.

-jason


___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev


[Freeciv-Dev] (PR#39849) strcasestr warning

2007-11-27 Thread Jason Short

http://bugs.freeciv.org/Ticket/Display.html?id=39849 >

Oops.  Your AC_GNU_SOURCE macro works and compiles fine but some time
later I notice the cryptic warning

+ running aclocal ...
configure.ac:168: warning: AC_COMPILE_IFELSE was called before AC_GNU_SOURCE
../../lib/autoconf/specific.m4:331: AC_GNU_SOURCE is expanded from...
configure.ac:168: the top level

during autogen.

I'm not sure what this refers to as AC_COMPILE_IFELSE is not called
directly anywhere in there.

However I'm going to commit this patch to move the AC_GNU_SOURCE call up
to the top with the other base platform checks.

-jason

Index: configure.ac
===
--- configure.ac	(revision 14085)
+++ configure.ac	(working copy)
@@ -8,6 +8,7 @@
 AC_CONFIG_AUX_DIR(bootstrap) # This can't be quoted or automake will fail
 AM_CONFIG_HEADER(config.h)
 AC_CANONICAL_HOST
+AC_GNU_SOURCE
 
 PACKAGE=freeciv
 
@@ -164,9 +165,6 @@
 	WITH_EFENCE=1
 )
 
-dnl Check for GNU libc
-AC_GNU_SOURCE
-
 dnl Checks for programs.
 AC_PROG_AWK
 AC_PROG_CC
___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev


Re: [Freeciv-Dev] (PR#39849) strcasestr warning

2007-11-09 Thread William Allen Simpson

http://bugs.freeciv.org/Ticket/Display.html?id=39849 >

Jason Dorje Short wrote:
> But, strcasestr is a nonstandard glibc extension.  To be portable we 
> need to use mystrcasestr and have a configure-time check or just 
> implement it ourselves.  Or avoid using it, of course.
> 
Actually a standard BSD libc function, and in the standard required Linux
glibc since time immemorial.  But apparently not in cygwin.

But since that's the only place used, I'll write a replacement later today,
assuming you don't beat me to it.



___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev


Re: [Freeciv-Dev] (PR#39849) strcasestr warning

2007-11-09 Thread William Allen Simpson

http://bugs.freeciv.org/Ticket/Display.html?id=39849 >

Naive trunk implementation:


Index: utility/support.c
===
--- utility/support.c   (revision 13930)
+++ utility/support.c   (working copy)
@@ -156,6 +156,40 @@
 }
 
 /***
+  Return the needle in the haystack (or NULL).
+  Naive implementation.
+***/
+char *mystrcasestr(const char *haystack, const char *needle)
+{
+#ifdef HAVE_STRCASESTR
+  return strcasestr(haystack, needle);
+#else
+  size_t haystacks;
+  size_t needles;
+  const char *p;
+
+  if (NULL == needle || '\0' == *needle) {
+return (char *)haystack;
+  }
+  if (NULL == haystack || '\0' == *haystack) {
+return NULL;
+  }
+  haystacks = strlen(haystack);
+  needles = strlen(needle);
+  if (haystacks < needles) {
+return NULL;
+  }
+
+  for (p = haystack; p <= &haystack[haystacks - needles]; p++) {
+if (0 == mystrncasecmp(p, needle, needles)) {
+  return (char *)p;
+}
+  }
+  return NULL;
+#endif
+}
+
+/***
   Return a string which describes a given error (errno-style.)
 ***/
 const char *mystrerror(void)
Index: utility/support.h
===
--- utility/support.h   (revision 13930)
+++ utility/support.h   (working copy)
@@ -74,6 +74,8 @@
 int mystrncasecmp(const char *str0, const char *str1, size_t n);
 int mystrncasequotecmp(const char *str0, const char *str1, size_t n);
 
+char *mystrcasestr(const char *haystack, const char *needle);
+
 const char *mystrerror(void);
 void myusleep(unsigned long usec);
 
Index: server/ruleset.c
===
--- server/ruleset.c(revision 13930)
+++ server/ruleset.c(working copy)
@@ -2286,7 +2286,7 @@
* Note that the section name is unique (by definition).
* The sub-strings are carefully crafted for this function.
*/
- if (NULL != strcasestr(isection, name)) {
+ if (NULL != mystrcasestr(isection, name)) {
city_names[j].terrain[i] = setting;
handled = TRUE;
break;
___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev


Re: [Freeciv-Dev] (PR#39849) strcasestr warning

2007-11-09 Thread Jason Dorje Short

http://bugs.freeciv.org/Ticket/Display.html?id=39849 >

William Allen Simpson wrote:
> http://bugs.freeciv.org/Ticket/Display.html?id=39849 >
> 
> Naive trunk implementation:

Naive is fine but you forgot to add the check to configure.ac.  Attached 
patch does that.

But now it still won't compile, and I don't understand why.

if gcc -DHAVE_CONFIG_H -I. -I. -I.. 
-DLOCALEDIR="\"/usr/local/share/locale\"" 
-DDEFAULT_DATA_PATH="\".:data:~/.freeciv:/usr/local/share/freeciv\""  -g 
-O0 -Wall -Werror -Wcast-align -Wmissing-prototypes 
-Wmissing-declarations -MT support.o -MD -MP -MF ".deps/support.Tpo" -c 
-o support.o support.c; \
 then mv -f ".deps/support.Tpo" ".deps/support.Po"; else rm -f 
".deps/support.Tpo"; exit 1; fi
cc1: warnings being treated as errors
support.c: In function 'mystrcasestr':
support.c:167: warning: implicit declaration of function 'strcasestr'
support.c:167: warning: return makes pointer from integer without a cast

Of course I have strcasestr, it's detected properly so HAVE_STRCASESTR 
is defined.  The function is in string.h which is properly included. 
Yet in compiling the prototype is apparently not being included.

This is on debian testing.

-jason

Index: utility/support.c
===
--- utility/support.c	(revision 13930)
+++ utility/support.c	(working copy)
@@ -156,6 +156,40 @@
 }
 
 /***
+  Return the needle in the haystack (or NULL).
+  Naive implementation.
+***/
+char *mystrcasestr(const char *haystack, const char *needle)
+{
+#ifdef HAVE_STRCASESTR
+  return strcasestr(haystack, needle);
+#else
+  size_t haystacks;
+  size_t needles;
+  const char *p;
+
+  if (NULL == needle || '\0' == *needle) {
+return (char *)haystack;
+  }
+  if (NULL == haystack || '\0' == *haystack) {
+return NULL;
+  }
+  haystacks = strlen(haystack);
+  needles = strlen(needle);
+  if (haystacks < needles) {
+return NULL;
+  }
+
+  for (p = haystack; p <= &haystack[haystacks - needles]; p++) {
+if (0 == mystrncasecmp(p, needle, needles)) {
+  return (char *)p;
+}
+  }
+  return NULL;
+#endif
+}
+
+/***
   Return a string which describes a given error (errno-style.)
 ***/
 const char *mystrerror(void)
Index: utility/support.h
===
--- utility/support.h	(revision 13930)
+++ utility/support.h	(working copy)
@@ -74,6 +74,8 @@
 int mystrncasecmp(const char *str0, const char *str1, size_t n);
 int mystrncasequotecmp(const char *str0, const char *str1, size_t n);
 
+char *mystrcasestr(const char *haystack, const char *needle);
+
 const char *mystrerror(void);
 void myusleep(unsigned long usec);
 
Index: configure.ac
===
--- configure.ac	(revision 13930)
+++ configure.ac	(working copy)
@@ -607,7 +607,7 @@
 
 AC_CHECK_FUNCS([fileno ftime gethostname getpwuid inet_aton \
 		select snooze strerror strcasecmp strncasecmp \
-		strlcat strlcpy strstr usleep uname flock \
+		strcasestr strlcat strlcpy strstr usleep uname flock \
 		gethostbyname connect bind])
 
 AC_MSG_CHECKING(for working gettimeofday)
Index: server/ruleset.c
===
--- server/ruleset.c	(revision 13930)
+++ server/ruleset.c	(working copy)
@@ -2286,7 +2286,7 @@
* Note that the section name is unique (by definition).
* The sub-strings are carefully crafted for this function.
*/
-	  if (NULL != strcasestr(isection, name)) {
+	  if (NULL != mystrcasestr(isection, name)) {
 	city_names[j].terrain[i] = setting;
 	handled = TRUE;
 		break;
___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev


Re: [Freeciv-Dev] (PR#39849) strcasestr warning

2007-11-09 Thread Jason Dorje Short

http://bugs.freeciv.org/Ticket/Display.html?id=39849 >

Jason Dorje Short wrote:
> http://bugs.freeciv.org/Ticket/Display.html?id=39849 >
> 
> William Allen Simpson wrote:
>> http://bugs.freeciv.org/Ticket/Display.html?id=39849 >
>>
>> Naive trunk implementation:
> 
> Naive is fine but you forgot to add the check to configure.ac.  Attached 
> patch does that.
> 
> But now it still won't compile, and I don't understand why.

Still strange.

Delving into the preprocessor, if I just throw a -E on to the above line 
the resulting file has no prototype for the function at all.  Yet it is 
clearly present in the header, surrounded by #ifdef __USE_GNU which is 
presumably being left undefined somehow in compilation while it was 
defined properly during the configure check.

I suppose I could upload my string.h if anyone has any bright ideas.

-jason



___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev


Re: [Freeciv-Dev] (PR#39849) strcasestr warning

2007-11-09 Thread William Allen Simpson

http://bugs.freeciv.org/Ticket/Display.html?id=39849 >

Jason Dorje Short wrote:
>> Naive is fine but you forgot to add the check to configure.ac.  Attached 
>> patch does that.
>>
I didn't forget; that ensured my new code was compiled and tested


> ... Yet it is 
> clearly present in the header, surrounded by #ifdef __USE_GNU which is 
> presumably being left undefined somehow in compilation while it was 
> defined properly during the configure check.
> 
My guess is that the wrong string.h (or strings.h) is included.  We've been
having problems with includes for some time.  I have posted various reports
about it (PR#39403 still open, though I haven't tested it recently).  Like
you, I was having similar problems with the faculty present during configure
check, but not during compile.

Marko was poking at them last.

Since your original report turns out to be fixed by my patch, and it will
fix cygwin systems, and we've both verified it works correctly without the
configure.ac check, I'll commit it.



___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev


Re: [Freeciv-Dev] (PR#39849) strcasestr warning

2007-11-27 Thread Egor Vyscrebentsov

http://bugs.freeciv.org/Ticket/Display.html?id=39849 >

On Fri, 9 Nov 2007 22:26:56 -0800 Jason Dorje Short wrote:

> Jason Dorje Short wrote:
> > 
> > William Allen Simpson wrote:
> >>
> >> Naive trunk implementation:
> > 
> > Naive is fine but you forgot to add the check to configure.ac.  Attached 
> > patch does that.
> > 
> > But now it still won't compile, and I don't understand why.
> 
> Still strange.
> 
> Delving into the preprocessor, if I just throw a -E on to the above line 
> the resulting file has no prototype for the function at all.  Yet it is 
> clearly present in the header, surrounded by #ifdef __USE_GNU which is 
> presumably being left undefined somehow in compilation while it was 
> defined properly during the configure check.
> 
> I suppose I could upload my string.h if anyone has any bright ideas.

Doesn't
  #define _GNU_SOURCE
required before including  to use strcasestr()?
(Or have I read man 3 strcasestr wrongly?)

Well, it works for me if I apply attached patch. (Note, that
placing #define right before #include  gives no effect.)

-- 
Thanks, evyscr

Index: utility/support.c
===
--- utility/support.c	(revision 14083)
+++ utility/support.c	(working copy)
@@ -41,6 +41,10 @@
 #include 
 #endif
 
+#ifdef HAVE_STRCASESTR
+#define _GNU_SOURCE
+#endif
+
 #include 
 #include 
 #include 
___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev


Re: [Freeciv-Dev] (PR#39849) strcasestr warning

2007-11-27 Thread Marko Lindqvist

http://bugs.freeciv.org/Ticket/Display.html?id=39849 >

On 10/11/2007, Jason Dorje Short <[EMAIL PROTECTED]> wrote:
>
>  #ifdef __USE_GNU which is
> presumably being left undefined somehow in compilation while it was
> defined properly during the configure check.

 I had similar problems in debian testing some time ago, when gcc
headers were including (incompatible) glibc headers.
 For this + miscompilation problem I have been using gcc compiled by
myself lately. I should again test with current debian package.


 - ML



___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev


Re: [Freeciv-Dev] (PR#39849) strcasestr warning

2007-11-27 Thread Marko Lindqvist

http://bugs.freeciv.org/Ticket/Display.html?id=39849 >

 Now I got this same error in Ubuntu system.

 It seems that user has to define "_GNU_SOURCE" for "__USE_GNU" to be defined.

 > ( export CFLAGS="-D_GNU_SOURCE" && ./autogen.sh && make)
 works


 No idea how it always gets set at configure time.


 - ML



___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev


Re: [Freeciv-Dev] (PR#39849) strcasestr warning

2007-11-27 Thread Marko Lindqvist

http://bugs.freeciv.org/Ticket/Display.html?id=39849 >

On 27/11/2007, Marko Lindqvist wrote:
>  Now I got this same error in Ubuntu system.
>
>  It seems that user has to define "_GNU_SOURCE" for "__USE_GNU" to be defined.
>
>  No idea how it always gets set at configure time.

 Patch to define it both configure and compile time.


 - ML

--- configure.ac	2007-11-27 20:27:58.0 +0200
+++ configure.ac	2007-11-27 20:28:07.0 +0200
@@ -164,6 +164,9 @@
 	WITH_EFENCE=1
 )
 
+dnl Check for GNU libc
+AC_GNU_SOURCE
+
 dnl Checks for programs.
 AC_PROG_AWK
 AC_PROG_CC
___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev


Re: [Freeciv-Dev] (PR#39849) strcasestr warning

2007-11-27 Thread Egor Vyscrebentsov

http://bugs.freeciv.org/Ticket/Display.html?id=39849 >

On Tue, 27 Nov 2007 10:10:57 -0800 Jason Short wrote:

> > [cazfi74 - Tue Nov 27 17:48:50 2007]:
> > On 27/11/2007, Marko Lindqvist wrote:
> > >  Now I got this same error in Ubuntu system.
> > >
> > >  It seems that user has to define "_GNU_SOURCE" for "__USE_GNU" to
> > > be defined.
> > >
> > >  No idea how it always gets set at configure time.
> >
> >  Patch to define it both configure and compile time.
>
> This *can't* be the right fix.
>
> First of all, why is configure finding the function when it can't be
> found by gcc later?

It doesn't give a warning about implicit function for the next file:
=
#include  
#include  

int main(void)
{
  char *c;

  c = strcasestr("123456", "45");
  printf("%s", c);
}
=
However, the warning about "assignment makes pointer from integer
without a cast" is present until "#define _GNU_SOURCE" is added. It is
also _shown_ if this define placed _after_ "#include "

Main thought here is that we have different includes while configuring
and while compiling, and this may affects.

We also have different gcc parameters at the configure time and at the
compile time.

> Secondly, _GNU_SOURCE? Is this a real define or just something internal
> to glibc?  Why would strcasestr not be presented to the user by default
> as the manual indicated?

Which manual?!

SYNOPSIS
   #include 

   char *strstr(const char *haystack, const char *needle);

   #define _GNU_SOURCE

   #include 

   char *strcasestr(const char *haystack, const char *needle);

CONFORMING TO
   The  strstr() function conforms to C89 and C99.  The strcasestr() func-
   tion is a non-standard extension.

> Honestly this looks like a glibc bug.

Don't think so.

-- 
Thanks, evyscr



___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev


Re: [Freeciv-Dev] (PR#39849) strcasestr warning

2007-11-27 Thread Marko Lindqvist

http://bugs.freeciv.org/Ticket/Display.html?id=39849 >

On 27/11/2007, Jason Short <[EMAIL PROTECTED]> wrote:
>
> > [EMAIL PROTECTED] - Tue Nov 27 17:48:50 2007]:
> >
> > On 27/11/2007, Marko Lindqvist wrote:
> > >  Now I got this same error in Ubuntu system.
> > >
> > >  It seems that user has to define "_GNU_SOURCE" for "__USE_GNU" to
> > be defined.
> > >
> > >  No idea how it always gets set at configure time.
> >
> >  Patch to define it both configure and compile time.
>
> This *can't* be the right fix.

 AC_GNU_SOURCE is what autoconf manual tells one to use. It's not fix
to the actual bug (wherever that is) but gets around it.

> First of all, why is configure finding the function when it can't be
> found by gcc later?

 This seems like autoconf bug. It should not find it when
AC_GNU_SOURCE is not used.

> Secondly, _GNU_SOURCE? Is this a real define or just something internal
> to glibc?  Why would strcasestr not be presented to the user by default
> as the manual indicated?

_GNU_SOURCE is documented as user (from glibc point of view) settable macro:
http://www.gnu.org/software/libc/manual/html_node/Feature-Test-Macros.html


 Glibc manual mentions that "strcasecmp is derived from BSD." Maybe
one is expected to read that as "strcasecmp is available only when
_BSD_SOURCE or _GNU_SOURCE is defined."


> Honestly this looks like a glibc bug.

 ...or gcc. There has been ongoing discussion for years if they should
define _GNU_SOURCE by default or not. I saw some comment saying that
currently g++ defines it, but gcc not!


 - ML



___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev


Re: [Freeciv-Dev] (PR#39849) strcasestr warning

2007-11-27 Thread Jason Dorje Short

http://bugs.freeciv.org/Ticket/Display.html?id=39849 >

Egor Vyscrebentsov wrote:

> Main thought here is that we have different includes while configuring
> and while compiling, and this may affects.

The compiler notification is only a warning...the compilation will 
succeed if -Werror is not on...so perhaps configure gets the warning but 
succeeds the check anyway.

> We also have different gcc parameters at the configure time and at the
> compile time.
> 
>> Secondly, _GNU_SOURCE? Is this a real define or just something internal
>> to glibc?  Why would strcasestr not be presented to the user by default
>> as the manual indicated?
> 
> Which manual?!

Oh.  Right.  Guess we need to just add AC_GNU_SOURCE then.

-jason



___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev