Skip to content

Commit

Permalink
preparing for next release
Browse files Browse the repository at this point in the history
  • Loading branch information
ohler55 committed Apr 4, 2012
1 parent 5a7a659 commit 6679570
Show file tree
Hide file tree
Showing 25 changed files with 268 additions and 470 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ ox-*.gem
Makefile
*.bundle
.rbenv-version
*.rbc
.rbx
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,27 @@ A fast XML parser and Object marshaller as a Ruby gem.

## <a name="release">Release Notes</a>

### Release 1.5.4
### Release 1.5.5

- Worked around bug in rb_protect in ruby 1.9.x and OS X 10.6.8 that caused ignored exceptions to be raised on program exit.
- Fixed bug in special character encoding to remove the double ampersands.

- Fixed a parse bug that did not accept &nn; sequences.
- Fixed bug that did not dump XSD times correctly.

- Fixed bug in the prolog parsing.

- Improved the speed of time parsing and dumping.

- Increased the time resolution for Rubies that support nanoseconds.

- Cleaned up compile flags.

- All tests pass with all supported Rubies.

- Added value() callback to the SAX parser which allows deferred value parsing and typing to improve performance.

- Added attr_value() callback to the SAX parser which allows deferred value parsing and typing to improve performance with attributes.

- Added an example that demonstrates using several parsing techniques with different parsers. The example is in the test/weather directory.

## <a name="description">Description</a>

Expand Down
28 changes: 28 additions & 0 deletions build_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/sh

for ruby in \
1.8.7-p358\
1.9.2-p290\
1.9.3-p125\
jruby-1.6.7\
rbx-1.2.4\
rbx-2.0.0-dev\
ree-1.8.7-2012.02
do
echo "\n********************************************************************************"
echo "Building $ruby\n"
cd ext/ox
rbenv local $ruby
ruby extconf.rb
make clean
make

echo "\nRunning tests for $ruby"
cd ../../test
rbenv local $ruby
./tests.rb
./sax_test.rb
cd ..

echo "\n"
done
85 changes: 30 additions & 55 deletions ext/ox/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,6 @@
#include <stdio.h>
#include <string.h>

