* Changed many files to use mkvalue() instead of newtupleobject().

* Fixcprt.py: added [-y file] option, do only files younger than file.
* modsupport.[ch]: added vmkvalue().
* intobject.c: use mkvalue().
* stringobject.c: added "formatstring"; renamed string* to string_*;
  ceval.c: call formatstring for string % value.
* longobject.c: close memory leak in divmod.
* parsetok.c: set result node to NULL when returning an error.
This commit is contained in:
Guido van Rossum 1993-03-16 12:15:04 +00:00
parent f48b419a07
commit e537240c25
21 changed files with 503 additions and 273 deletions

View file

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View file

@ -1671,6 +1671,9 @@ rem(v, w)
DECREF(w);
return x;
}
if (is_stringobject(v)) {
return formatstring(v, w);
}
err_setstr(TypeError, "bad operand type(s) for %");
return NULL;
}

View file

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@ -56,6 +56,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "allobjects.h"
#include "modsupport.h"
#include <errno.h>
#ifndef errno
@ -153,13 +154,11 @@ err_errno(exc)
err_set(KeyboardInterrupt);
return NULL;
}
v = newtupleobject(2);
v = mkvalue("(is)", errno, strerror(errno));
if (v != NULL) {
settupleitem(v, 0, newintobject((long)errno));
settupleitem(v, 1, newstringobject(strerror(errno)));
err_setval(exc, v);
DECREF(v);
}
err_setval(exc, v);
XDECREF(v);
return NULL;
}

View file

@ -28,17 +28,6 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "modsupport.h"
#include "import.h"
#ifdef HAVE_PROTOTYPES
#define USE_STDARG
#endif
#ifdef USE_STDARG
#include <stdarg.h>
#else
#include <varargs.h>
#endif
object *
initmodule(name, methods)
char *name;
@ -454,7 +443,7 @@ do_mkvalue(p_format, p_va)
case '(':
return do_mktuple(p_format, p_va, ')',
countformat(*p_format, ')'));
case 'b':
case 'h':
case 'i':
@ -466,7 +455,7 @@ do_mkvalue(p_format, p_va)
case 'f':
case 'd':
return newfloatobject((double)va_arg(*p_va, double));
case 'c':
{
char p[1];
@ -532,32 +521,34 @@ object *mkvalue(char *format, ...)
object *mkvalue(va_alist) va_dcl
#endif
{
int n;
char *f;
va_list va;
object* retval;
#ifdef USE_STDARG
va_start(va, format);
#else
char *format;
va_start(va);
format = va_arg(va, char *);
#endif
f = format;
n = countformat(f, '\0');
if (n < 0)
retval = NULL; /* Error in the format */
else if (n == 0) {
retval = None;
INCREF(retval);
}
else if (n == 1)
retval = do_mkvalue(&f, &va);
else
retval = do_mktuple(&f, &va, '\0', n);
retval = vmkvalue(format, va);
va_end(va);
if (retval == NULL)
fprintf(stderr, "format \"%s\", f \"%s\"\n", format, f);
return retval;
}
object *
vmkvalue(format, va)
char *format;
va_list va;
{
char *f = format;
int n = countformat(f, '\0');
if (n < 0)
return NULL;
if (n == 0) {
INCREF(None);
return None;
}
if (n == 1)
return do_mkvalue(&f, &va);
return do_mktuple(&f, &va, '\0', n);
}