You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucy.apache.org by Peter Karman <pe...@peknet.com> on 2010/01/15 05:59:27 UTC

c99

marvin@apache.org wrote on 1/14/10 5:53 PM:
> Author: marvin
> Date: Thu Jan 14 23:53:22 2010
> New Revision: 899480
> 
> URL: http://svn.apache.org/viewvc?rev=899480&view=rev
> Log:
> Always build under C99 with GCC.


*sigh*

perhaps this was premature on my part. Now I'm getting failures to compile under 
Linux, CentOS 5 32bit and RHEL 4 64bit both tested, with gcc 4.1.2 and 3.4.6. 
With -std=c99 I get errors like:

../core/KinoSearch/Store/FSFolder.c: In function ‘S_dir_ok’:
../core/KinoSearch/Store/FSFolder.c:292: error: ‘S_IFDIR’ undeclared (first use 
in this function)

and

../core/KinoSearch/Store/FSDirHandle.c: In function ‘kino_FSDH_entry_is_dir’:
../core/KinoSearch/Store/FSDirHandle.c:104: error: ‘DT_DIR’ undeclared (first 
use in this function)



but with no -std=c99 it compiles just fine.

I googled and poked around the code and am just puzzled. The errors indicate 
that some .h is not being properly included, but the code itself has #ifdef 
CHY_HAS_* tests around it, indicating that Charmonizer found the .h just fine. 
And yes, Charmonizer compiles ok with the -std=c99 option.

Weird.

Same holds true for KS 0.30_072 -- I just tried it with -std=c99 and it fails to 
compile with same error:

core/KinoSearch/Util/Compat/DirManip.c: In function ‘kino_DirManip_dir_ok’:
core/KinoSearch/Util/Compat/DirManip.c:36: error: ‘S_IFDIR’ undeclared (first 
use in this function)

core/KinoSearch/Util/Compat/DirManip.c: In function ‘SI_entry_is_dir’:
core/KinoSearch/Util/Compat/DirManip.c:101: error: ‘DT_DIR’ undeclared (first 
use in this function)

I tried it with KINO_DEBUG=1 as well under CentOS5 (gcc 4.1.2) which includes 
-std=c89 and it failed with same error.

So OS X is happy only with c99 and Linux is happy only without it.

thoughts?
-- 
Peter Karman  .  http://peknet.com/  .  peter@peknet.com

Re: c99

Posted by Peter Karman <pe...@peknet.com>.
Marvin Humphrey wrote on 1/15/10 11:24 AM:
> On Fri, Jan 15, 2010 at 08:49:55AM -0800, Eric Howe wrote:
>> Is there some sort of _POSIX_SOURCE, _BSD_SOURCE, _XOPEN_SOURCE, ... macro
>> magic needed to make things behave? 
> 
> I had a peek inside /usr/include/dirent.h on CentOS 5.2 and DT_DIR only gets
> defined if "__BSD" is defined.  Apparently adding "-std=c99" turns that off.
> 
> We probably want to blindly add "-D_GNU_SOURCE" when compiling under GCC.
> 
>   http://www.gnu.org/software/libc/manual/html_node/Feature-Test-Macros.html
> 
> It should be harmless on non-glibc systems.
> 
>     http://mail.python.org/pipermail/python-dev/2000-July/005414.html
> 
>     Defining _GNU_SOURCE on non glibc platforms shouldn't hurt,
>     so I simply dropped the switch.
> 

ah, ok.

Just tested this patch and it worked:

Index: buildlib/KinoSearch/Build.pm
===================================================================
--- buildlib/KinoSearch/Build.pm	(revision 5692)
+++ buildlib/KinoSearch/Build.pm	(working copy)
@@ -76,6 +76,9 @@
          $gcc_version = $1;
          if ($extra_ccflags !~ m/-std=c99/) {
              $extra_ccflags .= "-std=c99 ";
+        }
+        if ($extra_ccflags !~ m/-D_GNU_SOURCE/) {
+            $extra_ccflags .= "-D_GNU_SOURCE ";
          }
      }



-- 
Peter Karman  .  http://peknet.com/  .  peter@peknet.com

Re: [KinoSearch] c99

Posted by Marvin Humphrey <ma...@rectangular.com>.
On Fri, Jan 15, 2010 at 08:49:55AM -0800, Eric Howe wrote:
> Is there some sort of _POSIX_SOURCE, _BSD_SOURCE, _XOPEN_SOURCE, ... macro
> magic needed to make things behave? 

I had a peek inside /usr/include/dirent.h on CentOS 5.2 and DT_DIR only gets
defined if "__BSD" is defined.  Apparently adding "-std=c99" turns that off.

We probably want to blindly add "-D_GNU_SOURCE" when compiling under GCC.

  http://www.gnu.org/software/libc/manual/html_node/Feature-Test-Macros.html

It should be harmless on non-glibc systems.

    http://mail.python.org/pipermail/python-dev/2000-July/005414.html

    Defining _GNU_SOURCE on non glibc platforms shouldn't hurt,
    so I simply dropped the switch.

Marvin Humphrey


Re: [KinoSearch] c99

