Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: "Pierre Muller" <pierre.muller@ics-cnrs.unistra.fr>
To: "'nick clifton'" <nickc@redhat.com>,
	"'Pedro Alves'" <palves@redhat.com>,
	       "'asmwarrior'" <asmwarrior@gmail.com>
Cc: "'GDB Development'" <gdb@sourceware.org>,
	       "'Binutils Development'" <binutils@sourceware.org>
Subject: [RFC-v2] BFD MinGW/Cygwin build error in bfd/peiXXgen.c
Date: Thu, 19 Dec 2013 11:45:00 -0000	[thread overview]
Message-ID: <006c01cefcaf$bec215b0$3c464110$@muller@ics-cnrs.unistra.fr> (raw)
In-Reply-To: <52B1E03E.9010002@redhat.com>

  Hi Nick,

  After looking at the code a little longer,
I think that there were still other issues in that part
of the code.
  1) The astring and bstring were still not declared
for the last macro case (hosts having no wchar header).
  I solved this issue by placing the declarations
at the start of the function.
  2) In GDB coding rules, we are not allowed to mix code and declaration.
The declaration of res after handling the ! is_name part
does not follow this rule.
  Isn't that rule also used for Binutils project?
  I moved the declaration of astring, alen, bstring and blen to
the start of the function. It does introduce a penalty, in the sense that
those variables are set even though this is not useful if is_name is false.
  Otherwise adding an extra brace level might be the proper solution.
Another silly coding style question: Should there by a space
between the address operator "&" and the variable or expression following?

  3) I was wondering why the Windows case started at astring + 2,
but I couldn't find any valid reason, so that I changed it to
compare the strings from the first position. 
  4) I did the same for the code if wchar is missing.
  5) To have a symmetric code for cygwin versus mingw,
I introduced a macro called rscpcmp for both cases.

  Finally, I also have a question regarding the codepage field.
According to Windows PE resources can use any codepage.
Is the new code restricted to UNICODE only?
If not, shouldn't the rsrc_cmp code also depend on whether 
16-bit Windows UNICODE is used or any other page code?

  The main problem is that I have no source code to test this code on...


Pierre Muller

PS: I removed the fixme as suggested by Pedro.




2013-12-19  Pierre Muller  <muller@sourceware.org>

	peXXigen.c (u16_mbtouc): Avoid unused function warning by excluding if
	__CYGWIN__ or __MINGW32__ macro is defined.
	(rsrc_cmp): Fix Windows host version and version without wchar header.
	[__CYGWIN__, __MINGW32__]: Introduce rsrccmp macro.


diff --git a/bfd/peXXigen.c b/bfd/peXXigen.c
index 2a33a77..f5879f6 100644
--- a/bfd/peXXigen.c
+++ b/bfd/peXXigen.c
@@ -2930,7 +2930,7 @@ rsrc_write_directory (rsrc_write_data * data,
   BFD_ASSERT (nt == next_entry);
 }

-#ifdef HAVE_WCHAR_H
+#if defined HAVE_WCHAR_H && ! defined __CYGWIN__ && ! defined __MINGW32__
 /* Return the length (number of units) of the first character in S,
    putting its 'ucs4_t' representation in *PUC.  */

@@ -2974,22 +2974,30 @@ static signed int
 rsrc_cmp (bfd_boolean is_name, rsrc_entry * a, rsrc_entry * b)
 {
   if (! is_name)
-    return a->name_id.id - b->name_id.id;
+    return a->name_id.id - b->name_id.id;

   /* We have to perform a case insenstive, unicode string comparison...  */
   int res;
-
-#ifdef __CYGWIN__
-  /* Under Cygwin unicode == UTF-16 == wchar_t.
-     FIXME: The same is true for MingGW - we should test for that too.  */
-  res = wcsncasecmp ((const wchar_t *) astring + 2, (const wchar_t *) bstring + 2, min (alen, blen));
-#elif defined HAVE_WCHAR_H
-  unsigned int  i;
   bfd_byte *    astring = a->name_id.name.string;
   unsigned int  alen    = a->name_id.name.len;
   bfd_byte *    bstring = b->name_id.name.string;
   unsigned int  blen    = b->name_id.name.len;

+#if defined  __CYGWIN__ || defined __MINGW32__
+#undef rscpcmp
+#ifdef __CYGWIN__
+#define rscpcmp wcsncasecmp
+#endif
+#ifdef __MINGW32__
+#define rscpcmp wcsnicmp
+#endif
+  /* Under Windows hosts (both cygwin and mingw types),
+     unicode == UTF-16 == wchar_t.  */
+  res = rscpcmp ((const wchar_t *) astring, (const wchar_t *) bstring,
+                min (alen, blen));
+#elif defined HAVE_WCHAR_H
+  unsigned int  i;
+
   res = 0;
   for (i = min (alen, blen); i--; astring += 2, bstring += 2)
     {
@@ -3008,7 +3016,7 @@ rsrc_cmp (bfd_boolean is_name, rsrc_entry * a, rsrc_entry * b)
        break;
     }
 #else
-  res = memcmp (astring + 2, bstring + 2, min (alen, blen) * 2);
+  res = memcmp (astring, bstring, min (alen, blen) * 2);
 #endif

   if (res == 0)


  reply	other threads:[~2013-12-19 11:45 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-18  9:54 GDB MinGW build error: implicit declaration of function 'wcsncasecmp' asmwarrior
2013-12-18  9:58 ` asmwarrior
2013-12-18 10:06 ` BFD " Pedro Alves
2013-12-18 12:50   ` asmwarrior
2013-12-18 15:47     ` Eli Zaretskii
2013-12-18 13:03   ` [RFC] BFD MinGW/Cygwin build error in bfd/peiXXgen.c Pierre Muller
2013-12-18 17:52     ` nick clifton
2013-12-19 11:45       ` Pierre Muller [this message]
2013-12-19 12:41         ` [RFC-v2] " nick clifton
2013-12-19 13:02           ` Mark Kettenis
2013-12-19 13:18           ` Pierre Muller
2013-12-19 15:13             ` nick clifton
     [not found]   ` <52b19d01.22cbc20a.69b0.ffffb29eSMTPIN_ADDED_BROKEN@mx.google.com>
2013-12-18 13:25     ` [RFC] " asmwarrior
     [not found]   ` <52b19d19.0850420a.7b6a.52dcSMTPIN_ADDED_BROKEN@mx.google.com>
2013-12-18 17:56     ` Pedro Alves
2013-12-19 11:15       ` nick clifton
2013-12-18 15:35 ` GDB MinGW build error: implicit declaration of function 'wcsncasecmp' Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='006c01cefcaf$bec215b0$3c464110$@muller@ics-cnrs.unistra.fr' \
    --to=pierre.muller@ics-cnrs.unistra.fr \
    --cc=asmwarrior@gmail.com \
    --cc=binutils@sourceware.org \
    --cc=gdb@sourceware.org \
    --cc=nickc@redhat.com \
    --cc=palves@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox