[Python-checkins] CVS: python/dist/src/Objects longobject.c,1.71.6.2,1.71.6.3 floatobject.c,2.81.6.3,2.81.6.4 stringobject.c,2.103.2.4,2.103.2.5 tupleobject.c,2.48.6.2,2.48.6.3
Guido van Rossum
gvanrossum@users.sourceforge.net
Wed, 13 Jun 2001 18:01:18 -0700
Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv11831/Objects
Modified Files:
Tag: descr-branch
longobject.c floatobject.c stringobject.c tupleobject.c
Log Message:
Four more built-in types bite the dust: the built-ins long, float,
string and tuple are now type objects. These can't be subtyped yet!
Index: longobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/longobject.c,v
retrieving revision 1.71.6.2
retrieving revision 1.71.6.3
diff -C2 -r1.71.6.2 -r1.71.6.3
*** longobject.c 2001/06/06 14:27:54 1.71.6.2
--- longobject.c 2001/06/14 01:01:16 1.71.6.3
***************
*** 1813,1816 ****
--- 1813,1853 ----
}
+ static PyObject *
+ long_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+ {
+ PyObject *x = NULL;
+ int base = -909; /* unlikely! */
+ static char *kwlist[] = {"x", "base", 0};
+
+ assert(type == &PyLong_Type);
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "|Oi:long", kwlist,
+ &x, &base))
+ return NULL;
+ if (x == NULL)
+ return PyLong_FromLong(0L);
+ if (base == -909)
+ return PyNumber_Long(x);
+ else if (PyString_Check(x))
+ return PyLong_FromString(PyString_AS_STRING(x), NULL, base);
+ else if (PyUnicode_Check(x))
+ return PyLong_FromUnicode(PyUnicode_AS_UNICODE(x),
+ PyUnicode_GET_SIZE(x),
+ base);
+ else {
+ PyErr_SetString(PyExc_TypeError,
+ "long() can't convert non-string with explicit base");
+ return NULL;
+ }
+ }
+
+ static char long_doc[] =
+ "long(x[, base]) -> integer\n\
+ \n\
+ Convert a string or number to a long integer, if possible. A floating\n\
+ point argument will be truncated towards zero (this does not include a\n\
+ string representation of a floating point number!) When converting a\n\
+ string, use the optional base. It is an error to supply a base when\n\
+ converting a non-string.";
+
static PyNumberMethods long_as_number = {
(binaryfunc) long_add, /*nb_add*/
***************
*** 1853,1857 ****
PyObject_HEAD_INIT(&PyType_Type)
0, /* ob_size */
! "long int", /* tp_name */
sizeof(PyLongObject) - sizeof(digit), /* tp_basicsize */
sizeof(digit), /* tp_itemsize */
--- 1890,1894 ----
PyObject_HEAD_INIT(&PyType_Type)
0, /* ob_size */
! "long", /* tp_name */
sizeof(PyLongObject) - sizeof(digit), /* tp_basicsize */
sizeof(digit), /* tp_itemsize */
***************
*** 1872,1874 ****
--- 1909,1929 ----
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_CHECKTYPES, /* tp_flags */
+ long_doc, /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ 0, /* tp_methods */
+ 0, /* tp_members */
+ 0, /* tp_getset */
+ 0, /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ 0, /* tp_init */
+ 0, /* tp_alloc */
+ long_new, /* tp_new */
};
Index: floatobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/floatobject.c,v
retrieving revision 2.81.6.3
retrieving revision 2.81.6.4
diff -C2 -r2.81.6.3 -r2.81.6.4
*** floatobject.c 2001/06/06 14:27:54 2.81.6.3
--- floatobject.c 2001/06/14 01:01:16 2.81.6.4
***************
*** 625,628 ****
--- 625,648 ----
+ static PyObject *
+ float_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+ {
+ PyObject *x;
+ static char *kwlist[] = {"x", 0};
+
+ assert(type == &PyFloat_Type);
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O:float", kwlist, &x))
+ return NULL;
+ if (PyString_Check(x))
+ return PyFloat_FromString(x, NULL);
+ return PyNumber_Float(x);
+ }
+
+ static char float_doc[] =
+ "float(x) -> floating point number\n\
+ \n\
+ Convert a string or number to a floating point number, if possible.";
+
+
static PyNumberMethods float_as_number = {
(binaryfunc)float_add, /*nb_add*/
***************
*** 683,687 ****
0, /* tp_setattro */
0, /* tp_as_buffer */
! Py_TPFLAGS_DEFAULT | Py_TPFLAGS_CHECKTYPES /* tp_flags */
};
--- 703,725 ----
0, /* tp_setattro */
0, /* tp_as_buffer */
! Py_TPFLAGS_DEFAULT | Py_TPFLAGS_CHECKTYPES, /* tp_flags */
! float_doc, /* tp_doc */
! 0, /* tp_traverse */
! 0, /* tp_clear */
! 0, /* tp_richcompare */
! 0, /* tp_weaklistoffset */
! 0, /* tp_iter */
! 0, /* tp_iternext */
! 0, /* tp_methods */
! 0, /* tp_members */
! 0, /* tp_getset */
! 0, /* tp_base */
! 0, /* tp_dict */
! 0, /* tp_descr_get */
! 0, /* tp_descr_set */
! 0, /* tp_dictoffset */
! 0, /* tp_init */
! 0, /* tp_alloc */
! float_new, /* tp_new */
};
Index: stringobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/stringobject.c,v
retrieving revision 2.103.2.4
retrieving revision 2.103.2.5
diff -C2 -r2.103.2.4 -r2.103.2.5
*** stringobject.c 2001/06/06 14:27:54 2.103.2.4
--- stringobject.c 2001/06/14 01:01:16 2.103.2.5
***************
*** 2358,2362 ****
--- 2358,2381 ----
};
+ static PyObject *
+ string_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+ {
+ PyObject *x = NULL;
+ static char *kwlist[] = {"object", 0};
+ assert(type == &PyString_Type);
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O:str", kwlist, &x))
+ return NULL;
+ if (x == NULL)
+ return PyString_FromString("");
+ return PyObject_Str(x);
+ }
+
+ static char string_doc[] =
+ "str(object) -> string\n\
+ \n\
+ Return a nice string representation of the object.\n\
+ If the argument is a string, the return value is the same object.";
+
PyTypeObject PyString_Type = {
PyObject_HEAD_INIT(&PyType_Type)
***************
*** 2381,2385 ****
&string_as_buffer, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
! 0, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
--- 2400,2404 ----
&string_as_buffer, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
! string_doc, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
***************
*** 2393,2396 ****
--- 2412,2421 ----
0, /* tp_base */
0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ 0, /* tp_init */
+ 0, /* tp_alloc */
+ string_new, /* tp_new */
};
Index: tupleobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/tupleobject.c,v
retrieving revision 2.48.6.2
retrieving revision 2.48.6.3
diff -C2 -r2.48.6.2 -r2.48.6.3
*** tupleobject.c 2001/06/06 14:27:54 2.48.6.2
--- tupleobject.c 2001/06/14 01:01:16 2.48.6.3
***************
*** 444,447 ****
--- 444,469 ----
}
+ static PyObject *
+ tuple_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+ {
+ PyObject *arg = NULL;
+ static char *kwlist[] = {"sequence", 0};
+
+ assert(type == &PyTuple_Type);
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O:tuple", kwlist, &arg))
+ return NULL;
+
+ if (arg == NULL)
+ return PyTuple_New(0);
+ else
+ return PySequence_Tuple(arg);
+ }
+
+ static char tuple_doc[] =
+ "tuple(sequence) -> list\n\
+ \n\
+ Return a tuple whose items are the same as those of the argument sequence.\n\
+ If the argument is a tuple, the return value is the same object.";
+
static PySequenceMethods tuple_as_sequence = {
(inquiry)tuplelength, /* sq_length */
***************
*** 477,484 ****
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_GC, /* tp_flags */
! 0, /* tp_doc */
(traverseproc)tupletraverse, /* tp_traverse */
0, /* tp_clear */
tuplerichcompare, /* tp_richcompare */
};
--- 499,520 ----
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_GC, /* tp_flags */
! tuple_doc, /* tp_doc */
(traverseproc)tupletraverse, /* tp_traverse */
0, /* tp_clear */
tuplerichcompare, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ 0, /* tp_methods */
+ 0, /* tp_members */
+ 0, /* tp_getset */
+ 0, /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ 0, /* tp_init */
+ 0, /* tp_alloc */
+ tuple_new, /* tp_new */
};