ext/Row.c in rubyfb-0.6.2 vs ext/Row.c in rubyfb-0.6.3

- old
+ new

@@ -56,12 +56,49 @@ static VALUE rowValuesAt(int, VALUE *, VALUE); /* Globals. */ VALUE cRow; +/** + * This function integrates with the Ruby garbage collector to insure that + * all resources associated with a Row object are marked during the mark phase + * + * @param row A pointer to the RowHandle object for the Row object. + * + */ +void rowGCMark(void *handle) { + if(handle != NULL) { + RowHandle *row = (RowHandle *)handle; + int i; + for(i = 0; i < row->size; i++) { + rb_gc_mark(row->columns[i].value); + rb_gc_mark(row->columns[i].type); + rb_gc_mark(row->columns[i].scale); + } + } +} /** + * This function integrates with the Ruby garbage collector to insure that + * all resources associated with a Row object are released whenever the Row + * object is collected. + * + * @param row A pointer to the RowHandle object for the Row object. + * + */ +void freeRow(void *row) { + if(row != NULL) { + RowHandle *handle = (RowHandle *)row; + + if(handle->columns != NULL) { + free(handle->columns); + } + free(handle); + } +} + +/** * This function integrates with the Ruby memory allocation system to allocate * space for new Row objects. * * @param klass A reference to the Row class. * @@ -75,11 +112,11 @@ if(handle != NULL) { /* Initialise the row fields. */ handle->size = 0; handle->number = 0; handle->columns = NULL; - row = Data_Wrap_Struct(klass, NULL, freeRow, handle); + row = Data_Wrap_Struct(klass, rowGCMark, freeRow, handle); } else { /* Generate an exception. */ rb_raise(rb_eNoMemError, "Memory allocation failure allocating a row."); } @@ -811,29 +848,9 @@ for(i = 0; i < size; i++) { rb_ary_push(result, getColumnValue(self, keys[i])); } return(result); -} - - -/** - * This function integrates with the Ruby garbage collector to insure that - * all resources associated with a Row object are released whenever the Row - * object is collected. - * - * @param row A pointer to the RowHandle object for the Row object. - * - */ -void freeRow(void *row) { - if(row != NULL) { - RowHandle *handle = (RowHandle *)row; - - if(handle->columns != NULL) { - free(handle->columns); - } - free(handle); - } } /** * This function provides a programmatic means of creating a Row object.