Skip to content

Commit

Permalink
Stupid typechecking that should have been doing 6 months ago.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyler McMullen committed Nov 23, 2009
1 parent f61a370 commit 720586e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
16 changes: 16 additions & 0 deletions ext/trie/trie.c
Expand Up @@ -28,6 +28,8 @@ static VALUE rb_trie_alloc(VALUE klass) {
*
*/
static VALUE rb_trie_has_key(VALUE self, VALUE key) {
StringValue(key);

Trie *trie;
Data_Get_Struct(self, Trie, trie);

Expand All @@ -46,6 +48,8 @@ static VALUE rb_trie_has_key(VALUE self, VALUE key) {
*
*/
static VALUE rb_trie_get(VALUE self, VALUE key) {
StringValue(key);

Trie *trie;
Data_Get_Struct(self, Trie, trie);

Expand Down Expand Up @@ -74,6 +78,8 @@ static VALUE rb_trie_add(VALUE self, VALUE args) {

VALUE key;
key = RARRAY(args)->ptr[0];
StringValue(key);

TrieData value = size == 2 ? RARRAY(args)->ptr[1] : TRIE_DATA_ERROR;

if(trie_store(trie, (TrieChar*)RSTRING(key)->ptr, value))
Expand All @@ -90,6 +96,8 @@ static VALUE rb_trie_add(VALUE self, VALUE args) {
*
*/
static VALUE rb_trie_delete(VALUE self, VALUE key) {
StringValue(key);

Trie *trie;
Data_Get_Struct(self, Trie, trie);

Expand Down Expand Up @@ -134,6 +142,8 @@ static VALUE rb_trie_children(VALUE self, VALUE prefix) {
if(NIL_P(prefix))
return rb_ary_new();

StringValue(prefix);

Trie *trie;
Data_Get_Struct(self, Trie, trie);

Expand Down Expand Up @@ -210,6 +220,8 @@ static VALUE rb_trie_children_with_values(VALUE self, VALUE prefix) {
if(NIL_P(prefix))
return rb_ary_new();

StringValue(prefix);

Trie *trie;
Data_Get_Struct(self, Trie, trie);

Expand Down Expand Up @@ -330,6 +342,8 @@ static VALUE rb_trie_node_get_full_state(VALUE self) {
*
*/
static VALUE rb_trie_node_walk_bang(VALUE self, VALUE rchar) {
StringValue(rchar);

TrieState *state;
Data_Get_Struct(self, TrieState, state);

Expand Down Expand Up @@ -357,6 +371,8 @@ static VALUE rb_trie_node_walk_bang(VALUE self, VALUE rchar) {
*
*/
static VALUE rb_trie_node_walk(VALUE self, VALUE rchar) {
StringValue(rchar);

VALUE new_node = rb_funcall(self, rb_intern("dup"), 0);

TrieState *state;
Expand Down
2 changes: 1 addition & 1 deletion lib/trie.rb
@@ -1 +1 @@
require File.dirname(__FILE__) + '/../ext/trie'
#require File.dirname(__FILE__) + '/../ext/trie'
4 changes: 3 additions & 1 deletion spec/trie_spec.rb
@@ -1,4 +1,6 @@
require File.dirname(__FILE__) + '/../ext/trie/trie'
#require File.dirname(__FILE__) + '/../ext/trie/trie'
require 'rubygems'
require 'trie'

describe Trie do
before :each do
Expand Down

0 comments on commit 720586e

Please sign in to comment.