[Python-checkins] cpython: Issue #22120: For functions using an unsigned integer return converter,

larry.hastings python-checkins at python.org
Tue Aug 5 11:55:41 CEST 2014


http://hg.python.org/cpython/rev/9c949e0115e2
changeset:   92011:9c949e0115e2
user:        Larry Hastings <larry at hastings.org>
date:        Tue Aug 05 19:55:21 2014 +1000
summary:
  Issue #22120: For functions using an unsigned integer return converter,
Argument Clinic now generates a cast to that type for the comparison
to -1 in the generated code.  (This supresses a compilation warning.)

files:
  Misc/NEWS                   |   4 ++++
  Modules/clinic/binascii.c.h |   4 ++--
  Modules/posixmodule.c       |  12 ++++++------
  Tools/clinic/clinic.py      |   6 +++++-
  4 files changed, 17 insertions(+), 9 deletions(-)


diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -882,6 +882,10 @@
 Tools/Demos
 -----------
 
+- Issue #22120: For functions using an unsigned integer return converter,
+  Argument Clinic now generates a cast to that type for the comparison
+  to -1 in the generated code.  (This supresses a compilation warning.)
+
 - Issue #18974: Tools/scripts/diff.py now uses argparse instead of optparse.
 
 - Issue #21906: Make Tools/scripts/md5sum.py work in Python 3.
diff --git a/Modules/clinic/binascii.c.h b/Modules/clinic/binascii.c.h
--- a/Modules/clinic/binascii.c.h
+++ b/Modules/clinic/binascii.c.h
@@ -320,7 +320,7 @@
         &data, &crc))
         goto exit;
     _return_value = binascii_crc32_impl(module, &data, crc);
-    if ((_return_value == -1) && PyErr_Occurred())
+    if ((_return_value == (unsigned int)-1) && PyErr_Occurred())
         goto exit;
     return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
 
@@ -475,4 +475,4 @@
 
     return return_value;
 }
-/*[clinic end generated code: output=68e2bcc6956b6213 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=53cd6b379c745220 input=a9049054013a1b77]*/
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -12465,7 +12465,7 @@
         &device))
         goto exit;
     _return_value = os_major_impl(module, device);
-    if ((_return_value == -1) && PyErr_Occurred())
+    if ((_return_value == (unsigned int)-1) && PyErr_Occurred())
         goto exit;
     return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
 
@@ -12475,7 +12475,7 @@
 
 static unsigned int
 os_major_impl(PyModuleDef *module, int device)
-/*[clinic end generated code: output=f60d3cc3d5d20325 input=ea48820b7e10d310]*/
+/*[clinic end generated code: output=52e6743300dcf4ad input=ea48820b7e10d310]*/
 {
     return major(device);
 }
@@ -12514,7 +12514,7 @@
         &device))
         goto exit;
     _return_value = os_minor_impl(module, device);
-    if ((_return_value == -1) && PyErr_Occurred())
+    if ((_return_value == (unsigned int)-1) && PyErr_Occurred())
         goto exit;
     return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
 
@@ -12524,7 +12524,7 @@
 
 static unsigned int
 os_minor_impl(PyModuleDef *module, int device)
-/*[clinic end generated code: output=71eca1d5149c2a07 input=089733ebbf9754e8]*/
+/*[clinic end generated code: output=aebe4bd7f455b755 input=089733ebbf9754e8]*/
 {
     return minor(device);
 }
@@ -12565,7 +12565,7 @@
         &major, &minor))
         goto exit;
     _return_value = os_makedev_impl(module, major, minor);
-    if ((_return_value == -1) && PyErr_Occurred())
+    if ((_return_value == (unsigned int)-1) && PyErr_Occurred())
         goto exit;
     return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
 
@@ -12575,7 +12575,7 @@
 
 static unsigned int
 os_makedev_impl(PyModuleDef *module, int major, int minor)
-/*[clinic end generated code: output=e04dc5723a98cd3b input=f55bf7cffb028a08]*/
+/*[clinic end generated code: output=5cb79d9c9eac58b0 input=f55bf7cffb028a08]*/
 {
     return makedev(major, minor);
 }
diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py
--- a/Tools/clinic/clinic.py
+++ b/Tools/clinic/clinic.py
@@ -2865,10 +2865,11 @@
     type = 'long'
     conversion_fn = 'PyLong_FromLong'
     cast = ''
+    unsigned_cast = ''
 
     def render(self, function, data):
         self.declare(data)
-        self.err_occurred_if("_return_value == -1", data)
+        self.err_occurred_if("_return_value == {}-1".format(self.unsigned_cast), data)
         data.return_conversion.append(
             ''.join(('return_value = ', self.conversion_fn, '(', self.cast, '_return_value);\n')))
 
@@ -2889,10 +2890,12 @@
 class unsigned_long_return_converter(long_return_converter):
     type = 'unsigned long'
     conversion_fn = 'PyLong_FromUnsignedLong'
+    unsigned_cast = '(unsigned long)'
 
 class unsigned_int_return_converter(unsigned_long_return_converter):
     type = 'unsigned int'
     cast = '(unsigned long)'
+    unsigned_cast = '(unsigned int)'
 
 class Py_ssize_t_return_converter(long_return_converter):
     type = 'Py_ssize_t'
@@ -2901,6 +2904,7 @@
 class size_t_return_converter(long_return_converter):
     type = 'size_t'
     conversion_fn = 'PyLong_FromSize_t'
+    unsigned_cast = '(size_t)'
 
 
 class double_return_converter(CReturnConverter):

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list