Skip to content

Resource Checklist (Direct/Host side) #16

@cpetig

Description

@cpetig

Header File

  • guest imported classes should include a definition header
  • g.i. resource returning functions should return R::Owned
  • g.i. res. consuming functions should received R::Owned
  • exported res. shouldn't include a header
  • g.e. function consuming should use && args

Code:

  • g.i. dtor should become X00X5Bresource_dropX5D
    • Contents:
  auto ptr = T::remove_resource(idx);
  assert(ptr.has_value());
  T::Dtor(*ptr);
  • g.i. ctor should call new and
    • return result0.release()->get_handle();
  • g.i. borrowing funcs should (**T::lookup_resource(arg0))
    • stretch goal: With assertion that lookup succeeded
  • g.i. consuming funs should
  auto objptr = T::remove_resource(arg0);
  assert(objptr.has_value());
  func(T::Owned(*objptr));
  • Missing functions for guest export:
extern "C" int32_t X5BexportX5DfooX3AfooX2FresourcesX00X5Bresource_newX5Dr(uint8_t* rep) {
  return exports::foo::foo::resources::R::store_resource(std::move(rep));
}
extern "C" void X5BexportX5DfooX3AfooX2FresourcesX00X5Bresource_dropX5Dr(int32_t idx) {
  exports::foo::foo::resources::R::remove_resource(idx);
}
  • g.e. Dtor should become a normal dtor with if (this->rep) X5BdtorX5Dr(this->rep);
  • g.e. ctor should this->index = ret; this->rep = *lookup_resource(ret);
  • g.e. methods should call get_rep() instead of get_handle()
  • g.e. res. returning funcs should go via wit::ResourceExportBase
  • g.e. res. borrowing funcs should add .get() and use get_rep()
  • g.e. res. consuming funcs should receive &&
  • g.e. res. consuming funcs should use
  auto rep = o.take_rep();
  R::remove_resource(o.get_handle());
  consume(rep);
  • create ResourceExportBase based move ctors

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions