From 676c937a7b53de94bf375b3ce994b430b1efad3a Mon Sep 17 00:00:00 2001 From: "zik.saleeba" Date: Mon, 2 Mar 2009 22:13:47 +0000 Subject: [PATCH] Fixed bug in stdarg handling of non-stack values git-svn-id: http://picoc.googlecode.com/svn/trunk@142 21eae674-98b7-11dd-bd71-f92a316d2d60 --- clibrary.c | 2 +- picoc.h | 3 +++ platform_library.c | 2 +- type.c | 9 +++++++++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/clibrary.c b/clibrary.c index fd573a1..0ca6037 100644 --- a/clibrary.c +++ b/clibrary.c @@ -124,7 +124,7 @@ void LibPrintf(struct ParseState *Parser, struct Value *ReturnValue, struct Valu PrintStr("XXX", PlatformPutc); /* not enough parameters for format */ else { - NextArg = (struct Value *)((void *)NextArg + sizeof(struct Value) + TypeSizeValue(NextArg)); + NextArg = (struct Value *)((void *)NextArg + sizeof(struct Value) + TypeStackSizeValue(NextArg)); if (NextArg->Typ != FormatType) PrintStr("XXX", PlatformPutc); /* bad type for format */ else diff --git a/picoc.h b/picoc.h index 3738845..18a36cd 100644 --- a/picoc.h +++ b/picoc.h @@ -122,6 +122,7 @@ struct FuncDef struct ParseState Body; /* lexical tokens of the function body if not intrinsic */ }; +/* values */ struct ArrayValue { unsigned int Size; /* the number of elements in the array */ @@ -161,6 +162,7 @@ struct Value char ValOnHeap; /* the AnyValue is on the heap (but this Value is on the stack) */ char ValOnStack; /* the AnyValue is on the stack along with this Value */ char IsLValue; /* is modifiable and is allocated somewhere we can usefully modify it */ + char TempToken; /* temporary token used in expression evaluation */ }; /* hash table data structure */ @@ -260,6 +262,7 @@ void Parse(const char *FileName, const char *Source, int SourceLen, int RunIt); void TypeInit(); int TypeSize(struct ValueType *Typ, int ArraySize); int TypeSizeValue(struct Value *Val); +int TypeStackSizeValue(struct Value *Val); void TypeParse(struct ParseState *Parser, struct ValueType **Typ, char **Identifier); struct ValueType *TypeGetMatching(struct ParseState *Parser, struct ValueType *ParentType, enum BaseType Base, int ArraySize, const char *Identifier); diff --git a/platform_library.c b/platform_library.c index 78bf81a..f6cf5a7 100644 --- a/platform_library.c +++ b/platform_library.c @@ -19,7 +19,7 @@ void Random(struct ParseState *Parser, struct Value *ReturnValue, struct Value * static int SomeVar = 42; static int SomeArray[4]; -static int Blobcnt, Blobx1, Blobx2, Bloby1, Bloby2; +static int Blobcnt = 12, Blobx1 = 34, Blobx2 = 56, Bloby1 = 78, Bloby2 = 90; void PlatformLibraryInit() { struct ValueType *IntArrayType; diff --git a/type.c b/type.c index d7a81f8..51c0c88 100644 --- a/type.c +++ b/type.c @@ -56,6 +56,15 @@ struct ValueType *TypeGetMatching(struct ParseState *Parser, struct ValueType *P return TypeAdd(Parser, ParentType, Base, ArraySize, Identifier, Sizeof); } +/* stack space used by a value */ +int TypeStackSizeValue(struct Value *Val) +{ + if (Val->ValOnStack) + return TypeSizeValue(Val); // XXX - doesn't handle passing system-memory arrays by value correctly + else + return 0; +} + /* memory used by a value */ int TypeSizeValue(struct Value *Val) {