Skip to content

Commit e25f40f

Browse files
committed
Swift 3.0
1 parent ab7c690 commit e25f40f

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

StringIO.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// Created by John Holdsworth on 28/09/2015.
66
// Copyright © 2015 John Holdsworth. All rights reserved.
77
//
8-
// $Id: //depot/SwiftRuby/StringIO.swift#8 $
8+
// $Id: //depot/SwiftRuby/StringIO.swift#9 $
99
//
1010
// Repo: https://github.com/RubyNative/SwiftRuby
1111
//
@@ -109,6 +109,7 @@ open class StringIO: IO {
109109
return self
110110
}
111111

112+
@discardableResult
112113
open override func seek( _ amount: Int, _ whence: Int, file: StaticString = #file, line: UInt = #line ) -> Bool {
113114
switch Int32(whence) {
114115
case SEEK_SET:

Utilities.m

+18-9
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// Created by John Holdsworth on 26/09/2015.
66
// Copyright © 2015 John Holdsworth. All rights reserved.
77
//
8-
// $Id: //depot/SwiftRuby/Utilities.m#17 $
8+
// $Id: //depot/SwiftRuby/Utilities.m#18 $
99
//
1010
// Repo: https://github.com/RubyNative/SwiftRuby
1111
//
@@ -28,17 +28,25 @@
2828
int f1, f2; // added for 1.0 Beta5
2929
int size, tos, mdsize, eight;
3030

31-
struct __swift_data {
32-
unsigned long flags;
31+
struct _swift_data3 {
32+
// unsigned long flags;
3333
const char *className;
3434
int fieldcount, flags2;
35-
const char *ivarNames;
36-
struct _swift_field **(*get_field_data)();
35+
int ivarNames;
36+
int get_field_data;
37+
// const char *ivarNames;
38+
// struct _swift_field **(*get_field_data)();
3739
} *swiftData;
3840

3941
IMP dispatch[1];
4042
};
4143

44+
// Swift3 pointers to some metadata are relative
45+
static const char *swift3Relative( void *ptrPtr ) {
46+
intptr_t offset = *(int *)ptrPtr;
47+
return offset < 0 ? (const char *)((intptr_t)ptrPtr + offset) : (const char *)offset;
48+
}
49+
4250
NSArray<NSString *> *instanceVariablesForClass( Class cls, NSMutableArray<NSString *> *ivarNames ) {
4351
Class superCls = class_getSuperclass( cls );
4452
if ( superCls )
@@ -47,12 +55,13 @@
4755
struct _in_objc_class *swiftClass = (__bridge struct _in_objc_class *)cls;
4856

4957
if ( (uintptr_t)swiftClass->internal & 0x1 ) {
50-
const char *names = swiftClass->swiftData->ivarNames;
58+
struct _swift_data3 *swiftData = (struct _swift_data3 *)swift3Relative( &swiftClass->swiftData );
59+
const char *nameptr = swift3Relative( &swiftData->ivarNames );
5160

52-
for ( int f = 0 ; f < swiftClass->swiftData->fieldcount ; f++ ) {
61+
for ( int f = 0 ; f < swiftData->fieldcount ; f++ ) {
5362
[ivarNames addObject:[NSString stringWithFormat:@"%@.%@", NSStringFromClass( cls ),
54-
[NSString stringWithUTF8String:names]]];
55-
names += strlen( names ) + 1;
63+
[NSString stringWithUTF8String:nameptr]]];
64+
nameptr += strlen( nameptr ) + 1;
5665
}
5766
}
5867
else {

0 commit comments

Comments
 (0)