init memory to 0

This commit is contained in:
Kyle Maxwell 2009-02-26 12:31:19 -08:00
parent 1281cf1d8d
commit 8d4d34a305
4 changed files with 15 additions and 1 deletions

View File

@ -16,5 +16,11 @@ void * dex_alloc(int size) {
obstack_init(&dex_obstack); obstack_init(&dex_obstack);
dex_obstack_initialized = true; dex_obstack_initialized = true;
} }
return obstack_alloc(&dex_obstack, size); void * mem = obstack_alloc(&dex_obstack, size);
void * ptr = mem;
for(int i = 0; i < size; i++)
{
*(char *)(mem + i) = '\0';
}
return mem;
} }

View File

@ -1,4 +1,5 @@
#include "ruby.h" #include "ruby.h"
#include <stdio.h>
#include <libxslt/xslt.h> #include <libxslt/xslt.h>
#include <libexslt/exslt.h> #include <libexslt/exslt.h>
#include <libxslt/xsltInternals.h> #include <libxslt/xsltInternals.h>
@ -35,6 +36,7 @@ VALUE _new(VALUE self, VALUE dex, VALUE incl){
dex_free(ptr); dex_free(ptr);
return Qnil; return Qnil;
} }
return Data_Wrap_Struct(c_dex, 0, dex_free, ptr); return Data_Wrap_Struct(c_dex, 0, dex_free, ptr);
} }

View File

@ -10,6 +10,7 @@ class Dexterous
end end
@@mutex ||= Mutex.new @@mutex ||= Mutex.new
@@mutex.synchronize do @@mutex.synchronize do
puts dex
@dex = CDexter.new(dex, incl) @dex = CDexter.new(dex, incl)
end end
end end

View File

@ -12,6 +12,11 @@ class TestDexterous < Test::Unit::TestCase
assert_equal "/c/sf/shopping", out["categories"][0]["href"] assert_equal "/c/sf/shopping", out["categories"][0]["href"]
end end
def test_yelp_xml
@dex = Dexterous.new(File.read(File.dirname(__FILE__) + "/../../test/yelp-home.dex"))
out = @dex.parse(:file => File.dirname(__FILE__) + "/../../test/yelp-home.html", :output => :xml)
end
def test_simple def test_simple
@dex = Dexterous.new("hi" => "h1") @dex = Dexterous.new("hi" => "h1")
assert_equal({"hi" => "Nick's Crispy Tacos"}, @dex.parse(:file => @file)) assert_equal({"hi" => "Nick's Crispy Tacos"}, @dex.parse(:file => @file))