detached b4ba55d

better error message and padding support (#83)

This commit improves the error message when the Ivar and struct field are not at the same offset. 

If the parent class has fields its fields are located before the child's in the struct. This causes issues since there is no way to know the internal structure of the class so padding is required. This commit enables the use of padding by using the underscore (_) identifier with an array of bytes that matches the parent's field size. Still, if any fields are misaligned an error is produced.
commit
b4ba55de7c488d0483dd40f45e8dbd6be4b8ea44
author
TotallyGamerJet · · 2022-12-17 18:34 UTC
committer
GitHub · · 2022-12-17 18:34 UTC
parent
7b60891
signature
GPG Unverified4AEE18F83AFDEB23 The key is unknown
1 file · +4 -1
M objc/objc_runtime_darwin.go +4 -1
@@ -286,6 +286,9 @@ func RegisterClass(object Selector) (Class, error) {
286286 // Start at 1 because we skip the class object which is first
287287 for i := 1; i < strct.NumField(); i++ {
288288 f := strct.Field(i)
289+ if f.Name == "_" {
290+ continue
291+ }
289292 size := f.Type.Size()
290293 alignment := uint8(math.Log2(float64(f.Type.Align())))
291294 enc, err := encodeType(f.Type, false)
@@ -296,7 +299,7 @@ func RegisterClass(object Selector) (Class, error) {
296299 return 0, fmt.Errorf("objc: couldn't add Ivar %s", f.Name)
297300 }
298301 if offset := class.InstanceVariable(f.Name).Offset(); offset != f.Offset {
299- return 0, fmt.Errorf("objc: couldn't add Ivar %s", f.Name)
302+ return 0, fmt.Errorf("objc: couldn't add Ivar %s because offset (%d != %d)", f.Name, offset, f.Offset)
300303 }
301304 }
302305 objc_registerClassPair(class)
@@ -286,6 +286,9 @@ func RegisterClass(object Selector) (Class, error) {
286 // Start at 1 because we skip the class object which is first286 // Start at 1 because we skip the class object which is first
287 for i := 1; i < strct.NumField(); i++ {287 for i := 1; i < strct.NumField(); i++ {
288 f := strct.Field(i)288 f := strct.Field(i)
289+ if f.Name == "_" {
290+ continue
291+ }
289 size := f.Type.Size()292 size := f.Type.Size()
290 alignment := uint8(math.Log2(float64(f.Type.Align())))293 alignment := uint8(math.Log2(float64(f.Type.Align())))
291 enc, err := encodeType(f.Type, false)294 enc, err := encodeType(f.Type, false)
@@ -296,7 +299,7 @@ func RegisterClass(object Selector) (Class, error) {
296 return 0, fmt.Errorf("objc: couldn't add Ivar %s", f.Name)299 return 0, fmt.Errorf("objc: couldn't add Ivar %s", f.Name)
297 }300 }
298 if offset := class.InstanceVariable(f.Name).Offset(); offset != f.Offset {301 if offset := class.InstanceVariable(f.Name).Offset(); offset != f.Offset {
299- return 0, fmt.Errorf("objc: couldn't add Ivar %s", f.Name)302+ return 0, fmt.Errorf("objc: couldn't add Ivar %s because offset (%d != %d)", f.Name, offset, f.Offset)
300 }303 }
301 }304 }
302 objc_registerClassPair(class)305 objc_registerClassPair(class)

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 102

↑↓ moveenter openesc close