rust-lang / rust-lang/rust-bindgen

Objective-c method generation uses implementation variable names

Open
#1,705 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-Obj-C enhancement help wanted
Dominant language
Rust
Stars
5.3k
Forks
829
Avg merge
1d 1h
Merged PRs (30d)
15

Description

I'm on the fence for filing this issue because after testing out all of the iOS frameworks on my system, I've had this issue happen twice but I figure it's useful for documentation purposes if it doesn't get fixed.

According to the apple developer docs:

- (void)someMethodWithValue:(SomeType)value;
Note: The value1 and value2 value names used above aren’t strictly part of the method declaration, which means it’s not necessary to use exactly the same value names in the declaration as you do in the implementation. The only requirement is that the signature matches, which means you must keep the name of the method as well as the parameter and return types exactly the same.

As an example, this method has the same signature as the one shown above:
- (void)someMethodWithFirstValue:(SomeType)info1 secondValue:(AnotherType)info2;

This is also against apples guidelines I'm quite sure (cause why would it not).

Anyway, this is an issue because the headers for translateInCameraSpaceByX:Y:Z from SCNCameraController in SceneKit and dividerImageForLeftSegmentState:rightSegmentState from UIStepper in UIKit have the same name (state and deltaX respectively).

Ideally, the method names in the generation are from the sender name variable name. This is also related to #1703 because method headers that don't have sender names require the existing functionality.

Input Objective-C Header
@interface CAMediaTimingFunction
- (float *)dividerImageForLeftSegmentState:(float)state
                         rightSegmentState:(float)state;
@end
Bindgen Invocation
$ bindgen input.h -- -x objective-c
Actual Results
use objc;
#[allow(non_camel_case_types)]
pub type id = *mut objc::runtime::Object;
pub trait CAMediaTimingFunction {
    unsafe fn dividerImageForLeftSegmentState_rightSegmentState_(
        self,
        state: f32,
        state: f32,
    ) -> *mut f32;
}
impl CAMediaTimingFunction for id {
    unsafe fn dividerImageForLeftSegmentState_rightSegmentState_(
        self,
        state: f32,
        state: f32,
    ) -> *mut f32 {
        msg_send ! ( self , dividerImageForLeftSegmentState : state rightSegmentState : state )
    }
}
Expected Results
pub trait CAMediaTimingFunction {
    unsafe fn dividerImageForLeftSegmentState_rightSegmentState_(
        self,
        state: f32,
        rightSegmentState: f32,
    ) -> *mut f32;
}
impl CAMediaTimingFunction for id {
    unsafe fn dividerImageForLeftSegmentState_rightSegmentState_(
        self,
        state: f32,
        rightSegmentState: f32,
    ) -> *mut f32 {
        msg_send ! ( self , dividerImageForLeftSegmentState : state rightSegmentState : rightSegmentState )
    }
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the shown bindgen invocation with the provided Objective-C header and compare the generated trait, implementation, and msg_send arguments with the expected output. Trace Objective-C method-parameter name generation, including the sender-name case referenced in #1703; done means distinct names are preserved without breaking headers that lack sender names.

Written by the indexing model from the issue text.

Assessment

Tech stack
objective-c, rust
Domain
devtools, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.