From 860d398fb4d7b3961d362064571bcf6feb0f765a Mon Sep 17 00:00:00 2001 From: fedor Date: Fri, 13 Sep 2002 21:56:09 +0000 Subject: [PATCH] Fix sizing structures in cifframe git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@14437 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 7 +++++++ Source/NSZone.m | 1 - Source/cifframe.m | 9 ++++++--- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index c46e001d4..58e8d6cd2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2002-09-13 Adam Fedor + + * Source/cifframe.m (cifframe_guess_struct_size): Recurse if + element contains structures. + (cifframe_from_info): Alloc room for return value even if caller + doesn't use it. + Thu Sep 12 11:02:03 2002 Nicola Pero * Source/NSObject.m ([+_becomeMultiThreaded:]): Fixed typo - this diff --git a/Source/NSZone.m b/Source/NSZone.m index 2a7c2706e..7601ffb04 100644 --- a/Source/NSZone.m +++ b/Source/NSZone.m @@ -95,7 +95,6 @@ #include #include - /* * Try to get more memory - the normal process has failed. * If we can't do anything, bomb out. diff --git a/Source/cifframe.m b/Source/cifframe.m index cbe026255..581c824b2 100644 --- a/Source/cifframe.m +++ b/Source/cifframe.m @@ -100,7 +100,10 @@ cifframe_guess_struct_size(ffi_type *stype) i = 0; while (stype->elements[i]) { - size += stype->elements[i]->size; + if (stype->elements[i]->elements) + size += cifframe_guess_struct_size(stype->elements[i]); + else + size += stype->elements[i]->size; if (size % align != 0) { @@ -173,7 +176,7 @@ cifframe_from_info (NSArgumentInfo *info, int numargs, void **retval) * make room for it at the end of the cifframe so we * only need to do a single malloc. */ - if (retval) + if (rtype && rtype->size > 0) { unsigned full = size; unsigned pos; @@ -188,7 +191,7 @@ cifframe_from_info (NSArgumentInfo *info, int numargs, void **retval) else full += MAX(rtype->size, sizeof(smallret_t)); cframe = buf = NSZoneCalloc(NSDefaultMallocZone(), full, 1); - if (cframe) + if (cframe && retval) { *retval = buf + pos; }