classification
Title: do_mkvalue and 'boolean'
Type: Stage: needs patch
Components: Versions: Python 3.5
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Digitalxero, IROV, Owais Kazi, amaury.forgeotdarc, temoto
Priority: normal Keywords: easy, patch

Created on 2011-01-10 16:55 by IROV, last changed 2019-06-08 14:46 by Owais Kazi.

Files
File name Uploaded Description Edit
issue10880_68064.patch Digitalxero, 2011-02-27 18:23 corrected patch
Messages (13)
msg125903 - (view) Author: Yuriy (IROV) Date: 2011-01-10 16:55
If a value created by Py_VaBuildValue and parameter "b" is transfered - a PyLong_Type value is returned despite of the fact that it would be reasonable if PyBool_Type were returned. Are there any reasons for this?

modsupport.c Ln 214
msg125904 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2011-01-10 17:05
What makes you think it should be a boolean?
in http://docs.python.org/py3k/c-api/arg.html#Py_BuildValue "b" means "byte" and is processed as a tiny integer.

Now, that's true that Py_BuildValue could have a format for boolean values.  Maybe with a "?" parameter?
msg125911 - (view) Author: Yuriy (IROV) Date: 2011-01-10 18:55
Thank you, how is it possible to ask the developers to add such a flag?
msg125914 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2011-01-10 19:07
This is the right place to ask... but it will be faster if someone provides a patch.
msg125925 - (view) Author: Yuriy (IROV) Date: 2011-01-10 20:28
case 'g':
		{
			int n;
			n = va_arg(*p_va, int);

			if (n == 0)
				Py_RETURN_FALSE;
			else
				Py_RETURN_TRUE;
		}
msg126034 - (view) Author: Sergey Shepelev (temoto) Date: 2011-01-11 20:51
Here's patch against 2.6


--- a/Python/modsupport.c	Tue Aug 24 18:19:58 2010 +0200
+++ b/Python/modsupport.c	Tue Jan 11 23:50:40 2011 +0300
@@ -459,6 +459,16 @@
             return v;
         }
 
+        case '?':
+        {
+            int n;
+            n = va_arg(*p_va, int);
+            if (n == 0)
+                Py_RETURN_FALSE;
+            else
+                Py_RETURN_TRUE;
+        }
+
         case ':':
         case ',':
         case ' ':
msg129613 - (view) Author: Dj Gilcrease (Digitalxero) Date: 2011-02-27 05:30
Add a boolean format option to Py_BuildValue and Py_VaBuildValue

Also added some tests to test_capi that verifies Py_BuildValue is building the right type. I did not add tests for every possible type as it has lived this long without, but I did want to test my new code.
msg129618 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2011-02-27 09:53
This test is wrong::
   if (!PyBool_Check(test_var) && test_var == Py_False)
the second part is never executed.
   if (test_var != Py_False)
is enough to test the return value.
msg129619 - (view) Author: Yuriy (IROV) Date: 2011-02-27 10:05
+    test_var = Py_BuildValue("?", 0);
+    if (PyBool_Check(test_var) && test_var == Py_True) {
+        PyErr_SetString(TestError, "Failed to Create boolean");
+        return NULL;
+    }
+    
+    test_var = Py_BuildValue("?", 1);
+    if (PyBool_Check(test_var) && test_var == Py_False) {
+        PyErr_SetString(TestError, "Failed to Create boolean");
+        return NULL;
+    }
msg129621 - (view) Author: Yuriy (IROV) Date: 2011-02-27 10:16
sorry ^_^

+    test_var = Py_BuildValue("?", 0);
+    if (!PyBool_Check(test_var) || test_var == Py_True) {
+        PyErr_SetString(TestError, "Failed to Create boolean");
+        return NULL;
+    }
+    
+    test_var = Py_BuildValue("?", 1);
+    if (!PyBool_Check(test_var) || test_var == Py_False) {
+        PyErr_SetString(TestError, "Failed to Create boolean");
+        return NULL;
+    }
msg129645 - (view) Author: Dj Gilcrease (Digitalxero) Date: 2011-02-27 18:23
Correct the tests. They passed before but had a logic flaw that caused them to never test that the correct boolean value was being returned.
msg221747 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-06-27 22:05
Can somebody do a patch review on this please, it's against _testcapimodule.c.
msg345040 - (view) Author: Owais Kazi (Owais Kazi) Date: 2019-06-08 14:46
If it's a easy patch, I would like to pick it up. Can someone please explain how should I proceed with this? I am already done with the setup.
TIA
History
Date User Action Args
2019-06-08 14:46:59Owais Kazisettype: enhancement ->

messages: + msg345040
nosy: + Owais Kazi
2019-03-15 23:58:52BreamoreBoysetnosy: - BreamoreBoy
2014-06-27 22:05:50BreamoreBoysetnosy: + BreamoreBoy

messages: + msg221747
versions: + Python 3.5, - Python 3.3
2011-02-27 18:23:53Digitalxerosetfiles: - issue10880_rev68064.patch
nosy: amaury.forgeotdarc, temoto, Digitalxero, IROV
2011-02-27 18:23:48Digitalxerosetfiles: + issue10880_68064.patch
nosy: amaury.forgeotdarc, temoto, Digitalxero, IROV
messages: + msg129645
2011-02-27 10:16:44IROVsetnosy: amaury.forgeotdarc, temoto, Digitalxero, IROV
messages: + msg129621
2011-02-27 10:05:36IROVsetnosy: amaury.forgeotdarc, temoto, Digitalxero, IROV
messages: + msg129619
2011-02-27 09:53:24amaury.forgeotdarcsetnosy: amaury.forgeotdarc, temoto, Digitalxero, IROV
messages: + msg129618
2011-02-27 05:30:27Digitalxerosetfiles: + issue10880_rev68064.patch

nosy: + Digitalxero
messages: + msg129613

keywords: + patch
2011-01-11 20:51:56temotosetnosy: + temoto
messages: + msg126034
2011-01-10 20:28:38IROVsetmessages: + msg125925
2011-01-10 19:07:41amaury.forgeotdarcsetkeywords: + easy
messages: + msg125914
stage: needs patch
2011-01-10 18:55:26IROVsetmessages: + msg125911
2011-01-10 17:05:03amaury.forgeotdarcsettype: behavior -> enhancement

messages: + msg125904
nosy: + amaury.forgeotdarc
2011-01-10 16:55:09IROVcreate