Skip to content

Commit

Permalink
Merge pull request #224 from BallAerospace/c_ext_improvements
Browse files Browse the repository at this point in the history
closes #223 Minor C Extension Improvements
  • Loading branch information
ryanmelt committed Nov 20, 2015
2 parents 6e7e371 + a0e2dd7 commit 03a2213
Show file tree
Hide file tree
Showing 13 changed files with 147 additions and 147 deletions.
12 changes: 6 additions & 6 deletions ext/cosmos/ext/array/array.c
Expand Up @@ -22,9 +22,9 @@ static VALUE max_with_index (VALUE self)
int index = 0;
long array_length = RARRAY_LEN(self);
int maximum_index = 0;
VALUE value = Qnil;
VALUE maximum = Qnil;
VALUE return_value = Qnil;
volatile VALUE value = Qnil;
volatile VALUE maximum = Qnil;
volatile VALUE return_value = Qnil;

if (array_length > 0)
{
Expand Down Expand Up @@ -64,9 +64,9 @@ static VALUE min_with_index (VALUE self)
int index = 0;
long array_length = RARRAY_LEN(self);
int minimum_index = 0;
VALUE value = Qnil;
VALUE minimum = Qnil;
VALUE return_value = Qnil;
volatile VALUE value = Qnil;
volatile VALUE minimum = Qnil;
volatile VALUE return_value = Qnil;

if (array_length > 0)
{
Expand Down
20 changes: 10 additions & 10 deletions ext/cosmos/ext/buffered_file/buffered_file.c
Expand Up @@ -37,11 +37,11 @@ static VALUE buffered_file_initialize(int argc, VALUE* argv, VALUE self) {
/* Read using an internal buffer to avoid system calls */
static VALUE buffered_file_read(VALUE self, VALUE arg_length) {
long length = FIX2INT(arg_length);
VALUE buffer = rb_ivar_get(self, id_ivar_buffer);
volatile VALUE buffer = rb_ivar_get(self, id_ivar_buffer);
long buffer_length = RSTRING_LEN(buffer);
long buffer_index = FIX2INT(rb_ivar_get(self, id_ivar_buffer_index));
VALUE result = Qnil;
VALUE super_arg = Qnil;
volatile VALUE result = Qnil;
volatile VALUE super_arg = Qnil;

if (length <= (buffer_length - buffer_index)) {
/* Return part of the buffer without having to go to the OS */
Expand All @@ -59,7 +59,7 @@ static VALUE buffered_file_read(VALUE self, VALUE arg_length) {
rb_ivar_set(self, id_ivar_buffer_index, INT2FIX(0));
}
super_arg = INT2FIX(length - buffer_length);
rb_str_append(buffer, rb_funcall(rb_call_super(1, &super_arg), id_method_to_s, 0));
rb_str_append(buffer, rb_funcall(rb_call_super(1, (VALUE*) &super_arg), id_method_to_s, 0));
return rb_funcall(buffer, id_method_slice_bang, 1, rb_const_get(cBufferedFile, id_const_ALL_RANGE));
} else {
return rb_call_super(1, &arg_length);
Expand All @@ -73,7 +73,7 @@ static VALUE buffered_file_read(VALUE self, VALUE arg_length) {
rb_ivar_set(self, id_ivar_buffer_index, INT2FIX(0));
}
super_arg = INT2FIX(BUFFER_SIZE - buffer_length);
rb_str_append(buffer, rb_funcall(rb_call_super(1, &super_arg), id_method_to_s, 0));
rb_str_append(buffer, rb_funcall(rb_call_super(1, (VALUE*) &super_arg), id_method_to_s, 0));
buffer_length = RSTRING_LEN(buffer);
if (buffer_length <= 0) {
return Qnil;
Expand All @@ -92,7 +92,7 @@ static VALUE buffered_file_read(VALUE self, VALUE arg_length) {

/* Get the current file position */
static VALUE buffered_file_pos(VALUE self) {
VALUE parent_pos = rb_call_super(0, NULL);
volatile VALUE parent_pos = rb_call_super(0, NULL);
long long ll_pos = NUM2LL(parent_pos);
long buffer_length = RSTRING_LEN(rb_ivar_get(self, id_ivar_buffer));
long buffer_index = FIX2INT(rb_ivar_get(self, id_ivar_buffer_index));
Expand All @@ -101,10 +101,10 @@ static VALUE buffered_file_pos(VALUE self) {

/* Seek to a given file position */
static VALUE buffered_file_seek(int argc, VALUE* argv, VALUE self) {
VALUE amount = Qnil;
VALUE whence = Qnil;
volatile VALUE amount = Qnil;
volatile VALUE whence = Qnil;
long buffer_index = 0;
VALUE super_args[2] = {Qnil, Qnil};
volatile VALUE super_args[2] = {Qnil, Qnil};

switch (argc)
{
Expand All @@ -131,7 +131,7 @@ static VALUE buffered_file_seek(int argc, VALUE* argv, VALUE self) {
}
super_args[0] = rb_funcall(self, id_method_pos, 0);
super_args[1] = BUFFERED_FILE_SEEK_SET;
rb_call_super(2, super_args);
rb_call_super(2, (VALUE*) super_args);
}

rb_funcall(rb_ivar_get(self, id_ivar_buffer), id_method_clear, 0);
Expand Down
20 changes: 10 additions & 10 deletions ext/cosmos/ext/config_parser/config_parser.c
Expand Up @@ -76,16 +76,16 @@ static VALUE parse_loop(VALUE self, VALUE io, VALUE yield_non_keyword_lines, VAL
int index = 0;
double float_pos = 0.0;
double float_size = NUM2DBL(size);
VALUE progress_callback = rb_cvar_get(cConfigParser, id_cvar_progress_callback);
VALUE line = Qnil;
VALUE data = Qnil;
VALUE line_continuation = Qfalse;
VALUE string = Qnil;
VALUE array = rb_ary_new();
VALUE first_item = Qnil;
VALUE ivar_keyword = Qnil;
VALUE ivar_parameters = rb_ary_new();
VALUE ivar_line =Qnil;
volatile VALUE progress_callback = rb_cvar_get(cConfigParser, id_cvar_progress_callback);
volatile VALUE line = Qnil;
volatile VALUE data = Qnil;
volatile VALUE line_continuation = Qfalse;
volatile VALUE string = Qnil;
volatile VALUE array = rb_ary_new();
volatile VALUE first_item = Qnil;
volatile VALUE ivar_keyword = Qnil;
volatile VALUE ivar_parameters = rb_ary_new();
volatile VALUE ivar_line =Qnil;

rb_ivar_set(self, id_ivar_line_number, INT2FIX(0));
rb_ivar_set(self, id_ivar_keyword, ivar_keyword);
Expand Down
6 changes: 3 additions & 3 deletions ext/cosmos/ext/cosmos_io/cosmos_io.c
Expand Up @@ -41,9 +41,9 @@ static VALUE read_length_bytes(VALUE self, VALUE param_length_num_bytes)
long string_length = 0;
unsigned short short_length = 0;
unsigned char* length_ptr = NULL;
VALUE temp_string = Qnil;
VALUE temp_string_length = Qnil;
VALUE return_value = Qnil;
volatile VALUE temp_string = Qnil;
volatile VALUE temp_string_length = Qnil;
volatile VALUE return_value = Qnil;

/* Read bytes for string length */
temp_string = rb_funcall(self, id_method_read, 1, param_length_num_bytes);
Expand Down
12 changes: 6 additions & 6 deletions ext/cosmos/ext/crc/crc.c
Expand Up @@ -90,8 +90,8 @@ static unsigned long long bit_reverse_64(unsigned long long value)
*/
static VALUE crc16_calculate(int argc, VALUE* argv, VALUE self)
{
VALUE param_data = Qnil;
VALUE param_seed = Qnil;
volatile VALUE param_data = Qnil;
volatile VALUE param_seed = Qnil;
unsigned char* data = NULL;
unsigned short* table = NULL;
int i = 0;
Expand Down Expand Up @@ -167,8 +167,8 @@ static VALUE crc16_calculate(int argc, VALUE* argv, VALUE self)
*/
static VALUE crc32_calculate(int argc, VALUE* argv, VALUE self)
{
VALUE param_data = Qnil;
VALUE param_seed = Qnil;
volatile VALUE param_data = Qnil;
volatile VALUE param_seed = Qnil;
unsigned char* data = NULL;
unsigned int* table = NULL;
int i = 0;
Expand Down Expand Up @@ -244,8 +244,8 @@ static VALUE crc32_calculate(int argc, VALUE* argv, VALUE self)
*/
static VALUE crc64_calculate(int argc, VALUE* argv, VALUE self)
{
VALUE param_data = Qnil;
VALUE param_seed = Qnil;
volatile VALUE param_data = Qnil;
volatile VALUE param_seed = Qnil;
unsigned char* data = NULL;
unsigned long long* table = NULL;
int i = 0;
Expand Down
40 changes: 20 additions & 20 deletions ext/cosmos/ext/line_graph/line_graph.c
Expand Up @@ -87,14 +87,14 @@ static int cal_code (double x, double y, double xmin, double ymin, double xmax,
/*
* Internal function to perform clipping
*/
static VALUE line_clip_internal(double x0, double y0, double x1, double y1, double xmin, double ymin, double xmax, double ymax, double* result_x0, double* result_y0, double* result_x1, double* result_y1, VALUE* result_clipped0, VALUE* result_clipped1) {
static VALUE line_clip_internal(double x0, double y0, double x1, double y1, double xmin, double ymin, double xmax, double ymax, double* result_x0, double* result_y0, double* result_x1, double* result_y1, volatile VALUE* result_clipped0, volatile VALUE* result_clipped1) {
int code0 = 0;
int code1 = 0;
int codeout = 0;
VALUE accept = Qfalse;
VALUE done = Qfalse;
VALUE clipped0 = Qfalse;
VALUE clipped1 = Qfalse;
volatile VALUE accept = Qfalse;
volatile VALUE done = Qfalse;
volatile VALUE clipped0 = Qfalse;
volatile VALUE clipped1 = Qfalse;
double x = 0.0;
double y = 0.0;

Expand Down Expand Up @@ -174,10 +174,10 @@ static VALUE line_clip_internal(double x0, double y0, double x1, double y1, doub
* If no part of the line is viewable, it returns nil
*/
static VALUE line_clip(VALUE self, VALUE x0, VALUE y0, VALUE x1, VALUE y1, VALUE xmin, VALUE ymin, VALUE xmax, VALUE ymax) {
VALUE result = Qnil;
VALUE result_clipped0 = Qnil;
VALUE result_clipped1 = Qnil;
VALUE return_value = Qnil;
volatile VALUE result = Qnil;
volatile VALUE result_clipped0 = Qnil;
volatile VALUE result_clipped1 = Qnil;
volatile VALUE return_value = Qnil;
double double_x0 = 0.0;
double double_y0 = 0.0;
double double_x1 = 0.0;
Expand Down Expand Up @@ -234,7 +234,7 @@ static long scale_value_to_graph_y_internal (double y, double y_max, double y_sc
* This function converts a y value to a y coordinate on the graph
*/
static VALUE scale_value_to_graph_y(int argc, VALUE* argv, VALUE self) {
VALUE y = Qnil;
volatile VALUE y = Qnil;
ID id_axis = 0;
long long_graph_top_y = 0;
double double_y = 0.0;
Expand Down Expand Up @@ -298,9 +298,9 @@ static VALUE scale_value_to_graph_x(VALUE self, VALUE x) {
* Internal version to draw a line
*/
static void draw_line_internal(VALUE dc, double x1, double y1, double x2, double y2, double x_min, double y_min, double x_max, double y_max, double x_scale, double y_scale, long graph_left_x, long graph_top_y, ID id_axis, VALUE show_line, VALUE point_size, VALUE color) {
VALUE result = Qnil;
VALUE clipped1 = Qnil;
VALUE clipped2 = Qnil;
volatile VALUE result = Qnil;
volatile VALUE clipped1 = Qnil;
volatile VALUE clipped2 = Qnil;
long x1_scaled = 0;
long y1_scaled = 0;
long x2_scaled = 0;
Expand Down Expand Up @@ -390,13 +390,13 @@ static VALUE draw_lines (VALUE self, VALUE dc, VALUE axis) {
long line_length = 0;
long point_index = 0;
ID id_axis = 0;
VALUE lines = Qnil;
VALUE line = Qnil;
VALUE x_values = Qnil;
VALUE y_values = Qnil;
VALUE color = Qnil;
VALUE show_lines = Qnil;
VALUE point_size = Qnil;
volatile VALUE lines = Qnil;
volatile VALUE line = Qnil;
volatile VALUE x_values = Qnil;
volatile VALUE y_values = Qnil;
volatile VALUE color = Qnil;
volatile VALUE show_lines = Qnil;
volatile VALUE point_size = Qnil;
double double_x1 = 0.0;
double double_y1 = 0.0;
double double_x2 = 0.0;
Expand Down
Expand Up @@ -89,7 +89,7 @@ static VALUE my_ary_alloc (VALUE klass)
*/
static VALUE my_ary_new (VALUE klass, long capa)
{
VALUE ary;
volatile VALUE ary;

if (capa < 0)
{
Expand Down Expand Up @@ -126,8 +126,8 @@ static VALUE initialize (VALUE self, VALUE size)
*/
static VALUE my_ary_subseq (VALUE ary, long beg, long len)
{
VALUE klass = Qnil;
VALUE ary2 = Qnil;
volatile VALUE klass = Qnil;
volatile VALUE ary2 = Qnil;

if (beg > RARRAY_LEN(ary))
{
Expand Down Expand Up @@ -162,7 +162,7 @@ static VALUE my_ary_subseq (VALUE ary, long beg, long len)
*/
static VALUE ary_aref(int argc, VALUE *argv, VALUE ary)
{
VALUE arg;
volatile VALUE arg;
long beg, len;

if (argc == 2)
Expand Down
41 changes: 18 additions & 23 deletions ext/cosmos/ext/packet/packet.c
Expand Up @@ -44,24 +44,22 @@ static ID id_ivar_target_name = 0;
static ID id_ivar_packet_name = 0;
static ID id_ivar_description = 0;

static ID id_const_ASCII_8BIT_STRING = 0;

/* Wraps read_item_internal so that it can be called by rb_protect in protected_read_item_internal */
static VALUE wrap_read_item_internal(VALUE args)
{
VALUE *values = (VALUE *)args;
VALUE self = values[0];
VALUE item = values[1];
VALUE buffer = values[2];
volatile VALUE *values = (VALUE *)args;
volatile VALUE self = values[0];
volatile VALUE item = values[1];
volatile VALUE buffer = values[2];
return read_item_internal(self, item, buffer);
}

/* Wraps read_item_internal to catch any exceptions and return nil on exception */
static VALUE protected_read_item_internal(VALUE self, VALUE item, VALUE buffer)
{
int error = 0;
VALUE result = Qnil;
VALUE args[3];
volatile VALUE result = Qnil;
volatile VALUE args[3];

args[0] = self;
args[1] = item;
Expand Down Expand Up @@ -91,10 +89,10 @@ static VALUE protected_read_item_internal(VALUE self, VALUE item, VALUE buffer)
*/
static VALUE identify(VALUE self, VALUE buffer)
{
VALUE id_items = rb_ivar_get(self, id_ivar_id_items);
VALUE item = Qnil;
VALUE id_value = Qnil;
VALUE raw_value = Qnil;
volatile VALUE id_items = rb_ivar_get(self, id_ivar_id_items);
volatile VALUE item = Qnil;
volatile VALUE id_value = Qnil;
volatile VALUE raw_value = Qnil;
long id_items_length = 0;
int index = 0;

Expand Down Expand Up @@ -205,13 +203,13 @@ static VALUE received_count_equals(VALUE self, VALUE received_count) {
* subclass of PacketItem)
*/
static VALUE packet_initialize(int argc, VALUE* argv, VALUE self) {
VALUE target_name = Qnil;
VALUE packet_name = Qnil;
VALUE default_endianness = Qnil;
VALUE description = Qnil;
VALUE buffer = Qnil;
VALUE item_class = Qnil;
VALUE super_args[3] = {Qnil, Qnil, Qnil};
volatile VALUE target_name = Qnil;
volatile VALUE packet_name = Qnil;
volatile VALUE default_endianness = Qnil;
volatile VALUE description = Qnil;
volatile VALUE buffer = Qnil;
volatile VALUE item_class = Qnil;
volatile VALUE super_args[3] = {Qnil, Qnil, Qnil};

switch (argc)
{
Expand Down Expand Up @@ -264,7 +262,7 @@ static VALUE packet_initialize(int argc, VALUE* argv, VALUE self) {
super_args[0] = default_endianness;
super_args[1] = buffer;
super_args[2] = item_class;
rb_call_super(3, super_args);
rb_call_super(3, (VALUE*) super_args);
target_name_equals(self, target_name);
packet_name_equals(self, packet_name);
description_equals(self, description);
Expand Down Expand Up @@ -302,8 +300,6 @@ void Init_packet (void)
id_method_upcase = rb_intern("upcase");
id_method_clone = rb_intern("clone");

id_const_ASCII_8BIT_STRING = rb_intern("ASCII_8BIT_STRING");

id_ivar_id_items = rb_intern("@id_items");
id_ivar_id_value = rb_intern("@id_value");
id_ivar_received_time = rb_intern("@received_time");
Expand All @@ -326,7 +322,6 @@ void Init_packet (void)
id_ivar_description = rb_intern("@description");

cPacket = rb_define_class_under(mCosmos, "Packet", cStructure);
rb_const_set(cPacket, id_const_ASCII_8BIT_STRING, ASCII_8BIT_STRING);
rb_define_method(cPacket, "initialize", packet_initialize, -1);
rb_define_method(cPacket, "identify?", identify, 1);
rb_define_method(cPacket, "packet_name=", packet_name_equals, 1);
Expand Down
2 changes: 1 addition & 1 deletion ext/cosmos/ext/platform/platform.c
Expand Up @@ -69,7 +69,7 @@ static VALUE segfault(VALUE self) {
*/
void Init_platform (void) {
#ifdef _WIN32
VALUE ruby_version = rb_const_get(rb_cObject, rb_intern("RUBY_VERSION"));
volatile VALUE ruby_version = rb_const_get(rb_cObject, rb_intern("RUBY_VERSION"));
char* rversion = RSTRING_PTR(ruby_version);

#if __x86_64__
Expand Down
Expand Up @@ -30,7 +30,7 @@ static ID id_method_to_f = 0;
*/
static VALUE polynomial_conversion_call(VALUE self, VALUE value, VALUE myself, VALUE buffer)
{
VALUE coeffs = Qnil;
volatile VALUE coeffs = Qnil;
long coeffs_length = 0;
int index = 0;
double double_value = 0.0;
Expand Down

0 comments on commit 03a2213

Please sign in to comment.