diff mbox

qapi: Fix compilation failure on MIPS

Message ID 1454424701-26111-1-git-send-email-eblake@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Eric Blake Feb. 2, 2016, 2:51 p.m. UTC
Commit 86f4b687 broke compilation on MIPS, which has a preprocessor
pollution of '#define mips 1'.  Treat it the same way as we do for
the pollution with 'unix', so that QMP remains backwards compatible
and only the C code needs to use the alternative 'q_mips' spelling.

CC: James Hogan <james.hogan@imgtec.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
---
 scripts/qapi.py | 2 +-
 cpus.c          | 4 ++--
 hmp.c           | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

Comments

James Hogan Feb. 2, 2016, 3:06 p.m. UTC | #1
On Tue, Feb 02, 2016 at 07:51:41AM -0700, Eric Blake wrote:
> Commit 86f4b687 broke compilation on MIPS, which has a preprocessor
> pollution of '#define mips 1'.  Treat it the same way as we do for
> the pollution with 'unix', so that QMP remains backwards compatible
> and only the C code needs to use the alternative 'q_mips' spelling.
> 
> CC: James Hogan <james.hogan@imgtec.com>
> Signed-off-by: Eric Blake <eblake@redhat.com>

Thanks, that fixes the build for me.

Tested-by: James Hogan <james.hogan@imgtec.com>

Cheers
James

> ---
>  scripts/qapi.py | 2 +-
>  cpus.c          | 4 ++--
>  hmp.c           | 2 +-
>  3 files changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/scripts/qapi.py b/scripts/qapi.py
> index d199222..7f114c4 100644
> --- a/scripts/qapi.py
> +++ b/scripts/qapi.py
> @@ -1482,7 +1482,7 @@ def c_name(name, protect=True):
>                       'and', 'and_eq', 'bitand', 'bitor', 'compl', 'not',
>                       'not_eq', 'or', 'or_eq', 'xor', 'xor_eq'])
>      # namespace pollution:
> -    polluted_words = set(['unix', 'errno'])
> +    polluted_words = set(['unix', 'errno', 'mips'])
>      name = name.translate(c_name_trans)
>      if protect and (name in c89_words | c99_words | c11_words | gcc_words
>                      | cpp_words | polluted_words):
> diff --git a/cpus.c b/cpus.c
> index 882b618..c8a2317 100644
> --- a/cpus.c
> +++ b/cpus.c
> @@ -1581,8 +1581,8 @@ CpuInfoList *qmp_query_cpus(Error **errp)
>          info->value->u.sparc->npc = env->npc;
>  #elif defined(TARGET_MIPS)
>          info->value->arch = CPU_INFO_ARCH_MIPS;
> -        info->value->u.mips = g_new0(CpuInfoMIPS, 1);
> -        info->value->u.mips->PC = env->active_tc.PC;
> +        info->value->u.q_mips = g_new0(CpuInfoMIPS, 1);
> +        info->value->u.q_mips->PC = env->active_tc.PC;
>  #elif defined(TARGET_TRICORE)
>          info->value->arch = CPU_INFO_ARCH_TRICORE;
>          info->value->u.tricore = g_new0(CpuInfoTricore, 1);
> diff --git a/hmp.c b/hmp.c
> index a4b74df..ef98344 100644
> --- a/hmp.c
> +++ b/hmp.c
> @@ -322,7 +322,7 @@ void hmp_info_cpus(Monitor *mon, const QDict *qdict)
>              monitor_printf(mon, " npc=0x%016" PRIx64, cpu->value->u.sparc->npc);
>              break;
>          case CPU_INFO_ARCH_MIPS:
> -            monitor_printf(mon, " PC=0x%016" PRIx64, cpu->value->u.mips->PC);
> +            monitor_printf(mon, " PC=0x%016" PRIx64, cpu->value->u.q_mips->PC);
>              break;
>          case CPU_INFO_ARCH_TRICORE:
>              monitor_printf(mon, " PC=0x%016" PRIx64, cpu->value->u.tricore->PC);
> -- 
> 2.5.0
>
Markus Armbruster Feb. 2, 2016, 4:14 p.m. UTC | #2
Eric Blake <eblake@redhat.com> writes:

