c_client.py: enumerator values generation

Submitted by Litvinenko, Evgeny on Jan. 17, 2017, 8:17 a.m.

Details

Message ID B090F14416879147852DB59B4633393F01846F3AA0@DB-MBOX-07.dbdc.luxoft.com
State New
Series "c_client.py: enumerator values generation"
Headers show

Commit Message

Litvinenko, Evgeny Jan. 17, 2017, 8:17 a.m.
From 2a9446c38f7f1977b32f85dcf4857db8c676799c Mon Sep 17 00:00:00 2001
From: Evgeny Litvinenko <evgeny.v.litvinenko@gmail.com>
Date: Tue, 17 Jan 2017 09:32:27 +0300
Subject: [PATCH] Convert enumerator values to the range of C 'int'

This fixes warning like the following (when gcc runs with -pedantic-errors)

In file included from xinput.c:14:0:
xinput.h:3079:35: error: ISO C restricts enumerator values to range of 'int' [-Wpedantic]
     XCB_INPUT_MODIFIER_MASK_ANY = 2147483648
                                   ^

In C99 standard (ISO/IEC 9899:1999)
...
6.7.2.2 Enumeration specifiers
The expression that defines the value of an enumeration constant
shall be an integer constant expression
that has a value representable as an int.
...
---
You can use this patch or any parts of it
as you consider it necessary.

 xcbgen/xtypes.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

--
2.11.0



Thanks,
Evgeny.

Patch hide | download patch | download mbox

diff --git a/xcbgen/xtypes.py b/xcbgen/xtypes.py
index b83b119..93db2ad 100644
--- a/xcbgen/xtypes.py
+++ b/xcbgen/xtypes.py
@@ -3,6 +3,7 @@  This module contains the classes which represent XCB data types.
 '''
 from xcbgen.expr import Field, Expression
 from xcbgen.align import Alignment, AlignmentLog
+from ctypes import c_int
 import __main__

 verbose_align_log = False
@@ -243,7 +244,7 @@  class Enum(SimpleType):
             if value.tag == 'value':
                 self.values.append((item.get('name'), value.text))
             elif value.tag == 'bit':
-                self.values.append((item.get('name'), '%u' % (1 << int(value.text, 0))))
+                self.values.append((item.get('name'), '%i' % c_int(1 <<  int(value.text, 0)).value))
                 self.bits.append((item.get('name'), value.text))

     def resolve(self, module):