msgpack-ruby icon indicating copy to clipboard operation
msgpack-ruby copied to clipboard

Use TypedData structs

Open casperisfine opened this issue 2 years ago • 3 comments

The API is a bit more modern and open the door to several features such as memsize, write barriers etc.

The main addition for now is support for memsize_of:

>> ObjectSpace.memsize_of(f)
=> 2128

Note: Buffer is still "untyped" because there is actually two types of buffer. Some with their own memory region, and in charge of freeing it, and some that point to the Unpacker memory and need to not have a free function.

For now I don't see how to do this with TypedData structs.

casperisfine avatar Feb 11 '22 10:02 casperisfine

Honestly speaking, I have almost no idea about TypeData structs. Could you point any kind of documents or texts we can learn it?

tagomoris avatar Mar 15 '22 11:03 tagomoris

Could you point any kind of documents or texts we can learn it?

I'll try to find some more, the MRI C API is unfortunately very undocumented. In the meantime there's this ticket (in japanese so I don't know what it says): https://bugs.ruby-lang.org/issues/1637

casperisfine avatar Mar 15 '22 12:03 casperisfine

A few more resources:

  • The official extension doc: https://github.com/ruby/ruby/blob/master/doc/extension.rdoc
  • Some unofficial (but generally more helpful) API guide: https://silverhammermba.github.io/emberb/c/#data
  • A somewhat "tutorially" description of it: https://blog.peterzhu.ca/ruby-c-ext-part-7/

casperisfine avatar Mar 15 '22 12:03 casperisfine

We should get on and do this - the old data API is very deprecated, and causes problems for future GC.

chrisseaton avatar Aug 22 '22 12:08 chrisseaton

Agreed. I may need to do it one class at a time though because this was too big of a change for me.

I'll try to get back at this this week.

byroot avatar Aug 22 '22 13:08 byroot

This has been split in 3 distinct PRs, one for each type.

byroot avatar Aug 24 '22 13:08 byroot