Skip to content

Latest commit

 

History

History
222 lines (147 loc) · 9.76 KB

README.md

File metadata and controls

222 lines (147 loc) · 9.76 KB

mulle-objc-runtime

⏩ A fast, portable Objective-C runtime written 100% in C11

A portable Objective-C runtime written in C11. No Assembler required. It follows the Apple "Objective-C 1 Runtime" and adds many features from "Objective-C 2.0", but the runtime function calls are completely different. It is designed to be suitable for massive multi-threading.

Release Version Release Notes
Mulle kybernetiK tag Build Status RELEASENOTES

API

Data structure Description
_mulle_objc_class Deal with Classes
_mulle_objc_ivar et al. Instance variables
_mulle_objc_loadinfo Install Classes, Categories, Methods, Strings into the runtime
_mulle_objc_method et al. Deal with Methods
_mulle_objc_object et al. Deal with Instances
_mulle_objc_property et al. Handle Properties
_mulle_objc_universe Work with the runtime universe
Function type Description
Global Functions Global functions and conveniences
Exceptions Raising exceptions
Vararg extensions Dealing with variable arguments

Usage

If you haven't used an Objective-C runtime before, it is useful to get to know the much better documented "Mac OS X Objective-C 1.0" runtime first. Intro to the Objective-C Runtime could be a good starting point.

C Caveat

It you use .c files that include <mulle-objc-runtime/mulle-objc-runtime.h> make sure that you compile with __MULLE_OBJC_TPS__, __MULLE_OBJC_NO_TPS__ __MULLE_OBJC_FCS__ __MULLE_OBJC_NO_FCS__ as defined when compiling the runtime. Since C-only compilations do not emit runtime information, mismatches can not be checked by the runtime. Easy fix: rename .c to .m and use mulle-clang

What's so different ?

  • Runtime objects (like classes and selectors) are not referenced by name, but by a unique ID. No special linker action required.

  • Parameters outside of self and _cmd are passed via _param, a single pointer to a struct. This simplifies a lot of code, especially forwarding code. Return values are also returned with the same struct. Optimizations are done for simple methods with only none or one parameter and none or one return value.

  • It uses inlineable method calls for superior performance. The user can specify "fast" classes and "fast" methods for extra speed in performance critical cases.

  • retain/release semantics are built in. These are non-overridable, which makes them a lot faster.

  • isa is not part of the instance, but instead prefixed to the instance.

  • Protocol as a type and an object does not exist anymore. Instead there is PROTOCOL which is basically the same as SEL and has compiler support.

  • No global lock, except when loading code. The runtime in normal operation only locks during +initialize on a per class basis.

  • Protections against the fragile base class problem

  • Multiple runtimes can coexist in differently named "universes".

Articles

These articles give you some background about the mulle-objc runtime:

  1. mulle-objc: a new Objective-C runtime
  2. mulle-objc: a meta calling convention
  3. mulle-objc: removing superflous ifs
  4. mulle-objc: inlined messaging
  5. mulle-objc: some research about selectors
  6. mulle-objc: hashes for classes, selectors and protocols
  7. mulle_objc: object layout, retain counting, finalize
  8. mulle_objc: inheriting methods from protocols
  9. mulle_objc: present and absent language features
  10. mulle_objc: the trouble with @property
  11. mulle_objc: ivar layout with @property
  12. mulle_objc: technically speaking
  13. mulle-clang, technically speaking
  14. mulle-objc-runtime, technically speaking
  15. MulleFoundation, technically speaking

If something is unclear, feel free to contact the author.

You are here

Overview

Requirements

Requirement Release Version Description
mulle-core Mulle kybernetiK tag Build Status 🌋 Almagamated library of mulle-core and mulle-c
mulle-atinit Mulle kybernetiK tag Build Status 🤱🏼 Compatibility library for deterministic initializers
mulle-atexit Mulle kybernetiK tag Build Status 👼 Compatibility library to fix atexit

Add

Use mulle-sde to add mulle-objc-runtime to your project. As long as your sources are using #include "include-private.h" and your headers use #include "include.h", there will nothing more to do:

mulle-sde add github:mulle-objc/mulle-objc-runtime

To only add the sources of mulle-objc-runtime with dependency sources use clib:

Legacy adds

One common denominator is that you will likely have to add #include <mulle-objc-runtime/mulle-objc-runtime.h> to your source files.

Add sources to your project with clib

clib install --out src/mulle-objc mulle-objc/mulle-objc-runtime

Add -isystem src/mulle-objc to your CFLAGS and compile all the sources that were downloaded with your project. (In cmake add include_directories( BEFORE SYSTEM src/mulle-objc) to your CMakeLists.txt file).

Add as subproject with cmake and git

git submodule add -f --name "mulle-core" \
                            "https://github.com/mulle-core/mulle-core.git" \
                            "stash/mulle-core"
git submodule add -f --name "mulle-atinit" \
                            "https://github.com/mulle-core/mulle-atinit.git" \
                            "stash/mulle-atinit"
git submodule add -f --name "mulle-atexit" \
                            "https://github.com/mulle-core/mulle-atexit.git" \
                            "stash/mulle-atexit"
git submodule add -f --name "mulle-objc-runtime" \
                            "https://github.com/mulle-objc/mulle-objc-runtime" \
                            "stash/mulle-objc-runtime"
git submodule update --init --recursive
add_subdirectory( stash/mulle-objc-runtime)
add_subdirectory( stash/mulle-atexit)
add_subdirectory( stash/mulle-atinit)
add_subdirectory( stash/mulle-core)

target_link_libraries( ${PROJECT_NAME} PUBLIC mulle-objc-runtime)
target_link_libraries( ${PROJECT_NAME} PUBLIC mulle-atexit)
target_link_libraries( ${PROJECT_NAME} PUBLIC mulle-atinit)
target_link_libraries( ${PROJECT_NAME} PUBLIC mulle-core)

Install

Install with mulle-sde

Use mulle-sde to build and install mulle-objc-runtime and all dependencies:

mulle-sde install --prefix /usr/local \
   https://github.com/mulle-objc/mulle-objc-runtime/archive/latest.tar.gz

Manual Installation

Install the Requirements and then install mulle-objc-runtime with cmake:

cmake -B build \
      -DCMAKE_INSTALL_PREFIX=/usr/local \
      -DCMAKE_PREFIX_PATH=/usr/local \
      -DCMAKE_BUILD_TYPE=Release &&
cmake --build build --config Release &&
cmake --install build --config Release

Author

Nat! for Mulle kybernetiK