Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4226e80

Browse files
committed
Bug fixes, RootObject.release()
- Added `isa` to `RootObject` (whoops, that's important…)- Added `release()` to `RootObject`- Added `Pointer.free()` which takes no arguments, as it should be
1 parentf41f6fc commit4226e80

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

‎Runtime/Method.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class Method: Hashable {
2727
self.imp= imp
2828
}
2929

30-
conveniencepublicinit(_name:String, signature:Signauture=(.void,[]), _ imp:@escapingIMP){
30+
conveniencepublicinit(name:String, signature:Signauture=(.void,[]), _ imp:@escapingIMP){
3131
self.init(name, returns: signature.returnType, args: signature.argumentTypes, imp)
3232
}
3333

‎Runtime/Pointer.swift‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ public struct Pointer<Pointee>: Strideable, Hashable, Equatable {
9090
#endif
9191
}
9292

93+
publicfunc free(){
94+
#if os(Linux)
95+
Glibc.free(self.raw)
96+
#else
97+
Darwin.free(self.raw)
98+
#endif
99+
}
100+
93101
publicfunc free(_ count:Int){
94102
self.raw.deallocate(bytes: count, alignedTo: MemoryLayout<Pointee>.alignment)
95103
}

‎Runtime/RootObject.swift‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public struct RootObject {
1515
isa:RootObject_meta.class,
1616
superclass:nil,
1717
name:"Object",
18-
ivars:[("_retainCount",.integer)],
18+
ivars:[("isa",.pointer(.class("self"))),("_retainCount",.integer)],
1919
methods:[_init, retain, retainCount]
2020
)
2121

@@ -38,6 +38,23 @@ public struct RootObject {
3838
returnretain$(this, _cmd)
3939
}
4040

41+
staticvarrelease=Method("release"){ this, _cmd, argsin
42+
func release$(_ this:id, _ _cmd:SEL){
43+
letnewCount:Int=(this|"_retainCount")-1
44+
this|=(newCount,"_retainCount")
45+
if newCount<1{
46+
if newCount<0{
47+
fatalError("Over-released object at\(this.raw.debugDescription)")
48+
}
49+
50+
this.free()
51+
}
52+
}
53+
54+
release$(this, _cmd)
55+
return()
56+
}
57+
4158
staticvarretainCount=Method("retainCount", returns:.integer){ this, _cmd, argsin
4259
func retainCount$(_ this:id, _ _cmd:SEL){
4360
return this|"_retainCount"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp