metal-rs icon indicating copy to clipboard operation
metal-rs copied to clipboard

Use `objc2` instead of `objc`

Open madsmtm opened this issue 1 year ago • 7 comments

Replace objc with my fork, objc2.

This crate contains many improvements, in particular:

  • Better tools for protecting against UB (see first commit)
  • You no longer have to worry about using bool in msg_send!.
  • The msg_send_id! macro greatly helps with follow memory management rules (similar to Objective-C ARC), potentially also alleviating a lot of the need for autoreleasepools.
  • The extern_protocol! macro is used in place of foreign_obj_type!

Notable breaking changes:

  • objc2::Message differs from objc::Message, so message sending is not compatible

  • NSUInteger is now usize instead of u32/u64 depending on platform (equivalently for NSInteger)

  • There is no longer three types for each class (e.g. MTLFoo, Foo and FooRef); these have been combined into one: Foo. Pointers to this can be used across FFI boundaries, and objc2::rc::Id<Foo, Shared> can be used as a strong pointer. In table form:

    Previously Now
    *mut MTLFoo *mut Foo
    &FooRef &Foo
    Foo Id<Foo, Shared>

When done, this should resolve the following issues:

  • Fixes https://github.com/gfx-rs/metal-rs/issues/5 now
  • Later: https://github.com/gfx-rs/metal-rs/issues/222
  • Later: https://github.com/gfx-rs/metal-rs/issues/218
  • Later: https://github.com/gfx-rs/metal-rs/issues/128
  • Later: https://github.com/gfx-rs/metal-rs/issues/86
  • Later: https://github.com/gfx-rs/metal-rs/issues/99
  • Later: https://github.com/gfx-rs/metal-rs/issues/225
  • Later: https://github.com/gfx-rs/metal-rs/issues/58
  • Later: https://github.com/gfx-rs/metal-rs/issues/282
  • Later: https://github.com/gfx-rs/metal-rs/issues/284

madsmtm avatar Sep 01 '22 16:09 madsmtm