Overview
Comment: | OFMethodSignature: Add frame length and offsets |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
3c740455b59e6131fc9a3286f38fa857 |
User & Date: | js on 2017-09-10 00:45:44 |
Other Links: | manifest | tags |
Context
2017-09-10
| ||
20:39 | Add of_{sizeof,alignof}_type_encoding() check-in: b03cff2f49 user: js tags: trunk | |
00:45 | OFMethodSignature: Add frame length and offsets check-in: 3c740455b5 user: js tags: trunk | |
2017-09-09
| ||
22:21 | src/encodings: Rename a few files check-in: da8cd1c0ad user: js tags: trunk | |
Changes
Modified src/OFMethodSignature.h from [c5568c9fc1] to [009831faed].
︙ | ︙ | |||
24 25 26 27 28 29 30 | * @class OFMethodSignature OFMethodSignature.h ObjFW/OFMethodSignature.h * * @brief A class for parsing type encodings and accessing them. */ @interface OFMethodSignature: OFObject { char *_types; | | > > > > > > > | 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | * @class OFMethodSignature OFMethodSignature.h ObjFW/OFMethodSignature.h * * @brief A class for parsing type encodings and accessing them. */ @interface OFMethodSignature: OFObject { char *_types; OFMutableData *_typesPointers, *_offsets; } /*! * The number of arguments of the method. */ @property (readonly, nonatomic) size_t numberOfArguments; /*! * The return type of the method. */ @property (readonly, nonatomic) const char *methodReturnType; /*! * The size of the arguments on the stack frame. * * @note This is platform-dependent! */ @property (readonly, nonatomic) size_t frameLength; /*! * @brief Creates a new, autoreleased OFMethodSignature with the specified * ObjC types. * * @param types The ObjC types of the method * @return A new, autoreleased OFMethodSignature */ |
︙ | ︙ | |||
58 59 60 61 62 63 64 | * @return An Initialized OFMethodSignature */ - initWithObjCTypes: (const char *)types; /*! * @brief Returns the ObjC type for the argument at the specified index. * | | > > > > > > > > > > > > | 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | * @return An Initialized OFMethodSignature */ - initWithObjCTypes: (const char *)types; /*! * @brief Returns the ObjC type for the argument at the specified index. * * @param index The index of the argument for which to return the ObjC type * @return The ObjC type for the argument at the specified index */ - (const char *)argumentTypeAtIndex: (size_t)index; /*! * @brief Returns the offset on the stack frame of the argument at the * specified index. * * @note This is platform-dependent! * * @param index The index of the argument for which to return the offset * @returns The offset on the stack frame of the argument at the * specified index */ - (size_t)argumentOffsetAtIndex: (size_t)index; @end OF_ASSUME_NONNULL_END |
Modified src/OFMethodSignature.m from [6d6b60fdc0] to [81cb0b1392].
︙ | ︙ | |||
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | @throw [OFInvalidFormatException exception]; _types = [self allocMemoryWithSize: length + 1]; memcpy(_types, types, length); _typesPointers = [[OFMutableData alloc] initWithItemSize: sizeof(char *)]; last = _types; for (size_t i = 0; i < length; i++) { if (isdigit(_types[i])) { if (last == _types + i) @throw [OFInvalidFormatException exception]; _types[i] = '\0'; [_typesPointers addItem: &last]; i++; | > > > > | > > > | 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | @throw [OFInvalidFormatException exception]; _types = [self allocMemoryWithSize: length + 1]; memcpy(_types, types, length); _typesPointers = [[OFMutableData alloc] initWithItemSize: sizeof(char *)]; _offsets = [[OFMutableData alloc] initWithItemSize: sizeof(size_t)]; last = _types; for (size_t i = 0; i < length; i++) { if (isdigit(_types[i])) { size_t offset = _types[i] - '0'; if (last == _types + i) @throw [OFInvalidFormatException exception]; _types[i] = '\0'; [_typesPointers addItem: &last]; i++; for (; i < length && isdigit(_types[i]); i++) offset = offset * 10 + _types[i] - '0'; [_offsets addItem: &offset]; last = _types + i; i--; } else if (_types[i] == '{') { size_t depth = 0; for (; i < length; i++) { |
︙ | ︙ | |||
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | return self; } - (void)dealloc { [_typesPointers release]; [super dealloc]; } - (size_t)numberOfArguments { return [_typesPointers count] - 1; } - (const char *)methodReturnType { return *(const char **)[_typesPointers firstItem]; } - (const char *)argumentTypeAtIndex: (size_t)index { return *(const char **)[_typesPointers itemAtIndex: index + 1]; } @end | > > > > > > > > > > > | 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | return self; } - (void)dealloc { [_typesPointers release]; [_offsets release]; [super dealloc]; } - (size_t)numberOfArguments { return [_typesPointers count] - 1; } - (const char *)methodReturnType { return *(const char **)[_typesPointers firstItem]; } - (size_t)frameLength { return *(size_t *)[_offsets firstItem]; } - (const char *)argumentTypeAtIndex: (size_t)index { return *(const char **)[_typesPointers itemAtIndex: index + 1]; } - (size_t)argumentOffsetAtIndex: (size_t)index { return *(size_t *)[_offsets itemAtIndex: index + 1]; } @end |
Modified tests/OFMethodSignatureTests.m from [893652a1f7] to [92ff74642f].
︙ | ︙ | |||
36 37 38 39 40 41 42 | TEST(@"-[:signatureWithObjCTypes:] #1", (ms = [OFMethodSignature signatureWithObjCTypes: "i28@0:8S16*20"]) && [ms numberOfArguments] == 4 && strcmp([ms methodReturnType], "i") == 0 && strcmp([ms argumentTypeAtIndex: 0], "@") == 0 && strcmp([ms argumentTypeAtIndex: 1], ":") == 0 && strcmp([ms argumentTypeAtIndex: 2], "S") == 0 && | | > > > > | > > > | 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | TEST(@"-[:signatureWithObjCTypes:] #1", (ms = [OFMethodSignature signatureWithObjCTypes: "i28@0:8S16*20"]) && [ms numberOfArguments] == 4 && strcmp([ms methodReturnType], "i") == 0 && strcmp([ms argumentTypeAtIndex: 0], "@") == 0 && strcmp([ms argumentTypeAtIndex: 1], ":") == 0 && strcmp([ms argumentTypeAtIndex: 2], "S") == 0 && strcmp([ms argumentTypeAtIndex: 3], "*") == 0 && [ms frameLength] == 28 && [ms argumentOffsetAtIndex: 0] == 0 && [ms argumentOffsetAtIndex: 1] == 8 && [ms argumentOffsetAtIndex: 2] == 16 && [ms argumentOffsetAtIndex: 3] == 20) TEST(@"-[signatureWithObjCTypes:] #2", (ms = [OFMethodSignature signatureWithObjCTypes: "{s0=csi(u1={s2=iii{s3=(u4=ic^v*)}})}24@0:8" "^{s0=csi(u1={s2=iii{s3=(u4=ic^v*)}})}16"]) && [ms numberOfArguments] == 3 && strcmp([ms methodReturnType], "{s0=csi(u1={s2=iii{s3=(u4=ic^v*)}})}") == 0 && strcmp([ms argumentTypeAtIndex: 0], "@") == 0 && strcmp([ms argumentTypeAtIndex: 1], ":") == 0 && strcmp([ms argumentTypeAtIndex: 2], "^{s0=csi(u1={s2=iii{s3=(u4=ic^v*)}})}") == 0 && [ms frameLength] == 24 && [ms argumentOffsetAtIndex: 0] == 0 && [ms argumentOffsetAtIndex: 1] == 8 && [ms argumentOffsetAtIndex: 2] == 16) EXPECT_EXCEPTION(@"-[signatureWithObjCTypes:] #3", OFInvalidFormatException, [OFMethodSignature signatureWithObjCTypes: "{ii"]) EXPECT_EXCEPTION(@"-[signatureWithObjCTypes:] #4", OFInvalidFormatException, |
︙ | ︙ |