[PATCH 21.5] Fix build with g++
Jerry James <[email protected]> Wed, 5 Nov 2014 15:51:14 -0700
| Newsgroups | gmane.emacs.xemacs.patches |
|---|---|
| Message-ID | <CAHCOHQ=6yKcjQELvG8FOHXcWVez+HufUWb4FdcJKpUNhm+8B=g@mail.gmail.com> |
PATCH 21.5 This patch fixes a collection of miscellaneous problems that break the build with g++ 4.8.3. Thanks to Mats for pointing out two of the problems. I think the contents of this patch are fairly straightforward, with the exception of the changes to XSTRING_LENGTH and XSTRING_DATA. Before I made those changes, g++ 4.8.3 complained about a possibly uninitialized anonymous value in both alloc.c and fileio.c. I looked briefly at the code, thought it looked okay and that g++ must have lost its marbles, and continued on. Then, after building temacs, it segfaulted while loading lisp, at the exact line in fileio.c where one of the warnings was issued. More digging showed that g++ was creating anonymous temporaries, and not initializing them, instead of using the parameters that I thought it should access. Very weird. I don't understand what is going on there. It may be a bug in g++ 4.8.3, but on the other hand, those macros evaluate their arguments multiple times, which may have something to do with the problem. Anyway, let me know if you object to this solution. diff -r 6928877dbc26 src/ChangeLog --- a/src/ChangeLog Sat Oct 25 15:59:31 2014 +0200 +++ b/src/ChangeLog Wed Nov 05 15:48:49 2014 -0700 @@ -1,3 +1,18 @@ +2014-11-05 Jerry James <[email protected]> + + * ExternalClient-Xlib.c (ExternalClientEventHandler): Cast integer + to long before casting to XPointer, which may be larger than int. + * database.c: Use BEGIN_C_DECLS/END_C_DECLS around dbm definitions. + * lisp.h (ALLOCA): Use NULL instead of (void) 0 to placate g++. + (MALLOC_OR_ALLOCA): Ditto. + (XSTRING_LENGTH): Use an explicit temporary with NEW_GC so g++ 4.8 + won't create an uninitialized anonymous temporary. + (XSTRING_DATA): Ditto. + * sysdll.c: Check whether HAVE_LTDL is defined, not its value. + * tls.c (tls_open): Add typecast to xmalloc call in the nss, + gnutls, and openssl versions to satisfy g++. In the gnutls version, + use gnutls_certificate_type_t appropriately. + 2014-10-25 Michael Sperber <[email protected]> * fontcolor-x.c (x_font_instance_truename): diff -r 6928877dbc26 src/ExternalClient-Xlib.c --- a/src/ExternalClient-Xlib.c Sat Oct 25 15:59:31 2014 +0200 +++ b/src/ExternalClient-Xlib.c Wed Nov 05 15:48:49 2014 -0700 @@ -134,9 +134,10 @@ else return; XFindContext(display, win, focus_context, ¤t_focus); - if (focus_status != (int) current_focus) + if ((XPointer) (long) focus_status != current_focus) { - XSaveContext(display, win, focus_context, (XPointer) focus_status); + XSaveContext(display, win, focus_context, + (XPointer) (long) focus_status); extw_send_notify_3(display, win, focus_status ? extw_notify_focus_in : extw_notify_focus_out, 0, 0, 0); diff -r 6928877dbc26 src/database.c --- a/src/database.c Sat Oct 25 15:59:31 2014 +0200 +++ b/src/database.c Wed Nov 05 15:48:49 2014 -0700 @@ -83,6 +83,7 @@ #endif /* HAVE_BERKELEY_DB */ #ifdef HAVE_DBM +BEGIN_C_DECLS # ifdef TRUST_NDBM_H_PROTOTYPES # include NDBM_H_FILE # else /* not TRUST_NDBM_H_PROTOTYPES */ @@ -91,10 +92,6 @@ using C++, since they are of the form `datum dbm_firstkey()', without any args given. */ -#if defined(__cplusplus) || defined(c_plusplus) -extern "C" { -#endif - /* Parameters to dbm_store for simple insertion or replacement. */ #define DBM_INSERT 0 #define DBM_REPLACE 1 @@ -119,11 +116,9 @@ DBM *dbm_open(const char *, int, mode_t); int dbm_store(DBM *, datum, datum, int); -#if defined(__cplusplus) || defined(c_plusplus) -} -#endif +# endif /* (not) TRUST_NDBM_H_PROTOTYPES */ +END_C_DECLS -# endif /* (not) TRUST_NDBM_H_PROTOTYPES */ Lisp_Object Qdbm; #endif /* HAVE_DBM */ diff -r 6928877dbc26 src/lisp.h --- a/src/lisp.h Sat Oct 25 15:59:31 2014 +0200 +++ b/src/lisp.h Wed Nov 05 15:48:49 2014 -0700 @@ -1368,7 +1368,7 @@ __temp_alloca_size__ = (size), \ __temp_alloca_size__ > MAX_ALLOCA_VS_C_ALLOCA ? \ xemacs_c_alloca (__temp_alloca_size__) : \ - (need_to_check_c_alloca ? xemacs_c_alloca (0) : (void) 0, \ + (need_to_check_c_alloca ? xemacs_c_alloca (0) : NULL, \ alloca (__temp_alloca_size__))) /* Version of ALLOCA() that is guaranteed to work inside of function calls @@ -1402,7 +1402,7 @@ __temp_alloca_size__ = (size), \ __temp_alloca_size__ > MAX_ALLOCA_VS_MALLOC ? \ xmalloc_and_record_unwind (__temp_alloca_size__) : \ - (need_to_check_c_alloca ? xemacs_c_alloca (0) : (void) 0, \ + (need_to_check_c_alloca ? xemacs_c_alloca (0) : NULL, \ alloca (__temp_alloca_size__))) /* -------------- convenience functions for memory allocation ------------- */ @@ -2643,13 +2643,27 @@ #ifdef NEW_GC #define STRING_DATA_OBJECT(s) ((s)->data_object) #define XSTRING_DATA_OBJECT(s) (STRING_DATA_OBJECT (XSTRING (s))) -#define XSTRING_LENGTH(s) (XSTRING_DATA_SIZE (XSTRING (s))) +DECLARE_INLINE_HEADER ( +Bytecount +XSTRING_LENGTH (Lisp_Object s) +) +{ + Lisp_String *str = XSTRING (s); + return XSTRING_DATA_SIZE (str); +} #else /* not NEW_GC */ #define XSTRING_LENGTH(s) (XSTRING (s)->size_) #endif /* not NEW_GC */ #define XSTRING_PLIST(s) (XSTRING (s)->plist) #ifdef NEW_GC -#define XSTRING_DATA(s) (XSTRING_DATA_DATA (XSTRING (s))) +DECLARE_INLINE_HEADER ( +Ibyte * +XSTRING_DATA (Lisp_Object s) +) +{ + Lisp_String *str = XSTRING (s); + return XSTRING_DATA_DATA (str); +} #else /* not NEW_GC */ #define XSTRING_DATA(s) (XSTRING (s)->data_ + 0) #endif /* not NEW_GC */ diff -r 6928877dbc26 src/sysdll.c --- a/src/sysdll.c Sat Oct 25 15:59:31 2014 +0200 +++ b/src/sysdll.c Wed Nov 05 15:48:49 2014 -0700 @@ -454,7 +454,7 @@ NSLinkEditError (&c, &errorNumber, &fileNameWithError, &errorString); return build_extstring (errorString, Qerror_message_encoding); } -#elif HAVE_LTDL +#elif defined(HAVE_LTDL) /* Libtool's libltdl */ #include <ltdl.h> diff -r 6928877dbc26 src/tls.c --- a/src/tls.c Sat Oct 25 15:59:31 2014 +0200 +++ b/src/tls.c Wed Nov 05 15:48:49 2014 -0700 @@ -122,7 +122,7 @@ } /* Create the socket */ - nspr = xmalloc (sizeof (*nspr)); + nspr = (tls_state_t *) xmalloc (sizeof (*nspr)); nspr->tls_refcount = 2; nspr->tls_file_desc = SSL_ImportFD (nss_model, PR_OpenTCPSocket (addr->sa_family)); @@ -507,7 +507,7 @@ setsockopt (s, IPPROTO_TCP, TCP_NODELAY, &val, sizeof(val)); /* Create the state object */ - gnutls = xmalloc (sizeof (*gnutls)); + gnutls = (tls_state_t *) xmalloc (sizeof (*gnutls)); gnutls->tls_refcount = 2; /* Initialize the session object */ @@ -615,7 +615,9 @@ gnutls_datum_t msg; #ifdef HAVE_GNUTLS_CERTIFICATE_VERIFICATION_STATUS_PRINT - int type = gnutls_certificate_type_get (gnutls->tls_session); + gnutls_certificate_type_t type; + + type = gnutls_certificate_type_get (gnutls->tls_session); err = gnutls_certificate_verification_status_print (status, type, &msg, 0); #else @@ -966,7 +968,7 @@ setsockopt (s, IPPROTO_TCP, TCP_NODELAY, &val, sizeof(val)); /* Create the state object */ - openssl = xmalloc (sizeof (*openssl)); + openssl = (tls_state_t *) xmalloc (sizeof (*openssl)); openssl->tls_refcount = 2; /* Create the connection object */ -- Jerry James http://www.jamezone.org/