fix compile against ruby 1.9

This commit is contained in:
Doug MacEachern 2009-03-25 20:10:19 -07:00
parent eb05ff0760
commit 4333771fc3
2 changed files with 19 additions and 3 deletions

View File

@ -61,6 +61,13 @@ osdir = "../../src/os/#{os}"
$CPPFLAGS += ' -I../../include' + ' -I' + osdir $CPPFLAGS += ' -I../../include' + ' -I' + osdir
$CPPFLAGS += ' -U_FILE_OFFSET_BITS' unless is_win32 $CPPFLAGS += ' -U_FILE_OFFSET_BITS' unless is_win32
if RUBY_VERSION > '1.8.4'
$CPPFLAGS += ' -DRB_HAS_RE_ERROR'
end
if RUBY_VERSION >= '1.9.0'
$CPPFLAGS += ' -DRB_RUBY_19'
end
#incase of nfs shared dir... #incase of nfs shared dir...
unless is_win32 unless is_win32
if File.exist?('Makefile') if File.exist?('Makefile')

View File

@ -17,8 +17,12 @@
*/ */
#include <ruby.h> #include <ruby.h>
#include <version.h> #ifdef RB_RUBY_19
#include <regex.h> #include <ruby/re.h>
#else
#include <re.h>
#endif
#include <errno.h> #include <errno.h>
#include "sigar.h" #include "sigar.h"
#include "sigar_fileinfo.h" #include "sigar_fileinfo.h"
@ -37,7 +41,7 @@
#define RSTRING_LEN(s) RSTRING(s)->len #define RSTRING_LEN(s) RSTRING(s)->len
#endif #endif
#if (RUBY_VERSION_MAJOR >= 1) && ((RUBY_VERSION_MINOR == 8) && (RUBY_VERSION_TEENY >= 6)) #ifdef RB_HAS_RE_ERROR
# define RB_REGEX_ERROR rb_eRegexpError # define RB_REGEX_ERROR rb_eRegexpError
#else #else
# define RB_REGEX_ERROR rb_eArgError # define RB_REGEX_ERROR rb_eArgError
@ -53,6 +57,10 @@ static sigar_t *rb_sigar_get(VALUE obj)
static int rbsigar_ptql_re_impl(void *data, static int rbsigar_ptql_re_impl(void *data,
char *haystack, char *needle) char *haystack, char *needle)
{ {
#ifdef RB_RUBY_19
/* XXX no more regex.h */
return 0;
#else
struct re_pattern_buffer *regex; struct re_pattern_buffer *regex;
int len = strlen(haystack); int len = strlen(haystack);
int retval; int retval;
@ -70,6 +78,7 @@ static int rbsigar_ptql_re_impl(void *data,
retval = re_match(regex, haystack, len, 0, NULL); retval = re_match(regex, haystack, len, 0, NULL);
re_free_pattern(regex); re_free_pattern(regex);
return retval > 0; return retval > 0;
#endif
} }
#define sigar_isdigit(c) \ #define sigar_isdigit(c) \