Skip to content

Commit

Permalink
Each function's role is described briefly (allocation vs. initializat…
Browse files Browse the repository at this point in the history
…ion)
  • Loading branch information
kojix2 committed Sep 19, 2024
1 parent ce3c2a0 commit fa4eae6
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions ext/bio/cgranges/cgranges.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ static cgranges_t *get_cgranges(VALUE self)
return ptr;
}

/*
* Allocates memory for a CGRanges object.
* This is called by rb_define_alloc_func and is responsible for
* memory allocation only, not initialization.
* Raises NoMemoryError if memory allocation fails.
*/

static VALUE
cgranges_allocate(VALUE klass)
{
Expand All @@ -94,17 +101,21 @@ cgranges_allocate(VALUE klass)
return Qnil;
}

// Wrap the C struct in a Ruby object and link with garbage collection
return TypedData_Wrap_Struct(klass, &cgranges_type, ptr);
}

/* Create a new cgranges object
*
* @return [Bio::CGRanges]
/*
* Initializes the CGRanges object.
* Called after memory is allocated by the allocate function.
* This method sets instance variable @indexed to false.
* @return [Bio::CGRanges] self
*/

static VALUE
cgranges_init(VALUE self)
{
// Retrieve the cgranges object
cgranges_t *cr = DATA_PTR(self);

if (!cr)
Expand All @@ -113,6 +124,7 @@ cgranges_init(VALUE self)
return Qnil;
}

// Set the @indexed instance variable to false
rb_ivar_set(self, rb_intern("@indexed"), Qfalse);

return self;
Expand Down

0 comments on commit fa4eae6

Please # to comment.