unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* build fails with new MinGW wchar.h
@ 2013-11-20  7:24 Claudio Bley
  2013-11-20 18:15 ` Eli Zaretskii
  0 siblings, 1 reply; 6+ messages in thread
From: Claudio Bley @ 2013-11-20  7:24 UTC (permalink / raw)
  To: emacs-devel

Hi.

When trying to build emacs on w32 using the latest MinGW, the build
failed for some reason I can't remember (something about mbstate_t
being defined twice).

Basically, it was because configure determined that the MinGW headers
did not define mbstate_t in wchar.h which is actually wrong.

The configure test failed with this error message:

---------------------------------------------------------------------------------------------------------------
c:\mingw\include\wchar.h:816:32: error: conflicting types for '_wstat64i32'
 __CRT_MAYBE_INLINE int __cdecl _wstat64i32(const wchar_t *fname, struct _stat64i32 *_stat)
                                ^
c:\mingw\include\wchar.h:814:29: note: previous declaration of '_wstat64i32' was here
 int __cdecl __MINGW_NOTHROW _wstat64i32 (const wchar_t*, struct _stat64i32*);
                             ^
c:\mingw\include\wchar.h: In function '_wstat64i32':
c:\mingw\include\wchar.h:818:20: error: storage size of 'st' isn't known
     struct _stat64 st;
                    ^
c:\mingw\include\wchar.h:821:31: error: invalid application of 'sizeof' to incomplete type 'struct _stat64i32'
       memset(_stat, 0, sizeof(struct _stat64i32));
                               ^
c:\mingw\include\wchar.h:824:10: error: dereferencing pointer to incomplete type
     _stat->st_dev = st.st_dev;
          ^
c:\mingw\include\wchar.h:825:10: error: dereferencing pointer to incomplete type
     _stat->st_ino = st.st_ino;
          ^
c:\mingw\include\wchar.h:826:10: error: dereferencing pointer to incomplete type
     _stat->st_mode = st.st_mode;
          ^
c:\mingw\include\wchar.h:827:10: error: dereferencing pointer to incomplete type
     _stat->st_nlink = st.st_nlink;
          ^
c:\mingw\include\wchar.h:828:10: error: dereferencing pointer to incomplete type
     _stat->st_uid = st.st_uid;
          ^
c:\mingw\include\wchar.h:829:10: error: dereferencing pointer to incomplete type
     _stat->st_gid = st.st_gid;
          ^
c:\mingw\include\wchar.h:830:10: error: dereferencing pointer to incomplete type
     _stat->st_rdev = st.st_rdev;
          ^
c:\mingw\include\wchar.h:831:10: error: dereferencing pointer to incomplete type
     _stat->st_size = (_off_t) st.st_size;
          ^
c:\mingw\include\wchar.h:832:10: error: dereferencing pointer to incomplete type
     _stat->st_atime = st.st_atime;
          ^
c:\mingw\include\wchar.h:833:10: error: dereferencing pointer to incomplete type
     _stat->st_mtime = st.st_mtime;
...
---------------------------------------------------------------------------------------------------------------

The wchar.h header was installed from mingwrt-4.0.3-1-mingw32-dev:

,----[ wchar.h ]
| /**
|  * @file wchar.h
|  * Copyright 2012, 2013 MinGW.org project
`----

It duplicates definitions from sys/stat.h instead of including that file,
conflicting with the overrides from nt/inc/sys/stat.h if both are included:

,----[ wchar.h ]
| /* @TODO: Use sys/stat.h to define these instead of duplicated code. */
| #ifndef _STAT_DEFINED 
| ...
| #endif
| ...
| #if !defined ( _WSTAT_DEFINED) /* also declared in sys/stat.h */ 
| ...
`----

This patch fixes it for me:

---- 8< -------- >8 ---------------- 8< ------------- >8 -------------
diff --git a/nt/inc/sys/stat.h b/nt/inc/sys/stat.h
index f1d8341..88352b1 100644
--- a/nt/inc/sys/stat.h
+++ b/nt/inc/sys/stat.h
@@ -23,6 +23,8 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */

 #ifdef __MINGW32__
 # include <_mingw.h>
+# define _STAT_DEFINED
+# define _WSTAT_DEFINED
 #endif

 /* Only MinGW 3.13 and later has __MINGW_NOTHROW.  */
---- 8< -------- >8 ---------------- 8< ------------- >8 -------------

-- 
Claudio




^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: build fails with new MinGW wchar.h
  2013-11-20  7:24 build fails with new MinGW wchar.h Claudio Bley
@ 2013-11-20 18:15 ` Eli Zaretskii
  2013-11-21  7:36   ` Claudio Bley
  0 siblings, 1 reply; 6+ messages in thread
From: Eli Zaretskii @ 2013-11-20 18:15 UTC (permalink / raw)
  To: Claudio Bley; +Cc: emacs-devel

> From: claudio.bley@gmail.com (Claudio Bley)
> Date: Wed, 20 Nov 2013 08:24:06 +0100
> 
> c:\mingw\include\wchar.h:816:32: error: conflicting types for '_wstat64i32'
>  __CRT_MAYBE_INLINE int __cdecl _wstat64i32(const wchar_t *fname, struct _stat64i32 *_stat)
>                                 ^
> c:\mingw\include\wchar.h:814:29: note: previous declaration of '_wstat64i32' was here
>  int __cdecl __MINGW_NOTHROW _wstat64i32 (const wchar_t*, struct _stat64i32*);
>                              ^
> c:\mingw\include\wchar.h: In function '_wstat64i32':
> c:\mingw\include\wchar.h:818:20: error: storage size of 'st' isn't known
>      struct _stat64 st;
>                     ^
> c:\mingw\include\wchar.h:821:31: error: invalid application of 'sizeof' to incomplete type 'struct _stat64i32'
>        memset(_stat, 0, sizeof(struct _stat64i32));
>                                ^
> c:\mingw\include\wchar.h:824:10: error: dereferencing pointer to incomplete type
>      _stat->st_dev = st.st_dev;
>           ^
> c:\mingw\include\wchar.h:825:10: error: dereferencing pointer to incomplete type

The reason is that MinGW Runtime 4.x added a few more variants of
'struct stat', which nt/inc/sys/stat.h does not have.

> This patch fixes it for me:

Thanks.

> diff --git a/nt/inc/sys/stat.h b/nt/inc/sys/stat.h
> index f1d8341..88352b1 100644
> --- a/nt/inc/sys/stat.h
> +++ b/nt/inc/sys/stat.h
> @@ -23,6 +23,8 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
> 
>  #ifdef __MINGW32__
>  # include <_mingw.h>
> +# define _STAT_DEFINED

Why did you need this part?  nt/inc/sys/stat.h already defines
_STAT_DEFINED, why do we need a second definition.

> +# define _WSTAT_DEFINED

We cannot define this symbol without also declaring the structures
guarded by it in the MinGW headers.  We should add them, and then
define _WSTAT_DEFINED.



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: build fails with new MinGW wchar.h
  2013-11-20 18:15 ` Eli Zaretskii
@ 2013-11-21  7:36   ` Claudio Bley
  2013-11-21 17:36     ` Eli Zaretskii
  2014-01-11 14:50     ` Eli Zaretskii
  0 siblings, 2 replies; 6+ messages in thread
From: Claudio Bley @ 2013-11-21  7:36 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

At Wed, 20 Nov 2013 20:15:41 +0200,
Eli Zaretskii wrote:
> 
> > diff --git a/nt/inc/sys/stat.h b/nt/inc/sys/stat.h
> > index f1d8341..88352b1 100644
> > --- a/nt/inc/sys/stat.h
> > +++ b/nt/inc/sys/stat.h
> > @@ -23,6 +23,8 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
> > 
> >  #ifdef __MINGW32__
> >  # include <_mingw.h>
> > +# define _STAT_DEFINED
> 
> Why did you need this part?  nt/inc/sys/stat.h already defines
> _STAT_DEFINED, why do we need a second definition.

I just did not realize that it already has that defined.

> > +# define _WSTAT_DEFINED
> 
> We cannot define this symbol without also declaring the structures
> guarded by it in the MinGW headers.  We should add them, and then
> define _WSTAT_DEFINED.

Why? Since those declarations are not used anyway, what's the point in
defining them in the first place?

Furthermore, this define actually does not guard declarations of any
structures, but only guards declarations of the functions:

_wstat
_wstat32
_wstat64
_wstat32i64
_wstat64i32

IMO, since none of those functions is used in Emacs' code base, we're
already set.

/ Claudio



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: build fails with new MinGW wchar.h
  2013-11-21  7:36   ` Claudio Bley
