Skip to content

Commit

Permalink
Merge pull request #99 from Shopify/typed-data
Browse files Browse the repository at this point in the history
Convert to TypedData API
  • Loading branch information
casperisfine authored Nov 10, 2023
2 parents 0df1312 + 73c7980 commit 59e3ecc
Show file tree
Hide file tree
Showing 7 changed files with 265 additions and 151 deletions.
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
source "https://rubygems.org"
gemspec

gem "rubocop", "~> 1.22", require: false
gem "rubocop-shopify", "~> 2.3.0", require: false
gem "rubocop", require: false
gem "rubocop-shopify", require: false
gem "ruby_memcheck", "~> 0.3.0", require: false
2 changes: 1 addition & 1 deletion dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ env:
ROTOSCOPE_COMPILE_ERROR: '1'

up:
- ruby: 2.7.4
- ruby: 2.7.8
- homebrew:
- clang-format
- bundler
Expand Down
24 changes: 20 additions & 4 deletions ext/rotoscope/rotoscope.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,22 +132,38 @@ static void event_hook(VALUE tpval, void *data) {
rb_funcall(config->trace_proc, id_call, 1, config->self);
}

static void rs_gc_mark(Rotoscope *config) {
static void rs_gc_mark(void *data) {
Rotoscope *config = (Rotoscope *)data;
rb_gc_mark(config->tracepoint);
rb_gc_mark(config->trace_proc);
rs_stack_mark(&config->stack);
}

void rs_dealloc(Rotoscope *config) {
static void rs_dealloc(void *data) {
Rotoscope *config = (Rotoscope *)data;
stop_tracing_on_cleanup(config);
rs_stack_free(&config->stack);
xfree(config);
}

static size_t rs_memsize(const void *data) {
return sizeof(Rotoscope);
}

static const rb_data_type_t rs_data_type = {
.wrap_struct_name = "Rotoscope",
.function = {
.dmark = rs_gc_mark,
.dfree = rs_dealloc,
.dsize = rs_memsize,
},
.flags = RUBY_TYPED_FREE_IMMEDIATELY
};

static VALUE rs_alloc(VALUE klass) {
Rotoscope *config;
VALUE self =
Data_Make_Struct(klass, Rotoscope, rs_gc_mark, rs_dealloc, config);
TypedData_Make_Struct(klass, Rotoscope, &rs_data_type, config);
config->self = self;
config->pid = getpid();
config->tid = current_thread_id();
Expand All @@ -168,7 +184,7 @@ static VALUE rs_alloc(VALUE klass) {

static Rotoscope *get_config(VALUE self) {
Rotoscope *config;
Data_Get_Struct(self, Rotoscope, config);
TypedData_Get_Struct(self, Rotoscope, &rs_data_type, config);
return config;
}

Expand Down
2 changes: 2 additions & 0 deletions lib/rotoscope/call_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def closed?

def state
return :closed if io.closed?

@rotoscope.tracing? ? :tracing : :open
end

Expand Down Expand Up @@ -142,6 +143,7 @@ def prevent_flush_from_finalizer_in_fork(io)
pid = Process.pid
finalizer = lambda do |_|
next if Process.pid == pid

# close the file descriptor from another IO object so
# buffered writes aren't flushed
IO.for_fd(io.fileno).close
Expand Down
2 changes: 1 addition & 1 deletion lib/rotoscope/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

class Rotoscope
VERSION = "0.3.1.pre.1"
VERSION = "0.3.1.pre.2"
end
6 changes: 4 additions & 2 deletions test/monadify.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# frozen_string_literal: true

module Monadify
def self.extended(base)
base.define_singleton_method("contents=") { |val| val }
class << self
def extended(base)
base.define_singleton_method("contents=") { |val| val }
end
end

define_method("contents") do
Expand Down
376 changes: 235 additions & 141 deletions test/rotoscope_test.rb

Large diffs are not rendered by default.

0 comments on commit 59e3ecc

Please sign in to comment.