[Python-checkins] CVS: python/dist/src/Python bltinmodule.c,2.246.4.2,2.246.4.3
Guido van Rossum
gvanrossum@users.sourceforge.net
Mon, 08 Apr 2002 06:29:04 -0700
Update of /cvsroot/python/python/dist/src/Python
In directory usw-pr-cvs1:/tmp/cvs-serv32072
Modified Files:
Tag: release22-maint
bltinmodule.c
Log Message:
Add bool(), True, False (as ints) for backwards compatibility.
Index: bltinmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/bltinmodule.c,v
retrieving revision 2.246.4.2
retrieving revision 2.246.4.3
diff -C2 -d -r2.246.4.2 -r2.246.4.3
*** bltinmodule.c 11 Mar 2002 10:15:00 -0000 2.246.4.2
--- bltinmodule.c 8 Apr 2002 13:29:00 -0000 2.246.4.3
***************
*** 108,111 ****
--- 108,131 ----
static PyObject *
+ builtin_bool(PyObject *self, PyObject *x)
+ {
+ long b = PyObject_IsTrue(x);
+ if (b < 0)
+ return NULL;
+ if (b)
+ x = Py_True;
+ else
+ x = Py_False;
+ Py_INCREF(x);
+ return x;
+ }
+
+ static char bool_doc[] =
+ "bool(x) -> integer\n\
+ \n\
+ Normalize Boolean: return True (1) when x is true, False (0) otherwise.";
+
+
+ static PyObject *
builtin_buffer(PyObject *self, PyObject *args)
{
***************
*** 1774,1777 ****
--- 1794,1798 ----
{"abs", builtin_abs, METH_O, abs_doc},
{"apply", builtin_apply, METH_VARARGS, apply_doc},
+ {"bool", builtin_bool, METH_O, bool_doc},
{"buffer", builtin_buffer, METH_VARARGS, buffer_doc},
{"callable", builtin_callable, METH_O, callable_doc},
***************
*** 1845,1848 ****
--- 1866,1871 ----
SETBUILTIN("Ellipsis", Py_Ellipsis);
SETBUILTIN("NotImplemented", Py_NotImplemented);
+ SETBUILTIN("True", Py_True);
+ SETBUILTIN("False", Py_False);
SETBUILTIN("classmethod", &PyClassMethod_Type);
#ifndef WITHOUT_COMPLEX