Author: leo
Date: Sat Apr 30 01:42:25 2005
New Revision: 7947
Modified:
trunk/config/gen/makefiles/root.in
trunk/include/parrot/misc.h
trunk/src/spf_render.c
trunk/src/spf_vtable.c
trunk/t/pmc/object-meths.t
Log:
fix a couple of segfaults; preliminary tailcallmethod test
* spf_render.c:handl_flags caused segfaults related to string handling
* replaced the bogus cstr2pstr with CONST_STRING
* test tailcallmethod
Modified: trunk/config/gen/makefiles/root.in
==============================================================================
--- trunk/config/gen/makefiles/root.in (original)
+++ trunk/config/gen/makefiles/root.in Sat Apr 30 01:42:25 2005
@@ -507,6 +507,8 @@
$(SRC_DIR)/mmd.str \
$(SRC_DIR)/pmc.str \
$(SRC_DIR)/objects.str \
+ $(SRC_DIR)/spf_render.str \
+ $(SRC_DIR)/spf_vtable.str \
$(CLASS_STR_FILES)
$(INC_DIR)/string_private_cstring.h : $(STR_FILES) build_tools/c2str.pl
@@ -919,9 +921,9 @@
$(SRC_DIR)/utils$(O) : $(GENERAL_H_FILES)
-$(SRC_DIR)/spf_render$(O) : $(GENERAL_H_FILES)
+$(SRC_DIR)/spf_render$(O) : $(GENERAL_H_FILES) $(SRC_DIR)/spf_render.str
-$(SRC_DIR)/spf_vtable$(O) : $(GENERAL_H_FILES)
+$(SRC_DIR)/spf_vtable$(O) : $(GENERAL_H_FILES) $(SRC_DIR)/spf_vtable.str
$(SRC_DIR)/encoding$(O) : $(SRC_DIR)/encoding.c $(GENERAL_H_FILES)
Modified: trunk/include/parrot/misc.h
==============================================================================
--- trunk/include/parrot/misc.h (original)
+++ trunk/include/parrot/misc.h Sat Apr 30 01:42:25 2005
@@ -84,8 +84,8 @@
*/
# define PARROT_SPRINTF_MAX_PREC 3 * PARROT_SPRINTF_BUFFER_SIZE / 4
-# define cstr2pstr(cstr) string_make(interpreter, cstr, strlen(cstr),
"iso-8859-1", PObj_external_FLAG)
-# define char2pstr(ch) string_make(interpreter, &ch , 1,
"iso-8859-1", PObj_external_FLAG)
+# define cstr2pstr(cstr) string_make(interpreter, cstr, strlen(cstr),
"ascii", 0)
+# define char2pstr(ch) string_make(interpreter, &ch , 1, "ascii", 0)
/* SPRINTF DATA STRUCTURE AND FLAGS */
Modified: trunk/src/spf_render.c
==============================================================================
--- trunk/src/spf_render.c (original)
+++ trunk/src/spf_render.c Sat Apr 30 01:42:25 2005
@@ -22,6 +22,7 @@
#define IN_SPF_SYSTEM
#include "parrot/parrot.h"
+#include "spf_render.str"
/* Per Dan's orders, we will not use sprintf if snprintf isn't
* around for us.
@@ -112,39 +113,38 @@
static STRING *
handle_flags(Interp *interpreter,
- SpfInfo info, STRING *str, INTVAL is_int_type, const char *prefix)
+ SpfInfo info, STRING *str, INTVAL is_int_type, STRING* prefix)
{
UINTVAL len = string_length(interpreter, str);
+ STRING *cs;
if (is_int_type) {
/* +, space */
if (string_ord(interpreter, str, 0) != '-') {
if (info->flags & FLAG_PLUS) {
- str = string_concat(interpreter, cstr2pstr("+"), str, 0);
+ cs = CONST_STRING(interpreter, "+");
+ str = string_concat(interpreter, cs , str, 0);
len++;
}
else if (info->flags & FLAG_SPACE) {
- str = string_concat(interpreter, cstr2pstr(" "), str, 0);
+ cs = CONST_STRING(interpreter, " ");
+ str = string_concat(interpreter, cs , str, 0);
len++;
}
}
- /* XXX
- * cstr2pstr mostly uses literal chars, which should generate a
- * string with PObj_external_FLAG
- * TODO make 2 versions of this if needed
- */
-
- /* # */
- if ((info->flags & FLAG_SHARP) && prefix && prefix[0]) {
- str = string_concat(interpreter, cstr2pstr(prefix), str, 0);
- len += strlen(prefix);
+
+ /* # 0x ... */
+ if ((info->flags & FLAG_SHARP) && prefix) {
+ str = string_concat(interpreter, prefix, str, 0);
+ len += string_length(interpreter, prefix);
}
/* XXX sharp + fill ??? */
/* precision */
if (info->flags & FLAG_PREC) {
info->flags |= FLAG_WIDTH;
- if (string_ord(interpreter, str, 0) == '-' ||
string_ord(interpreter, str, 0) == '+') {
+ if (string_ord(interpreter, str, 0) == '-' ||
+ string_ord(interpreter, str, 0) == '+') {
info->width = info->prec + 1;
}
else {
@@ -164,13 +164,13 @@
STRING *fill;
if (info->flags & FLAG_ZERO) {
- fill = cstr2pstr("0");
+ fill = CONST_STRING(interpreter, "0");
}
else {
- fill = cstr2pstr(" ");
+ fill = CONST_STRING(interpreter, " ");
}
- string_repeat(interpreter, fill, info->width - len, &fill);
+ fill = string_repeat(interpreter, fill, info->width - len, NULL);
if (info->flags & FLAG_MINUS) { /* left-align */
string_append(interpreter, str, fill, 0);
@@ -178,7 +178,8 @@
else { /* right-align */
/* signed and zero padded */
if (info->flags & FLAG_ZERO
- && (string_ord(interpreter, str,0) == '-' ||
string_ord(interpreter, str,0) == '+')) {
+ && (string_ord(interpreter, str,0) == '-' ||
+ string_ord(interpreter, str,0) == '+')) {
STRING *temp = 0;
string_substr(interpreter, str, 1, len-1, &temp, 0);
string_chopn(interpreter, str, -1);
@@ -293,7 +294,7 @@
* tc is used as a temporary buffer by uint_to_string and
* as a target by gen_sprintf_call.
*/
- STRING *ts;
+ STRING *ts, *prefix;
STRING *substr = NULL;
char tc[PARROT_SPRINTF_BUFFER_SIZE];
@@ -573,7 +574,9 @@
theint = obj->getint(interpreter, info.type, obj);
ts = int_to_str(interpreter, tc, theint, 8);
- ts = handle_flags(interpreter, &info, ts, 1, "0");
+ prefix = CONST_STRING(interpreter, "0");
+ ts = handle_flags(interpreter, &info,
+ ts, 1, prefix);
string_append(interpreter, targ, ts, 0);
break;
@@ -582,7 +585,9 @@
theuint = obj->getuint(interpreter, info.type,
obj);
ts = uint_to_str(interpreter, tc, theuint, 16, 0);
- ts = handle_flags(interpreter, &info, ts, 1, "0x");
+ prefix = CONST_STRING(interpreter, "0x");
+ ts = handle_flags(interpreter, &info,
+ ts, 1, prefix);
string_append(interpreter, targ, ts, 0);
break;
@@ -592,7 +597,9 @@
obj->getuint(interpreter, info.type, obj);
ts = uint_to_str(interpreter, tc, theuint, 16, 0);
- ts = handle_flags(interpreter, &info, ts, 1, "0X");
+ prefix = CONST_STRING(interpreter, "0X");
+ ts = handle_flags(interpreter, &info,
+ ts, 1, prefix);
string_append(interpreter, targ, ts, 0);
break;
@@ -602,7 +609,9 @@
obj->getuint(interpreter, info.type, obj);
ts = uint_to_str(interpreter, tc, theuint, 2, 0);
- ts = handle_flags(interpreter, &info, ts, 1, "0b");
+ prefix = CONST_STRING(interpreter, "0b");
+ ts = handle_flags(interpreter, &info,
+ ts, 1, prefix);
string_append(interpreter, targ, ts, 0);
break;
@@ -611,7 +620,9 @@
theint = obj->getint(interpreter, info.type, obj);
ts = int_to_str(interpreter, tc, theint, 2);
- ts = handle_flags(interpreter, &info, ts, 1, "0B");
+ prefix = CONST_STRING(interpreter, "0B");
+ ts = handle_flags(interpreter, &info,
+ ts, 1, prefix);
string_append(interpreter, targ, ts, 0);
break;
@@ -631,7 +642,9 @@
ts = uint_to_str(interpreter, tc,
(HUGEINTVAL) (size_t) ptr, 16, 0);
- ts = handle_flags(interpreter, &info, ts, 1, "0x");
+ prefix = CONST_STRING(interpreter, "0x");
+ ts = handle_flags(interpreter, &info,
+ ts, 1, prefix);
string_append(interpreter, targ, ts, 0);
break;
Modified: trunk/src/spf_vtable.c
==============================================================================
--- trunk/src/spf_vtable.c (original)
+++ trunk/src/spf_vtable.c Sat Apr 30 01:42:25 2005
@@ -24,6 +24,7 @@
#include "parrot/parrot.h"
#include <stdarg.h>
+#include "spf_vtable.str"
/*
@@ -239,7 +240,7 @@
case SIZE_PSTR:
{
STRING *s = (STRING *)va_arg(*arg, STRING *);
- return s ? s : cstr2pstr("(null)");
+ return s ? s : CONST_STRING(interpreter, "(null)");
}
Modified: trunk/t/pmc/object-meths.t
==============================================================================
--- trunk/t/pmc/object-meths.t (original)
+++ trunk/t/pmc/object-meths.t Sat Apr 30 01:42:25 2005
@@ -16,7 +16,7 @@
=cut
-use Parrot::Test tests => 27;
+use Parrot::Test tests => 28;
use Test::More;
output_like(<<'CODE', <<'OUTPUT', "callmethod - unknown method");
@@ -888,3 +888,34 @@
abc
OUTPUT
+pir_output_is(<<'CODE', <<'OUTPUT', "tailcallmeth");
+.sub main @MAIN
+ .local pmc cl, o, n
+ cl = newclass "Foo"
+ addattribute cl, "n"
+ o = new "Foo"
+ n = new Integer
+ n = 2000
+ setattribute o, "Foo\0n", n
+ o.go()
+ n = getattribute o, "Foo\0n"
+ print n
+ print "\n"
+.end
+
+.namespace ["Foo"]
+.sub go method
+ .local pmc n
+ n = getattribute self, "Foo\0n"
+ dec n
+ unless n goto done
+ # XXX this is ugly
+ P2 = self
+ tailcallmethod "go"
+done:
+.end
+CODE
+0
+OUTPUT
+
+