Skip to content

Commit

Permalink
Mkmf have (#247)
Browse files Browse the repository at this point in the history
* Use mkmf macros in extconf.rb

* Put back an else

* builder.c fix

* use RUBY_INTEGER_UNIFICATION
  • Loading branch information
ohler55 authored Sep 3, 2020
1 parent 0db3f9c commit 337b082
Show file tree
Hide file tree
Showing 14 changed files with 106 additions and 404 deletions.
6 changes: 5 additions & 1 deletion ext/ox/builder.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
#include <stdio.h>
#include <string.h>

#include "ruby.h"
#if HAVE_RB_ENC_ASSOCIATE
#include "ruby/encoding.h"
#endif
#include "ox.h"
#include "buf.h"
#include "err.h"
Expand Down Expand Up @@ -331,7 +335,7 @@ to_s(Builder b) {
rstr = rb_str_new(b->buf.head, buf_len(&b->buf));

if ('\0' != *b->encoding) {
#if HAS_ENCODING_SUPPORT
#if HAVE_RB_ENC_ASSOCIATE
rb_enc_associate(rstr, rb_enc_find(b->encoding));
#endif
}
Expand Down
24 changes: 6 additions & 18 deletions ext/ox/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -455,17 +455,14 @@ static void
dump_time_thin(Out out, VALUE obj) {
char buf[64];
char *b = buf + sizeof(buf) - 1;
#if HAS_RB_TIME_TIMESPEC
#if HAVE_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
//long nsec = NUM2LONG(rb_funcall2(obj, ox_tv_usec_id, 0, 0)) * 1000;
#endif
char *dot = b - 10;
long size;
Expand Down Expand Up @@ -520,11 +517,8 @@ dump_time_xsd(Out out, VALUE obj) {
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
//long nsec = NUM2LONG(rb_funcall2(obj, ox_tv_usec_id, 0, 0)) * 1000;
#endif
int tzhour, tzmin;
char tzsign = '+';
Expand Down Expand Up @@ -809,7 +803,7 @@ dump_obj(ID aid, VALUE obj, int depth, Out out) {
}
case T_STRUCT:
{
#if HAS_RSTRUCT
#ifdef RSTRUCT_GET
VALUE clas;

if (0 != out->circ_cache && check_circular(out, obj, &e)) {
Expand All @@ -831,7 +825,7 @@ dump_obj(ID aid, VALUE obj, int depth, Out out) {
} else {
char num_buf[16];
int d2 = depth + 1;
#if UNIFY_FIXNUM_AND_BIGNUM
#ifdef RUBY_INTEGER_UNIFICATION
long i;
long cnt = NUM2LONG(rb_struct_size(obj));
#else // UNIFY_FIXNUM_AND_INTEGER
Expand Down Expand Up @@ -877,7 +871,7 @@ dump_obj(ID aid, VALUE obj, int depth, Out out) {
dump_gen_element(obj, depth + 1, out);
out->w_end(out, &e);
} else { /* Object */
#if HAS_IVAR_HELPERS
#if HAVE_RB_IVAR_FOREACH
e.type = (Qtrue == rb_obj_is_kind_of(obj, rb_eException)) ? ExceptionCode : ObjectCode;
cnt = (int)rb_ivar_count(obj);
e.closed = (0 >= cnt);
Expand Down Expand Up @@ -1209,11 +1203,6 @@ dump_gen_attr(VALUE key, VALUE value, VALUE ov) {
size_t klen;
size_t size;

#if HAS_PRIVATE_ENCODING
// There seems to be a bug in jruby for converting symbols to strings and preserving the encoding. This is a work
// around.
ks = rb_str_ptr(rb_String(key));
#else
switch (rb_type(key)) {
case T_SYMBOL:
ks = rb_id2name(SYM2ID(key));
Expand All @@ -1226,7 +1215,6 @@ dump_gen_attr(VALUE key, VALUE value, VALUE ov) {
ks = StringValuePtr(key);
break;
}
#endif
klen = strlen(ks);
value = rb_String(value);
size = 4 + klen + RSTRING_LEN(value);
Expand Down
46 changes: 12 additions & 34 deletions ext/ox/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
parts = RUBY_DESCRIPTION.split(' ')
type = parts[0].downcase()
type = 'ree' if 'ruby' == type && RUBY_DESCRIPTION.include?('Ruby Enterprise Edition')
is_windows = RbConfig::CONFIG['host_os'] =~ /(mingw|mswin)/
platform = RUBY_PLATFORM
version = RUBY_VERSION.split('.')
puts ">>>>> Creating Makefile for #{type} version #{RUBY_VERSION} on #{platform} <<<<<"
Expand All @@ -18,41 +17,8 @@
'RUBY_VERSION_MAJOR' => version[0],
'RUBY_VERSION_MINOR' => version[1],
'RUBY_VERSION_MICRO' => version[2],
'HAS_RB_TIME_TIMESPEC' => ('ruby' == type && ('1.9.3' == RUBY_VERSION)) ? 1 : 0,
#'HAS_RB_TIME_TIMESPEC' => ('ruby' == type && ('1.9.3' == RUBY_VERSION || '2' <= version[0])) ? 1 : 0,
'HAS_TM_GMTOFF' => ('ruby' == type && (('1' == version[0] && '9' == version[1]) || '2' <= version[0]) &&
!(platform.include?('cygwin') || platform.include?('solaris') || platform.include?('linux') || RUBY_PLATFORM =~ /(win|w)32$/)) ? 1 : 0,
'HAS_ENCODING_SUPPORT' => (('ruby' == type || 'rubinius' == type || 'macruby' == type) &&
(('1' == version[0] && '9' == version[1]) || '2' <= version[0])) ? 1 : 0,
'HAS_ONIG' => (('ruby' == type || 'jruby' == type || 'rubinius' == type) &&
(('1' == version[0] && '9' == version[1]) || '2' <= version[0])) ? 1 : 0,
'HAS_PRIVATE_ENCODING' => ('jruby' == type && '1' == version[0] && '9' == version[1]) ? 1 : 0,
'HAS_NANO_TIME' => ('ruby' == type && ('1' == version[0] && '9' == version[1]) || '2' <= version[0]) ? 1 : 0,
'HAS_RSTRUCT' => ('ruby' == type || 'ree' == type) ? 1 : 0,
'HAS_IVAR_HELPERS' => ('ruby' == type && !is_windows && (('1' == version[0] && '9' == version[1]) || '2' <= version[0])) ? 1 : 0,
'HAS_PROC_WITH_BLOCK' => ('ruby' == type && ('1' == version[0] && '9' == version[1]) || '2' <= version[0]) ? 1 : 0,
'HAS_GC_GUARD' => ('jruby' != type && 'rubinius' != type) ? 1 : 0,
'HAS_BIGDECIMAL' => ('jruby' != type) ? 1 : 0,
'HAS_TOP_LEVEL_ST_H' => ('ree' == type || ('ruby' == type && '1' == version[0] && '8' == version[1])) ? 1 : 0,
'NEEDS_UIO' => (RUBY_PLATFORM =~ /(win|w)32$/) ? 0 : 1,
'HAS_DATA_OBJECT_WRAP' => ('ruby' == type && '2' == version[0] && '3' <= version[1]) ? 1 : 0,
'UNIFY_FIXNUM_AND_BIGNUM' => ('ruby' == type && '2' == version[0] && '4' <= version[1]) ? 1 : 0,
}

if RUBY_PLATFORM =~ /(win|w)32$/ || RUBY_PLATFORM =~ /solaris2\.10/
dflags['NEEDS_STPCPY'] = nil
end

if ['i386-darwin10.0.0', 'x86_64-darwin10.8.0'].include? RUBY_PLATFORM
dflags['NEEDS_STPCPY'] = nil
dflags['HAS_IVAR_HELPERS'] = 0 if ('ruby' == type && '1.9.1' == RUBY_VERSION)
elsif '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
end
end

dflags.each do |k,v|
if v.nil?
$CPPFLAGS += " -D#{k}"
Expand All @@ -66,6 +32,18 @@
CONFIG['warnflags'].slice!(/ -Wdeclaration-after-statement/)
CONFIG['warnflags'].slice!(/ -Wmissing-noreturn/)

have_func('rb_time_timespec')
have_func('rb_enc_associate')
have_func('rb_enc_find')
have_func('rb_struct_alloc_noinit')
have_func('rb_obj_encoding')
have_func('rb_ivar_foreach')

have_header('ruby/st.h')
have_header('sys/uio.h')

have_struct_member('struct tm', 'tm_gmtoff')

create_makefile(extension_name)

%x{make clean}
Loading

0 comments on commit 337b082

Please sign in to comment.