diff --git a/ChangeLog b/ChangeLog index 23613ef3f..c7389e772 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2008-02-22 Richard Frith-Macdonald + + * Source/mframe/mframe.head: Change function arguments + * Source/mframe.m: Support nul termination of type strings + * Source/NSMethodSignature.m: nul terminate type strings + * Source/NSObjCRuntime.m: update for changed function args + 2008-02-21 Richard Frith-Macdonald * Headers/Foundation/NSKeyValueCoding.h: diff --git a/Source/NSMethodSignature.m b/Source/NSMethodSignature.m index 53ad62265..ac22bd0bc 100644 --- a/Source/NSMethodSignature.m +++ b/Source/NSMethodSignature.m @@ -170,13 +170,24 @@ if (_info == 0) { const char *types = _methodTypes; + char *outTypes; unsigned int i; - _info = NSZoneMalloc(NSDefaultMallocZone(), - sizeof(NSArgumentInfo)*(_numArgs+1)); + /* Allocate space enough for an NSArgumentInfo structure for each + * argument (including the return type), and enough space to hold + * the type information for each argument as a nul terminated + * string. + */ + outTypes = NSZoneMalloc(NSDefaultMallocZone(), + sizeof(NSArgumentInfo)*(_numArgs+1) + strlen(types)*2); + _info = (NSArgumentInfo*)outTypes; + outTypes = outTypes + sizeof(NSArgumentInfo)*(_numArgs+1); + /* Fill in the full argment information for each arg. + */ for (i = 0; i <= _numArgs; i++) { - types = mframe_next_arg(types, &_info[i]); + types = mframe_next_arg(types, &_info[i], outTypes); + outTypes += strlen(outTypes) + 1; } } return _info; diff --git a/Source/NSObjCRuntime.m b/Source/NSObjCRuntime.m index 31093fe23..496e6ead9 100644 --- a/Source/NSObjCRuntime.m +++ b/Source/NSObjCRuntime.m @@ -109,7 +109,7 @@ const char * NSGetSizeAndAlignment(const char *typePtr, unsigned *sizep, unsigned *alignp) { NSArgumentInfo info; - typePtr = mframe_next_arg(typePtr, &info); + typePtr = mframe_next_arg(typePtr, &info, 0); if (sizep) *sizep = info.size; if (alignp) diff --git a/Source/mframe.m b/Source/mframe.m index 0ce1e12e5..26eea12b9 100644 --- a/Source/mframe.m +++ b/Source/mframe.m @@ -202,11 +202,14 @@ mframe_build_signature(const char *typePtr, int *size, int *narg, char *buf) } -/* - * Step through method encoding information extracting details. +/* Step through method encoding information extracting details. + * If outTypes is non-nul then we copy the argument type into + * the buffer as a nul terminated string and use the values in + * this buffer as the types in info, rather than pointers to + * positions in typePtr */ const char * -mframe_next_arg(const char *typePtr, NSArgumentInfo *info) +mframe_next_arg(const char *typePtr, NSArgumentInfo *info, char *outTypes) { NSArgumentInfo local; BOOL flag; @@ -354,7 +357,7 @@ mframe_next_arg(const char *typePtr, NSArgumentInfo *info) { typePtr++; } - typePtr = mframe_next_arg(typePtr, &local); + typePtr = mframe_next_arg(typePtr, &local, 0); info->size = length * ROUND(local.size, local.align); info->align = local.align; typePtr++; /* Skip end-of-array */ @@ -380,7 +383,7 @@ mframe_next_arg(const char *typePtr, NSArgumentInfo *info) */ if (*typePtr != _C_STRUCT_E) { - typePtr = mframe_next_arg(typePtr, &local); + typePtr = mframe_next_arg(typePtr, &local, 0); if (typePtr == 0) { return 0; /* error */ @@ -395,7 +398,7 @@ mframe_next_arg(const char *typePtr, NSArgumentInfo *info) */ while (*typePtr != _C_STRUCT_E) { - typePtr = mframe_next_arg(typePtr, &local); + typePtr = mframe_next_arg(typePtr, &local, 0); if (typePtr == 0) { return 0; /* error */ @@ -434,7 +437,7 @@ mframe_next_arg(const char *typePtr, NSArgumentInfo *info) } while (*typePtr != _C_UNION_E) { - typePtr = mframe_next_arg(typePtr, &local); + typePtr = mframe_next_arg(typePtr, &local, 0); if (typePtr == 0) { return 0; /* error */ @@ -462,6 +465,17 @@ mframe_next_arg(const char *typePtr, NSArgumentInfo *info) return 0; } + /* Copy tye type information into the buffer if provided. + */ + if (outTypes != 0) + { + unsigned len = typePtr - info->type; + + strncpy(outTypes, info->type, len); + outTypes[len] = '\0'; + info->type = outTypes; + } + /* * May tell the caller if the item is stored in a register. */ @@ -499,7 +513,6 @@ mframe_next_arg(const char *typePtr, NSArgumentInfo *info) return typePtr; } - /* Return the number of arguments that the method MTH expects. Note that all methods need two implicit arguments `self' and `_cmd'. */ diff --git a/Source/mframe/mframe.head b/Source/mframe/mframe.head index f96a39165..6774c7382 100644 --- a/Source/mframe/mframe.head +++ b/Source/mframe/mframe.head @@ -18,7 +18,8 @@ You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free - Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA. + Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02111 USA. */ #ifndef __mframe_h_GNUSTEP_BASE_INCLUDE @@ -96,7 +97,7 @@ mframe_handle_return(const char* type, void* retval, arglist_t argFrame); * Step through method encoding information extracting details. */ const char * -mframe_next_arg(const char *typePtr, NSArgumentInfo *info); +mframe_next_arg(const char *typePtr, NSArgumentInfo *info, char *outTypes); /* * Generate method encoding with stack/register offsets from a simple