> Commit 86f4b687 broke compilation on MIPS, which has a preprocessor
> pollution of '#define mips 1'.  Treat it the same way as we do for
> the pollution with 'unix', so that QMP remains backwards compatible
> and only the C code needs to use the alternative 'q_mips' spelling.
>
> CC: James Hogan <james.hogan@imgtec.com>
> Signed-off-by: Eric Blake <eblake@redhat.com>

Applied to qapi-next, thanks!
Peter Maydell Feb. 2, 2016, 5:26 p.m. UTC | #3
On 2 February 2016 at 14:51, Eric Blake <eblake@redhat.com> wrote:
> Commit 86f4b687 broke compilation on MIPS, which has a preprocessor
> pollution of '#define mips 1'.  Treat it the same way as we do for
> the pollution with 'unix', so that QMP remains backwards compatible
> and only the C code needs to use the alternative 'q_mips' spelling.
>
> CC: James Hogan <james.hogan@imgtec.com>
> Signed-off-by: Eric Blake <eblake@redhat.com>
> ---
>  scripts/qapi.py | 2 +-
>  cpus.c          | 4 ++--
>  hmp.c           | 2 +-
>  3 files changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/scripts/qapi.py b/scripts/qapi.py
> index d199222..7f114c4 100644
> --- a/scripts/qapi.py
> +++ b/scripts/qapi.py
> @@ -1482,7 +1482,7 @@ def c_name(name, protect=True):
>                       'and', 'and_eq', 'bitand', 'bitor', 'compl', 'not',
>                       'not_eq', 'or', 'or_eq', 'xor', 'xor_eq'])
>      # namespace pollution:
> -    polluted_words = set(['unix', 'errno'])
> +    polluted_words = set(['unix', 'errno', 'mips'])
>      name = name.translate(c_name_trans)
>      if protect and (name in c89_words | c99_words | c11_words | gcc_words
>                      | cpp_words | polluted_words):

Looking at commit 86f4b687 I think we also need to add 'sparc' to the
polluted_words list (Solaris defines that). I would also be unsurprised
to find that some PPC platforms define 'ppc'. (Tricore is probably
new enough to have escaped this namespace pollution and we don't
support it as a host CPU anyway.)

thanks
-- PMM
Eric Blake Feb. 2, 2016, 5:45 p.m. UTC | #4
On 02/02/2016 10:26 AM, Peter Maydell wrote:
> On 2 February 2016 at 14:51, Eric Blake <eblake@redhat.com> wrote:
>> Commit 86f4b687 broke compilation on MIPS, which has a preprocessor
>> pollution of '#define mips 1'.  Treat it the same way as we do for
>> the pollution with 'unix', so that QMP remains backwards compatible
>> and only the C code needs to use the alternative 'q_mips' spelling.
>>
>> CC: James Hogan <james.hogan@imgtec.com>
>> Signed-off-by: Eric Blake <eblake@redhat.com>
>> ---

>>      # namespace pollution:
>> -    polluted_words = set(['unix', 'errno'])
>> +    polluted_words = set(['unix', 'errno', 'mips'])
>>      name = name.translate(c_name_trans)
>>      if protect and (name in c89_words | c99_words | c11_words | gcc_words
>>                      | cpp_words | polluted_words):
> 
> Looking at commit 86f4b687 I think we also need to add 'sparc' to the
> polluted_words list (Solaris defines that). I would also be unsurprised
> to find that some PPC platforms define 'ppc'. (Tricore is probably
> new enough to have escaped this namespace pollution and we don't
> support it as a host CPU anyway.)

