From 4a00db2fedf5f75864b94a1b3c65e853dd5a646d Mon Sep 17 00:00:00 2001 From: pinskia Date: Sun, 4 Sep 2005 17:05:39 +0000 Subject: 2005-09-04 Andrew Pinski Rasmus Hahn PR libobjc/23108 * objc.dg/type-stream-1.m: New test. 2005-09-04 Andrew Pinski Rasmus Hahn PR libobjc/23108 * archive.c (objc_write_type): Correct the element offset. (objc_read_type): Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@103832 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/testsuite/ChangeLog | 6 ++++++ gcc/testsuite/objc.dg/type-stream-1.m | 25 +++++++++++++++++++++++++ libobjc/ChangeLog | 7 +++++++ libobjc/archive.c | 4 ++-- 4 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/objc.dg/type-stream-1.m diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c849daaa6b8..d9a5e534216 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2005-09-04 Andrew Pinski + Rasmus Hahn + + PR libobjc/23108 + * objc.dg/type-stream-1.m: New test. + 2005-09-04 Tobias Schl"uter PR fortran/23661 diff --git a/gcc/testsuite/objc.dg/type-stream-1.m b/gcc/testsuite/objc.dg/type-stream-1.m new file mode 100644 index 00000000000..edc04e6467b --- /dev/null +++ b/gcc/testsuite/objc.dg/type-stream-1.m @@ -0,0 +1,25 @@ +/* { dg-options "-fgnu-runtime" } */ +/* { dg-do run } */ +#include +#include +#include + +int main (void) +{ + FILE *f; TypedStream *ts; + struct T { int a, b; } x = { 1, 2 }; + f = fopen ("foo", "w"); ts = objc_open_typed_stream (f, OBJC_WRITEONLY); + objc_write_type (ts, @encode(struct T), &x); + objc_close_typed_stream (ts); fclose (f); + f = fopen ("foo", "r"); ts = objc_open_typed_stream (f, OBJC_READONLY); + struct T y; + objc_read_type (ts, @encode(struct T), &y); + if (y.a != 1) + abort (); + if (y.b != 2) + abort (); + objc_close_typed_stream (ts); fclose (f); + remove ("foo"); + return 0; +} + diff --git a/libobjc/ChangeLog b/libobjc/ChangeLog index 0161254ac5a..81e11ccbd5a 100644 --- a/libobjc/ChangeLog +++ b/libobjc/ChangeLog @@ -1,3 +1,10 @@ +2005-09-04 Andrew Pinski + Rasmus Hahn + + PR libobjc/23108 + * archive.c (objc_write_type): Correct the element offset. + (objc_read_type): Likewise. + 2005-08-17 Kelley Cook * All files: Update FSF address. diff --git a/libobjc/archive.c b/libobjc/archive.c index eeaf29c62f3..992a69600d4 100644 --- a/libobjc/archive.c +++ b/libobjc/archive.c @@ -1069,7 +1069,7 @@ objc_write_type (TypedStream *stream, const char *type, const void *data) while (*type != _C_STRUCT_E) { align = objc_alignof_type (type); /* padd to alignment */ - acc_size += ROUND (acc_size, align); + acc_size = ROUND (acc_size, align); objc_write_type (stream, type, ((char *) data) + acc_size); acc_size += objc_sizeof_type (type); /* add component size */ type = objc_skip_typespec (type); /* skip component */ @@ -1165,7 +1165,7 @@ objc_read_type(TypedStream *stream, const char *type, void *data) while (*type != _C_STRUCT_E) { align = objc_alignof_type (type); /* padd to alignment */ - acc_size += ROUND (acc_size, align); + acc_size = ROUND (acc_size, align); objc_read_type (stream, type, ((char*)data)+acc_size); acc_size += objc_sizeof_type (type); /* add component size */ type = objc_skip_typespec (type); /* skip component */ -- cgit v1.2.1