Skip to content

Start documenting the Objective-C ABI#7923

Merged
dlang-bot merged 1 commit intodlang:masterfrom
jacob-carlborg:objc_abi_docs
Mar 5, 2018
Merged

Start documenting the Objective-C ABI#7923
dlang-bot merged 1 commit intodlang:masterfrom
jacob-carlborg:objc_abi_docs

Conversation

@jacob-carlborg
Copy link
Copy Markdown
Contributor

This does not include the complete ABI, only what's necessary to call instance methods and class methods. This document will be extended when additional features are added.

@dlang-bot
Copy link
Copy Markdown
Contributor

Thanks for your pull request and interest in making D better, @jacob-carlborg! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the annotated coverage diff directly on GitHub with CodeCov's browser extension
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

@jacob-carlborg
Copy link
Copy Markdown
Contributor Author

@JinShil @ibuclaw @WalterBright @wilzbach @UplinkCoder please have a look.

Copy link
Copy Markdown
Contributor

@JinShil JinShil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't say I understand all of this, but if I were maintaining the Objective-C features of DMD, I think it would come in handy. My review is mostly just a bunch of nits.

from implementation stand point is that in D and C++ a vtable is used which
is an array of function pointers and the compiler uses an index into that array
to determine which method to call. In Objective-C it's the runtime that is
responsible to find the correct implementation when a message is sent to an
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/to find/for finding

int result = objc_msgSend(receiver, selector);
```

If the method expects any arguments they're passed after the selector argument:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/they're/it's

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But arguments is plural?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I don't know what I was thinking. Just ignore anything stupid in my comments.

id objc_msgSend(id self, SEL op, ...);
```

* The first parameter is the receiver (this/self pointer)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should "this" and "self" be surrounded by tick marks?


The call to `objc_msgSend` should not be performed as a variadic call but
instead as if it had the same signature as the method that should be called but
with the two additional parameter, `self` and `op`, added first. The
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That first sentence is a little hard to follow. Maybe it can be rephrased.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it slightly, but I'm not sure if it's any better. Writing is not my strongest skill. Suggestions are welcome.

implementation of `objc_msgSend` will jump to the method instead of calling it.

Because of the above, multiple versions of `objc_msgSend` exist. Depending on
the return type of the method that is called the correct version need to be
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comma after "called".

s/the correct version need to be used/the correct version will be used


For each selector that is used, a symbol is generated in the resulting binary.
The symbol has the name `L_OBJC_METH_VAR_NAME_.<number>`, where `<number>` is an
incrementing number. The selector is stored as a null terminated C string as the
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/as the section data/in the data section?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how to best describe it but the data stored in this section is the selector.

For each externally defined class that is referenced, a symbol is generated in
the resulting binary. The symbol has the name
`L_OBJC_CLASSLIST_REFERENCES_$_.<number>`, where `<number>` is an incrementing
number. The content of the symbols is a reference to an externally defined
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should "symbols" be singular here?


### `L_OBJC_IMAGE_INFO`

For any binary that is built the `L_OBJC_IMAGE_INFO` symbols is generated. The
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comma after built?


Indicates if features like: garbage collector, automatic reference counting
(ARC) or class properties are supported. These features can be enabled/disabled
in the Clang compiler using command line switches. The exact values used or the
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comma after "used" and "supported"?


## Tools

Here follows a list of useful tools that can/has been used to get the
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/has/have

This does not include the complete ABI, only what's necessary to call
instance methods and class methods. This document will be extended
when additional features are added.
@jacob-carlborg
Copy link
Copy Markdown
Contributor Author

Fixed all comments, except two, where I asked for more input.

@JinShil JinShil added the Merge:72h no objection -> merge The PR will be merged if there are no objections raised. label Feb 28, 2018
@jacob-carlborg
Copy link
Copy Markdown
Contributor Author

jacob-carlborg commented Mar 5, 2018

@JinShil @wilzbach can we please merge this as well. #7762 is already merged.

@dlang-bot dlang-bot merged commit d8642fe into dlang:master Mar 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Merge:auto-merge Merge:72h no objection -> merge The PR will be merged if there are no objections raised.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants