Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

Commit

Permalink
fixes for Ruby 1.9. Thanks, U.Nakamura.
Browse files Browse the repository at this point in the history
  • Loading branch information
shugo committed Jan 23, 2007
1 parent a5113b4 commit a5b9955
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 43 deletions.
16 changes: 15 additions & 1 deletion eruby.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ extern int eruby_noheader;
extern int eruby_sync;
extern VALUE eruby_charset;
extern VALUE eruby_default_charset;
#define ERUBY_CHARSET RSTRING(eruby_charset)->ptr
#define ERUBY_CHARSET RSTRING_PTR(eruby_charset)

const char *eruby_version();
int eruby_parse_options(int argc, char **argv, int *optind);
Expand All @@ -42,6 +42,20 @@ VALUE eruby_compiler_compile_string(VALUE self, VALUE s);
VALUE eruby_load(char *filename, int wrap, int *state);
void eruby_init();

/* for compatibility with ruby 1.9 */
#ifndef RARRAY_LEN
# define RARRAY_LEN(ary) (RARRAY(ary)->len)
#endif
#ifndef RARRAY_PTR
# define RARRAY_PTR(ary) (RARRAY(ary)->ptr)
#endif
#ifndef RSTRING_LEN
# define RSTRING_LEN(str) (RSTRING(str)->len)
#endif
#ifndef RSTRING_PTR
# define RSTRING_PTR(str) (RSTRING(str)->ptr)
#endif

#endif /* ERUBY_H */

/*
Expand Down
14 changes: 7 additions & 7 deletions eruby_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,18 +311,18 @@ static VALUE lex_str_gets(eruby_compiler_t *compiler)
VALUE s = compiler->lex_input;
char *beg, *end, *pend;

if (RSTRING(s)->len == compiler->lex_gets_ptr)
if (RSTRING_LEN(s) == compiler->lex_gets_ptr)
return Qnil;
beg = RSTRING(s)->ptr;
beg = RSTRING_PTR(s);
if (compiler->lex_gets_ptr > 0) {
beg += compiler->lex_gets_ptr;
}
pend = RSTRING(s)->ptr + RSTRING(s)->len;
pend = RSTRING_PTR(s) + RSTRING_LEN(s);
end = beg;
while (end < pend) {
if (*end++ == '\n') break;
}
compiler->lex_gets_ptr = end - RSTRING(s)->ptr;
compiler->lex_gets_ptr = end - RSTRING_PTR(s);
return rb_str_new(beg, end - beg);
}

Expand All @@ -341,8 +341,8 @@ static inline int nextc(eruby_compiler_t *compiler)

if (NIL_P(v)) return EOF;
compiler->sourceline++;
compiler->lex_pbeg = compiler->lex_p = RSTRING(v)->ptr;
compiler->lex_pend = compiler->lex_p + RSTRING(v)->len;
compiler->lex_pbeg = compiler->lex_p = RSTRING_PTR(v);
compiler->lex_pend = compiler->lex_p + RSTRING_LEN(v);
compiler->lex_lastline = v;
}
else {
Expand Down Expand Up @@ -486,7 +486,7 @@ static VALUE eruby_compile(eruby_compiler_t *compiler)
if (c == '!') {
char *p;
char *argv[2];
char *line = RSTRING(compiler->lex_lastline)->ptr;
char *line = RSTRING_PTR(compiler->lex_lastline);

if (line[strlen(line) - 1] == '\n') {
line[strlen(line) - 1] = '\0';
Expand Down
73 changes: 38 additions & 35 deletions eruby_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ static void write_escaping_html(FILE *out, char *str, int len)
static void error_pos(FILE *out, int cgi)
{
char buff[BUFSIZ];
#if RUBY_VERSION_CODE >= 190
ID last_func = rb_frame_this_func();
#else
ID last_func = rb_frame_last_func();
#endif

if (ruby_sourcefile) {
if (last_func) {
Expand All @@ -120,69 +124,69 @@ static void exception_print(FILE *out, int cgi)

errat = rb_funcall(ruby_errinfo, rb_intern("backtrace"), 0);
if (!NIL_P(errat)) {
VALUE mesg = RARRAY(errat)->ptr[0];
VALUE mesg = RARRAY_PTR(errat)[0];

if (NIL_P(mesg)) {
error_pos(out, cgi);
}
else {
if (cgi)
write_escaping_html(out, RSTRING(mesg)->ptr, RSTRING(mesg)->len);
write_escaping_html(out, RSTRING_PTR(mesg), RSTRING_LEN(mesg));
else
fwrite(RSTRING(mesg)->ptr, 1, RSTRING(mesg)->len, out);
fwrite(RSTRING_PTR(mesg), 1, RSTRING_LEN(mesg), out);
}
}

eclass = CLASS_OF(ruby_errinfo);
einfo = rb_obj_as_string(ruby_errinfo);
if (eclass == rb_eRuntimeError && RSTRING(einfo)->len == 0) {
if (eclass == rb_eRuntimeError && RSTRING_LEN(einfo) == 0) {
fprintf(out, ": unhandled exception\n");
}
else {
VALUE epath;

epath = rb_class_path(eclass);
if (RSTRING(einfo)->len == 0) {
if (RSTRING_LEN(einfo) == 0) {
fprintf(out, ": ");
if (cgi)
write_escaping_html(out, RSTRING(epath)->ptr, RSTRING(epath)->len);
write_escaping_html(out, RSTRING_PTR(epath), RSTRING_LEN(epath));
else
fwrite(RSTRING(epath)->ptr, 1, RSTRING(epath)->len, out);
fwrite(RSTRING_PTR(epath), 1, RSTRING_LEN(epath), out);
if (cgi)
fprintf(out, "<br>\n");
else
fprintf(out, "\n");
}
else {
char *tail = 0;
int len = RSTRING(einfo)->len;
int len = RSTRING_LEN(einfo);

if (RSTRING(epath)->ptr[0] == '#') epath = 0;
if ((tail = strchr(RSTRING(einfo)->ptr, '\n')) != NULL) {
len = tail - RSTRING(einfo)->ptr;
if (RSTRING_PTR(epath)[0] == '#') epath = 0;
if ((tail = strchr(RSTRING_PTR(einfo), '\n')) != NULL) {
len = tail - RSTRING_PTR(einfo);
tail++; /* skip newline */
}
fprintf(out, ": ");
if (cgi)
write_escaping_html(out, RSTRING(einfo)->ptr, len);
write_escaping_html(out, RSTRING_PTR(einfo), len);
else
fwrite(RSTRING(einfo)->ptr, 1, len, out);
fwrite(RSTRING_PTR(einfo), 1, len, out);
if (epath) {
fprintf(out, " (");
if (cgi)
write_escaping_html(out, RSTRING(epath)->ptr, RSTRING(epath)->len);
write_escaping_html(out, RSTRING_PTR(epath), RSTRING_LEN(epath));
else
fwrite(RSTRING(epath)->ptr, 1, RSTRING(epath)->len, out);
fwrite(RSTRING_PTR(epath), 1, RSTRING_LEN(epath), out);
if (cgi)
fprintf(out, ")<br>\n");
else
fprintf(out, ")\n");
}
if (tail) {
if (cgi)
write_escaping_html(out, tail, RSTRING(einfo)->len - len - 1);
write_escaping_html(out, tail, RSTRING_LEN(einfo) - len - 1);
else
fwrite(tail, 1, RSTRING(einfo)->len - len - 1, out);
fwrite(tail, 1, RSTRING_LEN(einfo) - len - 1, out);
if (cgi)
fprintf(out, "<br>\n");
else
Expand All @@ -201,38 +205,38 @@ static void exception_print(FILE *out, int cgi)

rb_ary_pop(errat);
ep = RARRAY(errat);
for (i=1; i<ep->len; i++) {
if (TYPE(ep->ptr[i]) == T_STRING) {
for (i=1; i<RARRAY_LEN(ep); i++) {
if (TYPE(RARRAY_PTR(ep)[i]) == T_STRING) {
if (cgi) {
fprintf(out, "<div class=\"backtrace\">from ");
write_escaping_html(out,
RSTRING(ep->ptr[i])->ptr,
RSTRING(ep->ptr[i])->len);
RSTRING_PTR(RARRAY_PTR(ep)[i]),
RSTRING_LEN(RARRAY_PTR(ep)[i]));
}
else {
fprintf(out, " from ");
fwrite(RSTRING(ep->ptr[i])->ptr, 1,
RSTRING(ep->ptr[i])->len, out);
fwrite(RSTRING_PTR(RARRAY_PTR(ep)[i]), 1,
RSTRING_LEN(RARRAY_PTR(ep)[i]), out);
}
if (cgi)
fprintf(out, "<br></div>\n");
else
fprintf(out, "\n");
}
if (i == TRACE_HEAD && ep->len > TRACE_MAX) {
if (i == TRACE_HEAD && RARRAY_LEN(ep) > TRACE_MAX) {
char buff[BUFSIZ];
if (cgi)
snprintf(buff, BUFSIZ,
"<div class=\"backtrace\">... %ld levels...\n",
ep->len - TRACE_HEAD - TRACE_TAIL);
RARRAY_LEN(ep) - TRACE_HEAD - TRACE_TAIL);
else
snprintf(buff, BUFSIZ, " ... %ld levels...<br></div>\n",
ep->len - TRACE_HEAD - TRACE_TAIL);
RARRAY_LEN(ep) - TRACE_HEAD - TRACE_TAIL);
if (cgi)
write_escaping_html(out, buff, strlen(buff));
else
fputs(buff, out);
i = ep->len - TRACE_TAIL;
i = RARRAY_LEN(ep) - TRACE_TAIL;
}
}
}
Expand All @@ -252,10 +256,10 @@ static void print_generated_code(FILE *out, VALUE code, int cgi)
}

if (cgi) {
write_escaping_html(out, RSTRING(code)->ptr, RSTRING(code)->len);
write_escaping_html(out, RSTRING_PTR(code), RSTRING_LEN(code));
}
else {
fwrite(RSTRING(code)->ptr, 1, RSTRING(code)->len, out);
fwrite(RSTRING_PTR(code), 1, RSTRING_LEN(code), out);
}
if (cgi) {
fprintf(out, "</code></pre>\n");
Expand Down Expand Up @@ -395,15 +399,14 @@ static void error_print(FILE *out, int state, int cgi, int mode, VALUE code)
static VALUE defout_write(VALUE self, VALUE str)
{
str = rb_obj_as_string(str);
rb_str_cat(self, RSTRING(str)->ptr, RSTRING(str)->len);
rb_str_cat(self, RSTRING_PTR(str), RSTRING_LEN(str));
return Qnil;
}

static VALUE defout_cancel(VALUE self)
{
if (RSTRING(self)->len == 0) return Qnil;
RSTRING(self)->len = 0;
RSTRING(self)->ptr[0] = '\0';
if (RSTRING_LEN(self) == 0) return Qnil;
rb_str_resize(self, 0);
return Qnil;
}

Expand Down Expand Up @@ -586,8 +589,8 @@ static void flush_buffer()
int nout;

#if RUBY_VERSION_CODE >= 180
out = RSTRING(rb_stdout)->ptr;
nout = RSTRING(rb_stdout)->len;
out = RSTRING_PTR(rb_stdout);
nout = RSTRING_LEN(rb_stdout);
#else
out = RSTRING(rb_defout)->ptr;
nout = RSTRING(rb_defout)->len;
Expand Down

0 comments on commit a5b9955

Please sign in to comment.