Posted by Peter Karman <pe...@peknet.com>.
Eric Howe wrote on 1/15/10 10:49 AM:
> S_IFDIR comes from stat.h, right? Is there some sort of _POSIX_SOURCE,
> _BSD_SOURCE, _XOPEN_SOURCE, ... macro magic needed to make things behave? I
> used to have to play around with various combinations of defining and
> undefining various *_SOURCE flags back in my portable C days, different
> combinations for different systems of course. This problem smells like GCC is
> being stricter than we want it to be and it needs to be told to loosen up.
> 
> Just a wild guess.

It was a good guess.

I found the following necessary to compile KS trunk with -std=c99 on Linux. 
Seems like the #define statements ought to be part of what Charmonizer writes to 
charmony.h, based on arch/os detection. Is that right, Marvin? If it is, I can 
prepare a patch.

Index: perl/xs/XSBind.h
===================================================================
--- perl/xs/XSBind.h	(revision 5692)
+++ perl/xs/XSBind.h	(working copy)
@@ -8,6 +8,8 @@
  extern "C" {
  #endif

+#define _XOPEN_SOURCE
+
  #include "charmony.h"
  #include "KinoSearch/Object/Obj.h"
  #include "KinoSearch/Object/ByteBuf.h"
Index: core/KinoSearch/Store/FSDirHandle.c
===================================================================
--- core/KinoSearch/Store/FSDirHandle.c	(revision 5692)
+++ core/KinoSearch/Store/FSDirHandle.c	(working copy)
@@ -1,4 +1,7 @@
  #define C_KINO_FSDIRHANDLE
+#define _XOPEN_SOURCE
+#define _BSD_SOURCE
+
  #include <string.h>
  #include <stdlib.h>
  #include <stdio.h>
Index: core/KinoSearch/Store/FSFolder.c
===================================================================
--- core/KinoSearch/Store/FSFolder.c	(revision 5692)
+++ core/KinoSearch/Store/FSFolder.c	(working copy)
@@ -1,4 +1,7 @@
  #define C_KINO_FSFOLDER
+#define _XOPEN_SOURCE
+#define _BSD_SOURCE
+
  #include "KinoSearch/Util/ToolSet.h"

  #include <ctype.h>




-- 
Peter Karman  .  http://peknet.com/  .  peter@peknet.com

Re: [KinoSearch] c99

Posted by Eric Howe <er...@pieinsky.ca>.
S_IFDIR comes from stat.h, right? Is there some sort of _POSIX_SOURCE, _BSD_SOURCE, _XOPEN_SOURCE, ... macro magic needed to make things behave? I used to have to play around with various combinations of defining and undefining various *_SOURCE flags back in my portable C days, different combinations for different systems of course. This problem smells like GCC is being stricter than we want it to be and it needs to be told to loosen up.

Just a wild guess.


On 2010-01-14, at 20:59 , Peter Karman wrote:

> marvin@apache.org wrote on 1/14/10 5:53 PM:
>> Author: marvin
>> Date: Thu Jan 14 23:53:22 2010
>> New Revision: 899480
>> 
>> URL: http://svn.apache.org/viewvc?rev=899480&view=rev
>> Log:
>> Always build under C99 with GCC.
> 
> 
> *sigh*
> 
> perhaps this was premature on my part. Now I'm getting failures to compile under 
> Linux, CentOS 5 32bit and RHEL 4 64bit both tested, with gcc 4.1.2 and 3.4.6. 
> With -std=c99 I get errors like:
> 
> ../core/KinoSearch/Store/FSFolder.c: In function ‘S_dir_ok’:
> ../core/KinoSearch/Store/FSFolder.c:292: error: ‘S_IFDIR’ undeclared (first use 
> in this function)
> 
> and
> 
> ../core/KinoSearch/Store/FSDirHandle.c: In function ‘kino_FSDH_entry_is_dir’:
> ../core/KinoSearch/Store/FSDirHandle.c:104: error: ‘DT_DIR’ undeclared (first 
> use in this function)
> 
> 
> 
> but with no -std=c99 it compiles just fine.
> 
> I googled and poked around the code and am just puzzled. The errors indicate 
> that some .h is not being properly included, but the code itself has #ifdef 
> CHY_HAS_* tests around it, indicating that Charmonizer found the .h just fine. 
> And yes, Charmonizer compiles ok with the -std=c99 option.
> 
> Weird.
> 
> Same holds true for KS 0.30_072 -- I just tried it with -std=c99 and it fails to 
> compile with same error:
> 
> core/KinoSearch/Util/Compat/DirManip.c: In function ‘kino_DirManip_dir_ok’:
> core/KinoSearch/Util/Compat/DirManip.c:36: error: ‘S_IFDIR’ undeclared (first 
> use in this function)
> 
> core/KinoSearch/Util/Compat/DirManip.c: In function ‘SI_entry_is_dir’:
> core/KinoSearch/Util/Compat/DirManip.c:101: error: ‘DT_DIR’ undeclared (first 
> use in this function)
> 
> I tried it with KINO_DEBUG=1 as well under CentOS5 (gcc 4.1.2) which includes 
> -std=c89 and it failed with same error.
> 
> So OS X is happy only with c99 and Linux is happy only without it.
> 
> thoughts?
> -- 
> Peter Karman  .  http://peknet.com/  .  peter@peknet.com
> 
> _______________________________________________
> kinosearch mailing list
> kinosearch@rectangular.com
> http://rectangular.com/cgi-bin/mailman/listinfo/kinosearch


Eric Howe
eric@pieinsky.ca