@ 2013-11-21 17:36     ` Eli Zaretskii
  2014-01-11 14:50     ` Eli Zaretskii
  1 sibling, 0 replies; 6+ messages in thread
From: Eli Zaretskii @ 2013-11-21 17:36 UTC (permalink / raw)
  To: Claudio Bley; +Cc: emacs-devel

> Date: Thu, 21 Nov 2013 08:36:23 +0100
> From: Claudio Bley <claudio.bley@googlemail.com>
> Cc: emacs-devel@gnu.org
> 
> > > +# define _WSTAT_DEFINED
> > 
> > We cannot define this symbol without also declaring the structures
> > guarded by it in the MinGW headers.  We should add them, and then
> > define _WSTAT_DEFINED.
> 
> Why? Since those declarations are not used anyway, what's the point in
> defining them in the first place?

They are not currently used in Emacs, that's true, but they _are_ used
in wchar.h, which defines inline functions that reference members of
these structs.  That's why you got error messages in the first place.

> Furthermore, this define actually does not guard declarations of any
> structures, but only guards declarations of the functions:
> 
> _wstat
> _wstat32
> _wstat64
> _wstat32i64
> _wstat64i32

It guards both, because some of these functions are inline and use the
struct.

> IMO, since none of those functions is used in Emacs' code base, we're
> already set.

That would work for now, but is fragile: the moment the current
arrangement changes a bit (e.g., we start using wchar_t functions in
the Windows build), the problem will raise its ugly head again.  We
should play by the rules, and define these symbols only if everything
they guard is indeed defined/declared.



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: build fails with new MinGW wchar.h
  2013-11-21  7:36   ` Claudio Bley
  2013-11-21 17:36     ` Eli Zaretskii
@ 2014-01-11 14:50     ` Eli Zaretskii
  2014-01-14 10:28       ` Claudio Bley
  1 sibling, 1 reply; 6+ messages in thread
From: Eli Zaretskii @ 2014-01-11 14:50 UTC (permalink / raw)
  To: Claudio Bley; +Cc: emacs-devel

> Date: Thu, 21 Nov 2013 08:36:23 +0100
> From: Claudio Bley <claudio.bley@googlemail.com>
> Cc: emacs-devel@gnu.org
> 
> > > +# define _WSTAT_DEFINED
> > 
> > We cannot define this symbol without also declaring the structures
> > guarded by it in the MinGW headers.  We should add them, and then
> > define _WSTAT_DEFINED.
> 
> Why? Since those declarations are not used anyway, what's the point in
> defining them in the first place?

I eventually concluded that you were right, and installed the above
change in your name.

Thanks.



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: build fails with new MinGW wchar.h
  2014-01-11 14:50     ` Eli Zaretskii
@ 2014-01-14 10:28       ` Claudio Bley
  0 siblings, 0 replies; 6+ messages in thread
From: Claudio Bley @ 2014-01-14 10:28 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

At Sat, 11 Jan 2014 16:50:23 +0200,
Eli Zaretskii wrote:
> 
> > Date: Thu, 21 Nov 2013 08:36:23 +0100
> > From: Claudio Bley <claudio.bley@googlemail.com>
> > Cc: emacs-devel@gnu.org
> > 
> > > > +# define _WSTAT_DEFINED
> > > 
> > > We cannot define this symbol without also declaring the structures
> > > guarded by it in the MinGW headers.  We should add them, and then
> > > define _WSTAT_DEFINED.
> > 
> > Why? Since those declarations are not used anyway, what's the point in
> > defining them in the first place?
> 
> I eventually concluded that you were right, and installed the above
> change in your name.

Thank you!

Regards,
Claudio
-- 
Claudio



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-01-14 10:28 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-20  7:24 build fails with new MinGW wchar.h Claudio Bley
2013-11-20 18:15 ` Eli Zaretskii
2013-11-21  7:36   ` Claudio Bley
2013-11-21 17:36     ` Eli Zaretskii
2014-01-11 14:50     ` Eli Zaretskii
2014-01-14 10:28       ` Claudio Bley

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).