Skip to content

Commit

Permalink
worked around compile issues with 1.9.3-p0 on CentOS 5.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Ohler committed Apr 13, 2012
1 parent 37e9580 commit ae5fd3d
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -8,5 +8,6 @@ Makefile
*.bundle
.rbenv-version
*.rbc
.rbx
doc
.yardoc
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -24,9 +24,9 @@ A fast JSON parser and Object marshaller as a Ruby gem.

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

### Release 1.2.3
### Release 1.2.4

- Fixed compile error for the latest RBX on Travis.
- Removed all use of math.h to get around CentOS 5.4 compile problem.

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

Expand Down
32 changes: 12 additions & 20 deletions ext/oj/dump.c
Expand Up @@ -34,7 +34,6 @@
#include <time.h>
#include <stdio.h>
#include <string.h>
#include <math.h>

#include "oj.h"
#include "cache8.h"
Expand All @@ -43,6 +42,8 @@
#define rb_eEncodingError rb_eException
#endif

#define DBL_INF 1.e500

typedef unsigned long ulong;

typedef struct _Out {
Expand Down Expand Up @@ -391,39 +392,30 @@ dump_bignum(VALUE obj, Out out) {
*out->cur = '\0';
}

// Removed dependencies on math due to problems with CentOS 5.4.
static void
dump_float(VALUE obj, Out out) {
char buf[64];
char *b;
double d = rb_num2dbl(obj);
int cnt;

switch (fpclassify(d)) {
case FP_NAN:
printf("*** nan\n");
cnt = sprintf(buf, "%0.16g", d); // used sprintf due to bug in snprintf
break;
case FP_INFINITE:
b = buf;
cnt = 8;
if (d < 0.0) {
*b++ = '-';
cnt++;
}
strcpy(b, "Infinity");
break;
case FP_ZERO:
if (0.0 == d) {
b = buf;
*b++ = '0';
*b++ = '.';
*b++ = '0';
*b++ = '\0';
cnt = 3;
break;
default:
} else if (DBL_INF == d) {
strcpy(buf, "Infinity");
cnt = 8;
} else if (-DBL_INF == d) {
strcpy(buf, "-Infinity");
cnt = 9;
} else {
cnt = sprintf(buf, "%0.16g", d); // used sprintf due to bug in snprintf
break;
}
}
if (out->end - out->cur <= (long)cnt) {
grow(out, cnt);
}
Expand Down
11 changes: 11 additions & 0 deletions ext/oj/extconf.rb
Expand Up @@ -24,6 +24,15 @@
'HAS_PROC_WITH_BLOCK' => ('ruby' == type && '1' == version[0] && '9' == version[1]) ? 1 : 0,
'HAS_TOP_LEVEL_ST_H' => ('ree' == type || ('ruby' == type && '1' == version[0] && '8' == version[1])) ? 1 : 0,
}
# This is a monster hack to get around issues with 1.9.3-p0 on CentOS 5.4. SO
# some reason math.h and string.h contents are not processed. Might be a
# missing #define. This is the quick and easy way around it.
if 'x86_64-linux' == RUBY_PLATFORM && '1.9.3' == RUBY_VERSION && '2011-10-30' == RUBY_RELEASE_DATE
begin
dflags['NEEDS_STPCPY'] = nil if `more /etc/issue`.include?('CentOS release 5.4')
rescue Exception => e
end
end

dflags.each do |k,v|
if v.nil?
Expand All @@ -35,3 +44,5 @@
$CPPFLAGS += ' -Wall'
#puts "*** $CPPFLAGS: #{$CPPFLAGS}"
create_makefile(extension_name)

%x{make clean}
11 changes: 11 additions & 0 deletions ext/oj/fast.c
Expand Up @@ -112,6 +112,17 @@ static VALUE doc_size(VALUE self);

VALUE oj_doc_class = 0;

// This is only for CentOS 5.4 with Ruby 1.9.3-p0.
#ifdef NEEDS_STPCPY
char *stpcpy(char *dest, const char *src) {
size_t cnt = strlen(src);

strcpy(dest, src);

return dest + cnt;
}
#endif

inline static void
next_non_white(ParseInfo pi) {
for (; 1; pi->s++) {
Expand Down
2 changes: 1 addition & 1 deletion lib/oj/version.rb
@@ -1,5 +1,5 @@

module Oj
# Current version of the module.
VERSION = '1.2.3'
VERSION = '1.2.4'
end
8 changes: 6 additions & 2 deletions notes
Expand Up @@ -5,6 +5,10 @@

- next

- optimize read_hex in load.c
- add options for path in fetch
- wild cards

- setup travis to run tests
- does not load the oj gem in some cases

Expand All @@ -17,8 +21,8 @@
- object_end
- array_start
- array_end
- value
- key
- value - provide accessor call or object to get value
- key - provide accessor call or object to get value

- default callbacks use straight C and create Hash or Object according to mode
- callback object
Expand Down

0 comments on commit ae5fd3d

Please sign in to comment.