Kill all uses and definitions of tp_print under Objects/. (Others will follow.)

Finally kill intobject.c, which was #ifdef'ed out a long time ago.
This commit is contained in:
Guido van Rossum 2007-08-07 19:51:00 +00:00
parent d474ce8c7a
commit 04dbf3b5ec
11 changed files with 11 additions and 1470 deletions

View File

@ -3,15 +3,6 @@
#include "Python.h"
#include "longintrepr.h"
/* We need to define bool_print to override int_print */
static int
bool_print(PyObject *self, FILE *fp, int flags)
{
fputs(self == Py_False ? "False" : "True", fp);
return 0;
}
/* We define bool_repr to return "False" or "True" */
static PyObject *false_str = NULL;
@ -148,7 +139,7 @@ PyTypeObject PyBool_Type = {
sizeof(struct _longobject),
0,
0, /* tp_dealloc */
bool_print, /* tp_print */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_compare */

View File

@ -327,16 +327,6 @@ complex_to_buf(char *buf, int bufsz, PyComplexObject *v, int precision)
}
}
static int
complex_print(PyComplexObject *v, FILE *fp, int flags)
{
char buf[100];
complex_to_buf(buf, sizeof(buf), v,
(flags & Py_PRINT_RAW) ? PREC_STR : PREC_REPR);
fputs(buf, fp);
return 0;
}
static PyObject *
complex_repr(PyComplexObject *v)
{
@ -1005,7 +995,7 @@ PyTypeObject PyComplex_Type = {
sizeof(PyComplexObject),
0,
complex_dealloc, /* tp_dealloc */
(printfunc)complex_print, /* tp_print */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_compare */

View File

@ -886,51 +886,6 @@ dict_dealloc(register dictobject *mp)
Py_TRASHCAN_SAFE_END(mp)
}
static int
dict_print(register dictobject *mp, register FILE *fp, register int flags)
{
register Py_ssize_t i;
register Py_ssize_t any;
int status;
status = Py_ReprEnter((PyObject*)mp);
if (status != 0) {
if (status < 0)
return status;
fprintf(fp, "{...}");
return 0;
}
fprintf(fp, "{");
any = 0;
for (i = 0; i <= mp->ma_mask; i++) {
dictentry *ep = mp->ma_table + i;
PyObject *pvalue = ep->me_value;
if (pvalue != NULL) {
/* Prevent PyObject_Repr from deleting value during
key format */
Py_INCREF(pvalue);
if (any++ > 0)
fprintf(fp, ", ");
if (PyObject_Print((PyObject *)ep->me_key, fp, 0)!=0) {
Py_DECREF(pvalue);
Py_ReprLeave((PyObject*)mp);
return -1;
}
fprintf(fp, ": ");
if (PyObject_Print(pvalue, fp, 0) != 0) {
Py_DECREF(pvalue);
Py_ReprLeave((PyObject*)mp);
return -1;
}
Py_DECREF(pvalue);
}
}
fprintf(fp, "}");
Py_ReprLeave((PyObject*)mp);
return 0;
}
static PyObject *
dict_repr(dictobject *mp)
{
@ -1974,7 +1929,7 @@ PyTypeObject PyDict_Type = {
sizeof(dictobject),
0,
(destructor)dict_dealloc, /* tp_dealloc */
(printfunc)dict_print, /* tp_print */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_compare */

View File

@ -205,7 +205,7 @@ format_double(char *buf, size_t buflen, double ob_fval, int precision)
{
register char *cp;
char format[32];
/* Subroutine for float_repr, float_str, float_print and others.
/* Subroutine for float_repr, float_str, and others.
We want float numbers to be recognizable as such,
i.e., they should contain a decimal point or an exponent.
However, %g may print the number as an integer;
@ -286,17 +286,6 @@ convert_to_double(PyObject **v, double *dbl)
#define PREC_REPR 17
#define PREC_STR 12
/* ARGSUSED */
static int
float_print(PyFloatObject *v, FILE *fp, int flags)
{
char buf[100];
format_float(buf, sizeof(buf), v,
(flags & Py_PRINT_RAW) ? PREC_STR : PREC_REPR);
fputs(buf, fp);
return 0;
}
static PyObject *
float_repr(PyFloatObject *v)
{
@ -1058,7 +1047,7 @@ PyTypeObject PyFloat_Type = {
sizeof(PyFloatObject),
0,
(destructor)float_dealloc, /* tp_dealloc */
(printfunc)float_print, /* tp_print */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_compare */

File diff suppressed because it is too large Load Diff

View File

@ -272,33 +272,6 @@ list_dealloc(PyListObject *op)
Py_TRASHCAN_SAFE_END(op)
}
static int
list_print(PyListObject *op, FILE *fp, int flags)
{
int rc;
Py_ssize_t i;
rc = Py_ReprEnter((PyObject*)op);
if (rc != 0) {
if (rc < 0)
return rc;
fprintf(fp, "[...]");
return 0;
}
fprintf(fp, "[");
for (i = 0; i < Py_Size(op); i++) {
if (i > 0)
fprintf(fp, ", ");
if (PyObject_Print(op->ob_item[i], fp, 0) != 0) {
Py_ReprLeave((PyObject *)op);
return -1;
}
}
fprintf(fp, "]");
Py_ReprLeave((PyObject *)op);
return 0;
}
static PyObject *
list_repr(PyListObject *v)
{
@ -2665,7 +2638,7 @@ PyTypeObject PyList_Type = {
sizeof(PyListObject),
0,
(destructor)list_dealloc, /* tp_dealloc */
(printfunc)list_print, /* tp_print */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_compare */

View File

@ -279,7 +279,7 @@ internal_print(PyObject *op, FILE *fp, int flags, int nesting)
universally available */
fprintf(fp, "<refcnt %ld at %p>",
(long)op->ob_refcnt, op);
else if (Py_Type(op)->tp_print == NULL) {
else {
PyObject *s;
if (flags & Py_PRINT_RAW)
s = PyObject_Str(op);
@ -293,8 +293,6 @@ internal_print(PyObject *op, FILE *fp, int flags, int nesting)
}
Py_XDECREF(s);
}
else
ret = (*Py_Type(op)->tp_print)(op, fp, flags);
}
if (ret == 0) {
if (ferror(fp)) {

View File

@ -565,50 +565,6 @@ set_dealloc(PySetObject *so)
Py_TRASHCAN_SAFE_END(so)
}
static int
set_tp_print(PySetObject *so, FILE *fp, int flags)
{
setentry *entry;
Py_ssize_t pos=0;
char *emit = ""; /* No separator emitted on first pass */
char *separator = ", ";
int literalform = 0;
int status = Py_ReprEnter((PyObject*)so);
if (status != 0) {
if (status < 0)
return status;
fprintf(fp, "%s(...)", Py_Type(so)->tp_name);
return 0;
}
if (!so->used) {
Py_ReprLeave((PyObject*)so);
fprintf(fp, "%s()", Py_Type(so)->tp_name);
return 0;
}
if (Py_Type(so) == &PySet_Type) {
literalform = 1;
fprintf(fp, "{");
} else
fprintf(fp, "%s([", Py_Type(so)->tp_name);
while (set_next(so, &pos, &entry)) {
fputs(emit, fp);
emit = separator;
if (PyObject_Print(entry->key, fp, 0) != 0) {
Py_ReprLeave((PyObject*)so);
return -1;
}
}
if (literalform)
fputs("}", fp);
else
fputs("])", fp);
Py_ReprLeave((PyObject*)so);
return 0;
}
static PyObject *
set_repr(PySetObject *so)
{
@ -1957,7 +1913,7 @@ PyTypeObject PySet_Type = {
0, /* tp_itemsize */
/* methods */
(destructor)set_dealloc, /* tp_dealloc */
(printfunc)set_tp_print, /* tp_print */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
set_nocmp, /* tp_compare */
@ -2050,7 +2006,7 @@ PyTypeObject PyFrozenSet_Type = {
0, /* tp_itemsize */
/* methods */
(destructor)set_dealloc, /* tp_dealloc */
(printfunc)set_tp_print, /* tp_print */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
set_nocmp, /* tp_compare */

View File

@ -764,71 +764,6 @@ PyString_AsStringAndSize(register PyObject *obj,
#include "stringlib/partition.h"
static int
string_print(PyStringObject *op, FILE *fp, int flags)
{
Py_ssize_t i;
char c;
int quote;
/* XXX Ought to check for interrupts when writing long strings */
if (! PyString_CheckExact(op)) {
int ret;
/* A str subclass may have its own __str__ method. */
op = (PyStringObject *) PyObject_Str((PyObject *)op);
if (op == NULL)
return -1;
ret = string_print(op, fp, flags);
Py_DECREF(op);
return ret;
}
if (flags & Py_PRINT_RAW) {
char *data = op->ob_sval;
Py_ssize_t size = Py_Size(op);
while (size > INT_MAX) {
/* Very long strings cannot be written atomically.
* But don't write exactly INT_MAX bytes at a time
* to avoid memory aligment issues.
*/
const int chunk_size = INT_MAX & ~0x3FFF;
fwrite(data, 1, chunk_size, fp);
data += chunk_size;
size -= chunk_size;
}
#ifdef __VMS
if (size) fwrite(data, (int)size, 1, fp);
#else
fwrite(data, 1, (int)size, fp);
#endif
return 0;
}
/* figure out which quote to use; single is preferred */
quote = '\'';
if (memchr(op->ob_sval, '\'', Py_Size(op)) &&
!memchr(op->ob_sval, '"', Py_Size(op)))
quote = '"';
fputc(quote, fp);
for (i = 0; i < Py_Size(op); i++) {
c = op->ob_sval[i];
if (c == quote || c == '\\')
fprintf(fp, "\\%c", c);
else if (c == '\t')
fprintf(fp, "\\t");
else if (c == '\n')
fprintf(fp, "\\n");
else if (c == '\r')
fprintf(fp, "\\r");
else if (c < ' ' || c >= 0x7f)
fprintf(fp, "\\x%02x", c & 0xff);
else
fputc(c, fp);
}
fputc(quote, fp);
return 0;
}
PyObject *
PyString_Repr(PyObject *obj, int smartquotes)
{
@ -3983,7 +3918,7 @@ PyTypeObject PyString_Type = {
sizeof(PyStringObject),
sizeof(char),
string_dealloc, /* tp_dealloc */
(printfunc)string_print, /* tp_print */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_compare */

View File

@ -184,23 +184,6 @@ tupledealloc(register PyTupleObject *op)
Py_TRASHCAN_SAFE_END(op)
}
static int
tupleprint(PyTupleObject *op, FILE *fp, int flags)
{
Py_ssize_t i;
fprintf(fp, "(");
for (i = 0; i < Py_Size(op); i++) {
if (i > 0)
fprintf(fp, ", ");
if (PyObject_Print(op->ob_item[i], fp, 0) != 0)
return -1;
}
if (Py_Size(op) == 1)
fprintf(fp, ",");
fprintf(fp, ")");
return 0;
}
static PyObject *
tuplerepr(PyTupleObject *v)
{
@ -653,7 +636,7 @@ PyTypeObject PyTuple_Type = {
sizeof(PyTupleObject) - sizeof(PyObject *),
sizeof(PyObject *),
(destructor)tupledealloc, /* tp_dealloc */
(printfunc)tupleprint, /* tp_print */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_compare */

View File

@ -3260,7 +3260,6 @@ inherit_slots(PyTypeObject *type, PyTypeObject *base)
basebase = base->tp_base;
COPYSLOT(tp_dealloc);
COPYSLOT(tp_print);
if (type->tp_getattr == NULL && type->tp_getattro == NULL) {
type->tp_getattr = base->tp_getattr;
type->tp_getattro = base->tp_getattro;
@ -5212,10 +5211,8 @@ static slotdef slotdefs[] = {
TPSLOT("__str__", tp_str, slot_tp_str, wrap_unaryfunc,
"x.__str__() <==> str(x)"),
TPSLOT("__str__", tp_print, NULL, NULL, ""),
TPSLOT("__repr__", tp_repr, slot_tp_repr, wrap_unaryfunc,
"x.__repr__() <==> repr(x)"),
TPSLOT("__repr__", tp_print, NULL, NULL, ""),
TPSLOT("__cmp__", tp_compare, _PyObject_SlotCompare, wrap_cmpfunc,
"x.__cmp__(y) <==> cmp(x,y)"),
TPSLOT("__hash__", tp_hash, slot_tp_hash, wrap_hashfunc,