#include "ruby.h"
#ifdef HAVE_RUBY_ENCODING_H
#include "ruby/st.h"
#else
#include "st.h"
#endif
#include "base64.h"
#include "cache8.h"
#include "ox.h"
Expand Down Expand Up @@ -298,7 +292,7 @@ dump_start(Out out, Element e) {
}
if (0 < e->id) {
char buf[32];
char *end = buf + sizeof(buf);
char *end = buf + sizeof(buf) - 1;
const char *s = ulong2str(e->id, end);

fill_attr(out, 'i', s, end - s);
Expand Down Expand Up @@ -380,7 +374,6 @@ dump_str_value(Out out, const char *value, size_t size) {
*out->cur++ = 't';
break;
default:
*out->cur++ = '&';
*out->cur++ = '#';
*out->cur++ = 'x';
*out->cur++ = '0';
Expand Down Expand Up @@ -429,16 +422,26 @@ dump_num(Out out, VALUE obj) {

static void
dump_time_thin(Out out, VALUE obj) {
char buf[64];
char *b = buf + sizeof(buf) - 1;
time_t sec = NUM2LONG(rb_funcall2(obj, ox_tv_sec_id, 0, 0));
long usec = NUM2LONG(rb_funcall2(obj, ox_tv_usec_id, 0, 0));
char *dot = b - 7;
long size;
char buf[64];
char *b = buf + sizeof(buf) - 1;
#if HAS_RB_TIME_TIMESPEC
struct timespec ts = rb_time_timespec(obj);
time_t sec = ts.tv_sec;
long nsec = ts.tv_nsec;
#else
time_t sec = NUM2LONG(rb_funcall2(obj, ox_tv_sec_id, 0, 0));
#if HAS_NANO_TIME
long nsec = NUM2LONG(rb_funcall2(obj, ox_tv_nsec_id, 0, 0));
#else
long nsec = NUM2LONG(rb_funcall2(obj, ox_tv_usec_id, 0, 0)) * 1000;
#endif
#endif
char *dot = b - 10;
long size;

*b-- = '\0';
for (; dot < b; b--, usec /= 10) {
*b = '0' + (usec % 10);
for (; dot < b; b--, nsec /= 10) {
*b = '0' + (nsec % 10);
}
*b-- = '.';
for (; 0 < sec; b--, sec /= 10) {
Expand Down Expand Up @@ -477,34 +480,6 @@ dump_date(Out out, VALUE obj) {
out->cur += size;
}

#if 0
static void
dump_time_xsd(Out out, VALUE obj) {
struct tm *tm;
time_t sec = NUM2LONG(rb_funcall2(obj, ox_tv_sec_id, 0, 0));
long usec = NUM2LONG(rb_funcall2(obj, ox_tv_usec_id, 0, 0));
int tzhour, tzmin;
char tzsign = '+';

if (out->end - out->cur <= 33) {
grow(out, 33);
}
// 2010-07-09T10:47:45.895826+09:00
tm = localtime(&sec);
if (0 > tm->tm_gmtoff) {
tzsign = '-';
tzhour = (int)(tm->tm_gmtoff / -3600);
tzmin = (int)(tm->tm_gmtoff / -60) - (tzhour * 60);
} else {
tzhour = (int)(tm->tm_gmtoff / 3600);
tzmin = (int)(tm->tm_gmtoff / 60) - (tzhour * 60);
}
out->cur += sprintf(out->cur, "%04d-%02d-%02dT%02d:%02d:%02d.%06ld%c%02d:%02d",
tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
tm->tm_hour, tm->tm_min, tm->tm_sec, usec,
tzsign, tzhour, tzmin);
}
#else
static void
dump_time_xsd(Out out, VALUE obj) {
struct tm *tm;
Expand Down Expand Up @@ -542,7 +517,7 @@ dump_time_xsd(Out out, VALUE obj) {
tm->tm_hour, tm->tm_min, tm->tm_sec, nsec / 1000,
tzsign, tzhour, tzmin);
}
#endif

static void
dump_first_obj(VALUE obj, Out out) {
char buf[128];
Expand Down Expand Up @@ -660,7 +635,7 @@ dump_obj(ID aid, VALUE obj, unsigned int depth, Out out) {
break;
case T_FLOAT:
e.type = FloatCode;
cnt = sprintf(value_buf, "%0.16g", RFLOAT_VALUE(obj)); // used sprintf due to bug in snprintf
cnt = sprintf(value_buf, "%0.16g", rb_num2dbl(obj)); // used sprintf due to bug in snprintf
out->w_start(out, &e);
dump_value(out, value_buf, cnt);
e.indent = -1;
Expand Down Expand Up @@ -768,11 +743,7 @@ dump_obj(ID aid, VALUE obj, unsigned int depth, Out out) {
}
case T_STRUCT:
{
#ifdef NO_RSTRUCT
e.type = NilClassCode;
e.closed = 1;
out->w_start(out, &e);
#else
#if HAS_RSTRUCT
VALUE clas;

if (0 != out->circ_cache && check_circular(out, obj, &e)) {
Expand Down Expand Up @@ -807,6 +778,10 @@ dump_obj(ID aid, VALUE obj, unsigned int depth, Out out) {
}
out->w_end(out, &e);
}
#else
e.type = NilClassCode;
e.closed = 1;
out->w_start(out, &e);
#endif
break;
}
Expand All @@ -832,7 +807,7 @@ dump_obj(ID aid, VALUE obj, unsigned int depth, Out out) {
out->w_end(out, &e);
} else { // Object
// use encoding as the indicator for Ruby 1.8.7 or 1.9.x
#ifdef HAVE_RUBY_ENCODING_H
#if HAS_ENCODING_SUPPORT
e.type = (Qtrue == rb_obj_is_kind_of(obj, rb_eException)) ? ExceptionCode : ObjectCode;
cnt = (int)rb_ivar_count(obj);
e.closed = (0 >= cnt);
Expand All @@ -846,10 +821,10 @@ dump_obj(ID aid, VALUE obj, unsigned int depth, Out out) {
out->w_end(out, &e);
}
#else
#if (defined JRUBY || defined RUBINIUS)
VALUE vars = rb_funcall2(obj, rb_intern("instance_variables"), 0, 0);
#else
#if HAS_IVAR_HELPERS
VALUE vars = rb_obj_instance_variables(obj);
#else
VALUE vars = rb_funcall2(obj, rb_intern("instance_variables"), 0, 0);
#endif
e.type = (Qtrue == rb_obj_is_kind_of(obj, rb_eException)) ? ExceptionCode : ObjectCode;
cnt = (int)RARRAY_LEN(vars);
Expand Down
18 changes: 9 additions & 9 deletions ext/ox/gen_load.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ create_prolog_doc(PInfo pi, const char *target, Attr attrs) {
doc = rb_obj_alloc(ox_document_clas);
ah = rb_hash_new();
for (; 0 != attrs->name; attrs++) {
#ifdef HAVE_RUBY_ENCODING_H
#if HAS_ENCODING_SUPPORT
if (0 != pi->encoding) {
VALUE rstr = rb_str_new2(attrs->name);

Expand All @@ -127,7 +127,7 @@ create_prolog_doc(PInfo pi, const char *target, Attr attrs) {
sym = ID2SYM(rb_intern(attrs->name));
#endif
rb_hash_aset(ah, sym, rb_str_new2(attrs->value));
#ifdef HAVE_RUBY_ENCODING_H
#if HAS_ENCODING_SUPPORT
if (0 == strcmp("encoding", attrs->name)) {
pi->encoding = rb_enc_find(attrs->value);
}
Expand Down Expand Up @@ -198,7 +198,7 @@ add_doctype(PInfo pi, const char *docType) {
VALUE n = rb_obj_alloc(ox_doctype_clas);
VALUE s = rb_str_new2(docType);

#ifdef HAVE_RUBY_ENCODING_H
#if HAS_ENCODING_SUPPORT
if (0 != pi->encoding) {
rb_enc_associate(s, pi->encoding);
}
Expand All @@ -215,7 +215,7 @@ add_comment(PInfo pi, const char *comment) {
VALUE n = rb_obj_alloc(ox_comment_clas);
VALUE s = rb_str_new2(comment);

#ifdef HAVE_RUBY_ENCODING_H
#if HAS_ENCODING_SUPPORT
if (0 != pi->encoding) {
rb_enc_associate(s, pi->encoding);
}
Expand All @@ -232,7 +232,7 @@ add_cdata(PInfo pi, const char *cdata, size_t len) {
VALUE n = rb_obj_alloc(ox_cdata_clas);
VALUE s = rb_str_new2(cdata);

#ifdef HAVE_RUBY_ENCODING_H
#if HAS_ENCODING_SUPPORT
if (0 != pi->encoding) {
rb_enc_associate(s, pi->encoding);
}
Expand All @@ -248,7 +248,7 @@ static void
add_text(PInfo pi, char *text, int closed) {
VALUE s = rb_str_new2(text);

#ifdef HAVE_RUBY_ENCODING_H
#if HAS_ENCODING_SUPPORT
if (0 != pi->encoding) {
rb_enc_associate(s, pi->encoding);
}
Expand All @@ -264,7 +264,7 @@ add_element(PInfo pi, const char *ename, Attr attrs, int hasChildren) {
VALUE e;
VALUE s = rb_str_new2(ename);

#ifdef HAVE_RUBY_ENCODING_H
#if HAS_ENCODING_SUPPORT
if (0 != pi->encoding) {
rb_enc_associate(s, pi->encoding);
}
Expand All @@ -279,7 +279,7 @@ add_element(PInfo pi, const char *ename, Attr attrs, int hasChildren) {
VALUE *slot;

if (Qundef == (sym = ox_cache_get(ox_symbol_cache, attrs->name, &slot))) {
#ifdef HAVE_RUBY_ENCODING_H
#if HAS_ENCODING_SUPPORT
if (0 != pi->encoding) {
VALUE rstr = rb_str_new2(attrs->name);

Expand All @@ -294,7 +294,7 @@ add_element(PInfo pi, const char *ename, Attr attrs, int hasChildren) {
*slot = sym;
}
s = rb_str_new2(attrs->value);
#ifdef HAVE_RUBY_ENCODING_H
#if HAS_ENCODING_SUPPORT
if (0 != pi->encoding) {
rb_enc_associate(s, pi->encoding);
}
Expand Down
Loading

0 comments on commit 6679570

Please sign in to comment.