You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Gisle Vanem <gi...@bgnett.no> on 2004/08/26 23:58:59 UTC

Inline problems on MingW

Has anybody attempted building APR using MingW? The win32 portion
of the headers seems rather MSVC centric. I don't know if it's supposed
to works since I found no reference to MingW on apache.org or in the docs.

Anyway, in include\arch\win32\apr_arch_atime.h:

__inline void FileTimeToAprTime(apr_time_t *result, FILETIME *input)
{
    /* Convert FILETIME one 64 bit number so we can work with it. */
    *result = input->dwHighDateTime;

Gave heaps of duplicate errors when linking the test programs.
I assume it's because MSVC and gcc have different handling of 
inline and __inline. g++ is more like MSVC I believe. I tried to fix it 
in apr.hw:

#if defined(__GNUC__)
#define APR_INLINE extern __inline__ /* expanded on -O2 or above */
#else
#define APR_INLINE __inline
#endif

Which gave new error when some .c-files had thing like
static APR_INLINE void ..

(double modifiers). Would it be okay to replace the above with simply 
__inline? Or do we need a new "#define APR_INLINE_PRIVATE __inline"
or something?

--gv



Re: Inline problems on MingW

Posted by Joe Orton <jo...@redhat.com>.
On Mon, Aug 30, 2004 at 07:48:24PM +0200, Gisle Vanem wrote:
> So how to turn off inlining? I mean functions like FileTimeToAprTime()
> must be in 1 .o-file with "gcc -O0" too. One way is to put this at end of
> time/win32/time.c:

These should simply be fixed in the Win32 headers to be static, unless
that hurts the MSVC interpretation of '__inline' somehow in which case
something more subtle would be needed.

Otherwise it breaks with GCC, as you say, since gcc will emit a global
symbol for a non-static inline function, so putting such a declaration
in a header file won't work if the header included more than once.

joe

Re: Inline problems on MingW

Posted by Gisle Vanem <gi...@bgnett.no>.
"Cliff Woolley" wrote:

> Crap, I mised that detail.  Anyway I find it difficult to believe that
> this is an insoluable problem, since it works fine on a real
> configure-generated apr.h on other platforms that uses gcc.  Ah, I see my
> apr.h generated on Linux uses __inline__ instead of __inline (no extern).
> Does that help your situation at all?

So you bloating your Linux binaries/shared-libs for no reason.

__inline__ foo (void)
{
  puts ("Hello world");
}

This puts a foo() in every object regardless of you call foo() or
not. Use objdump to check. Adding an "extern" only adds foo() 
if it is called or referenced. gcc on MingW or djgpp has done this 
for a long time. I'd be amassed if this was any different on gcc/Linux.

--gv

Re: Inline problems on MingW

Posted by Cliff Woolley <jw...@virginia.edu>.
On Mon, 30 Aug 2004, Gisle Vanem wrote:

> Did you read and understand my 1st message? Stuff like
> static APR_INLINE void copy_array_hdr_core (in apr_tables.c)
>
> wouldn't compile. I.e. becoming "static extern __inline ..".

Crap, I mised that detail.  Anyway I find it difficult to believe that
this is an insoluable problem, since it works fine on a real
configure-generated apr.h on other platforms that uses gcc.  Ah, I see my
apr.h generated on Linux uses __inline__ instead of __inline (no extern).
Does that help your situation at all?

(In case you can't tell, I really don't like the idea of doing this in
every single header file that might need it, so I'm trying to find every
possible way to avoid it.  :)

--Cliff

Re: Inline problems on MingW

Posted by Gisle Vanem <gi...@bgnett.no>.
"Cliff Woolley" wrote:

> Um, why not just do this in apr.hw?
> 
> #ifndef __GNUC__
> #define APR_INLINE __inline
> #else
> #define APR_INLINE extern __inline
> #endif
> 
> Seems the cleanest way to me by far.  That is, after all, what apr.h is
> for.

Did you read and understand my 1st message? Stuff like
static APR_INLINE void copy_array_hdr_core (in apr_tables.c)

wouldn't compile. I.e. becoming "static extern __inline ..".

> > Another problem is that "extern __inline" code will *not* be inlined with
> > "gcc -O0" (__NO_INLINE__ becomes a built-in). So a gcc-built DLL must
> > use -O1 or higher unless we "sweep up" such inline functions in a src-file.
> 
> This is surely not a problem, right?  Only debug builds will use -O0, in
> which case you don't really want inlining anyway.

So how to turn off inlining? I mean functions like FileTimeToAprTime()
must be in 1 .o-file with "gcc -O0" too. One way is to put this at end of
time/win32/time.c:

#if defined(__GNUC__) && defined(__NO_INLINE__)
#undef ATIME_G
#include <apr_arch_atime.h>
#endif

Same for the other headerinliners.

--gv


Re: Inline problems on MingW

Posted by Cliff Woolley <jw...@virginia.edu>.
On Mon, 30 Aug 2004, Gisle Vanem wrote:

> Okay, I worked on the original problem and found a viable fix; Leave the
> APR_INLINE in apr.hw as-is:
>
> #define APR_INLINE __inline
>
> But in headers like arch\win32\apr_arch_atime.h, with inline code do at
> top:
>
> #ifdef __GNUC__
> #undef  APR_INLINE
> #define APR_INLINE extern __inline
> #endif

Um, why not just do this in apr.hw?

#ifndef __GNUC__
#define APR_INLINE __inline
#else
#define APR_INLINE extern __inline
#endif

Seems the cleanest way to me by far.  That is, after all, what apr.h is
for.

> Another problem is that "extern __inline" code will *not* be inlined with
> "gcc -O0" (__NO_INLINE__ becomes a built-in). So a gcc-built DLL must
> use -O1 or higher unless we "sweep up" such inline functions in a src-file.

This is surely not a problem, right?  Only debug builds will use -O0, in
which case you don't really want inlining anyway.

> BTW. Could we please have a bit more intuitive suffixes to the
> config-files? I.e. apr.h.netware, apr.h.win32 etc. Just my 0.2€

I was under the impression that the suffixes were short to be more
8.3-friendly (silly legacy file systems).  Could be wrong.

--Cliff

Re: Inline problems on MingW

Posted by Gisle Vanem <gi...@bgnett.no>.
Sorry for the late reply,

"Cliff Woolley" <jw...@virginia.edu> wrote:

> That said, APR does build on cygwin (or at least it used to at some
> distant point in the past), so I see no reason why it shouldn't be made to
> build on mingw.

I have attempted some Cygwin hacking, but prefer MingW for it's runtime
speed (-tune=pentium rivals MSVC6 with all optimise flags on).

> Feel free to submit those patches, appropriately #ifdef'ed so that they
> won't break the msvc build (or if you submitted them already and we missed
> them, please give us a pointer to them again).