Do we have anyone that can confirm on these platforms?  Obviously, I
proved that it's fairly easy to work around, and I don't mind doing the
followup patch(es), but only if we have concrete cases where we know it
is needed.
Peter Maydell Feb. 2, 2016, 6:16 p.m. UTC | #5
On 2 February 2016 at 17:45, Eric Blake <eblake@redhat.com> wrote:
> On 02/02/2016 10:26 AM, Peter Maydell wrote:
>> On 2 February 2016 at 14:51, Eric Blake <eblake@redhat.com> wrote:
>>> Commit 86f4b687 broke compilation on MIPS, which has a preprocessor
>>> pollution of '#define mips 1'.  Treat it the same way as we do for
>>> the pollution with 'unix', so that QMP remains backwards compatible
>>> and only the C code needs to use the alternative 'q_mips' spelling.
>>>
>>> CC: James Hogan <james.hogan@imgtec.com>
>>> Signed-off-by: Eric Blake <eblake@redhat.com>
>>> ---
>
>>>      # namespace pollution:
>>> -    polluted_words = set(['unix', 'errno'])
>>> +    polluted_words = set(['unix', 'errno', 'mips'])
>>>      name = name.translate(c_name_trans)
>>>      if protect and (name in c89_words | c99_words | c11_words | gcc_words
>>>                      | cpp_words | polluted_words):
>>
>> Looking at commit 86f4b687 I think we also need to add 'sparc' to the
>> polluted_words list (Solaris defines that). I would also be unsurprised
>> to find that some PPC platforms define 'ppc'. (Tricore is probably
>> new enough to have escaped this namespace pollution and we don't
>> support it as a host CPU anyway.)
>
> Do we have anyone that can confirm on these platforms?  Obviously, I
> proved that it's fairly easy to work around, and I don't mind doing the
> followup patch(es), but only if we have concrete cases where we know it
> is needed.

I just started up the elderly debian sparc VM image I have lying
around and installed the compiler, which is enough to confirm that
it does "#define sparc 1".

We know PPC Linux doesn't define 'ppc' because the ppc64be build
I do as part of pull request processing worked OK.
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=728710#25
suggests it uses "powerpc" and "PPC" so we're OK there.

thanks
-- PMM
diff mbox

Patch

diff --git a/scripts/qapi.py b/scripts/qapi.py
index d199222..7f114c4 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -1482,7 +1482,7 @@  def c_name(name, protect=True):
                      'and', 'and_eq', 'bitand', 'bitor', 'compl', 'not',
                      'not_eq', 'or', 'or_eq', 'xor', 'xor_eq'])
     # namespace pollution:
-    polluted_words = set(['unix', 'errno'])
+    polluted_words = set(['unix', 'errno', 'mips'])
     name = name.translate(c_name_trans)
     if protect and (name in c89_words | c99_words | c11_words | gcc_words
                     | cpp_words | polluted_words):
diff --git a/cpus.c b/cpus.c
index 882b618..c8a2317 100644
--- a/cpus.c
+++ b/cpus.c
@@ -1581,8 +1581,8 @@  CpuInfoList *qmp_query_cpus(Error **errp)
         info->value->u.sparc->npc = env->npc;
 #elif defined(TARGET_MIPS)
         info->value->arch = CPU_INFO_ARCH_MIPS;
-        info->value->u.mips = g_new0(CpuInfoMIPS, 1);
-        info->value->u.mips->PC = env->active_tc.PC;
+        info->value->u.q_mips = g_new0(CpuInfoMIPS, 1);
+        info->value->u.q_mips->PC = env->active_tc.PC;
 #elif defined(TARGET_TRICORE)
         info->value->arch = CPU_INFO_ARCH_TRICORE;
         info->value->u.tricore = g_new0(CpuInfoTricore, 1);
diff --git a/hmp.c b/hmp.c
index a4b74df..ef98344 100644
--- a/hmp.c
+++ b/hmp.c
@@ -322,7 +322,7 @@  void hmp_info_cpus(Monitor *mon, const QDict *qdict)
             monitor_printf(mon, " npc=0x%016" PRIx64, cpu->value->u.sparc->npc);
             break;
         case CPU_INFO_ARCH_MIPS:
-            monitor_printf(mon, " PC=0x%016" PRIx64, cpu->value->u.mips->PC);
+            monitor_printf(mon, " PC=0x%016" PRIx64, cpu->value->u.q_mips->PC);
             break;
         case CPU_INFO_ARCH_TRICORE:
             monitor_printf(mon, " PC=0x%016" PRIx64, cpu->value->u.tricore->PC);