diff options
author | Armin Rigo <arigo@tunes.org> | 2013-11-10 12:00:30 +0100 |
---|---|---|
committer | Armin Rigo <arigo@tunes.org> | 2013-11-10 12:00:30 +0100 |
commit | 4370664a6f2dad76a51c66b99caf00a8d514e618 (patch) | |
tree | 577a03f12dcddb3900561e49e9c7587b2e54716e /cffi/vengine_gen.py | |
parent | f531a6ad30a6424593d4d67cdf1de359eb8c3db7 (diff) | |
download | cffi-4370664a6f2dad76a51c66b99caf00a8d514e618.tar.gz |
Issue #118: improve the detection and error message, jumping
through hoops to cover both signed and unsigned cases.
Diffstat (limited to 'cffi/vengine_gen.py')
-rw-r--r-- | cffi/vengine_gen.py | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/cffi/vengine_gen.py b/cffi/vengine_gen.py index 97a70e2..f8715c7 100644 --- a/cffi/vengine_gen.py +++ b/cffi/vengine_gen.py @@ -422,11 +422,22 @@ class VGenericEngine(object): prnt('int %s(char *out_error)' % funcname) prnt('{') for enumerator, enumvalue in zip(tp.enumerators, tp.enumvalues): - prnt(' if (%s != %d) {' % (enumerator, enumvalue)) + if enumvalue < 0: + prnt(' if ((%s) >= 0 || (long)(%s) != %dL) {' % ( + enumerator, enumerator, enumvalue)) + else: + prnt(' if ((%s) < 0 || (unsigned long)(%s) != %dUL) {' % ( + enumerator, enumerator, enumvalue)) + prnt(' char buf[64];') + prnt(' if ((%s) < 0)' % enumerator) + prnt(' snprintf(buf, 63, "%%ld", (long)(%s));' % enumerator) + prnt(' else') + prnt(' snprintf(buf, 63, "%%lu", (unsigned long)(%s));' % + enumerator) prnt(' snprintf(out_error, 255,' - '"%s has the real value %d, not %d",') - prnt(' "%s", (int)%s, %d);' % ( - enumerator, enumerator, enumvalue)) + ' "%s has the real value %s, not %s",') + prnt(' "%s", buf, "%d");' % ( + enumerator, enumvalue)) prnt(' return -1;') prnt(' }') prnt(' return 0;') |