summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
Diffstat (limited to 'Objects')
-rw-r--r--Objects/fileobject.c15
-rw-r--r--Objects/object.c36
2 files changed, 41 insertions, 10 deletions
diff --git a/Objects/fileobject.c b/Objects/fileobject.c
index 7ed4fcd..518fe04 100644
--- a/Objects/fileobject.c
+++ b/Objects/fileobject.c
@@ -680,16 +680,13 @@ writeobject(v, f, flags)
writer = getattr(f, "write");
if (writer == NULL)
return -1;
- if ((flags & PRINT_RAW) && is_stringobject(v)) {
- value = v;
- INCREF(value);
- }
- else {
+ if (flags & PRINT_RAW)
+ value = strobject(v);
+ else
value = reprobject(v);
- if (value == NULL) {
- DECREF(writer);
- return -1;
- }
+ if (value == NULL) {
+ DECREF(writer);
+ return -1;
}
result = call_object(writer, value);
DECREF(writer);
diff --git a/Objects/object.c b/Objects/object.c
index 73fba50..7a7383e 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -124,7 +124,11 @@ printobject(op, fp, flags)
op->ob_type->tp_name, (long)op);
}
else {
- object *s = reprobject(op);
+ object *s;
+ if (flags & PRINT_RAW)
+ s = strobject(op);
+ else
+ s = reprobject(op);
if (s == NULL)
ret = -1;
else if (!is_stringobject(s)) {
@@ -171,6 +175,36 @@ reprobject(v)
return (*v->ob_type->tp_repr)(v);
}
+object *
+strobject(v)
+ object *v;
+{
+ if (v == NULL)
+ return newstringobject("<NULL>");
+ if (is_stringobject(v)) {
+ INCREF(v);
+ return v;
+ }
+ else {
+ object *func = getattr(v, "__str__");
+ object *args;
+ object *res;
+ if (func == NULL) {
+ err_clear();
+ return reprobject(v);
+ }
+ args = newtupleobject(0);
+ if (args == NULL)
+ res = NULL;
+ else {
+ res = call_object(func, args);
+ DECREF(args);
+ }
+ DECREF(func);
+ return res;
+ }
+}
+
int
cmpobject(v, w)
object *v, *w;