Okay, I worked on the original problem and found a viable fix; Leave the
APR_INLINE in apr.hw as-is:

#define APR_INLINE __inline

But in headers like arch\win32\apr_arch_atime.h, with inline code do at
top:

#ifdef __GNUC__
#undef  APR_INLINE
#define APR_INLINE extern __inline
#endif

APR_INLINE void FileTimeToAprTime(apr_time_t *result, FILETIME *input)
{
  ...
}
at bottom:

#ifdef __GNUC__
#undef  APR_INLINE
#define APR_INLINE __inline
#endif

"extern __inline" is the only usable form AFAICS gcc will work with. Otherwise
we'll get bloated .o-files and possibly duplicate symbol errors when linking
the DLLs. I don't know the gcc details.

But IMO the best would to do:


#ifdef __GNUC__
  extern __inline
#else
  APR_INLINE  /* whatever this is */
#endif
void FileTimeToAprTime(apr_time_t *result, FILETIME *input)
{
  ..

What way do you prefer? I need to hear comments on this before I
commit any MingW patches.

Another problem is that "extern __inline" code will *not* be inlined with
"gcc -O0" (__NO_INLINE__ becomes a built-in). So a gcc-built DLL must
use -O1 or higher unless we "sweep up" such inline functions in a src-file.

BTW. Could we please have a bit more intuitive suffixes to the
config-files? I.e. apr.h.netware, apr.h.win32 etc. Just my 0.2€

--gv



Re: Inline problems on MingW

Posted by Cliff Woolley <jw...@virginia.edu>.
On Sat, 28 Aug 2004, Gisle Vanem wrote:

> > Has anybody attempted building APR using MingW? The win32 portion
> > of the headers seems rather MSVC centric. I don't know if it's supposed
> > to works since I found no reference to MingW on apache.org or in the docs.

Our win32 support is indeed MSVC-centric, for the two reasons that (a)
that's what pretty much all of our win32 developers use and (b) apr
typically attempts to do things in the "most native" way on a given
platform.

That said, APR does build on cygwin (or at least it used to at some
distant point in the past), so I see no reason why it shouldn't be made to
build on mingw.

> I have managed to build all the DLLs with minor patches to the *.hw.

Feel free to submit those patches, appropriately #ifdef'ed so that they
won't break the msvc build (or if you submitted them already and we missed
them, please give us a pointer to them again).

Thanks,
--Cliff

Re: Inline problems on MingW

Posted by Gisle Vanem <gi...@bgnett.no>.
> Has anybody attempted building APR using MingW? The win32 portion
> of the headers seems rather MSVC centric. I don't know if it's supposed
> to works since I found no reference to MingW on apache.org or in the docs.

I didn't get any response on this. Does this mean MingW is not
considered an interesting platform for Win32 developement?
IMHO it rocks.

I have managed to build all the DLLs with minor patches to the *.hw.
I also used my own makefiles, since the configure didn't work for
MingW (they seldom do).

--gv