Skip to content

Commit b6dc749

Browse files
committed
Check for rb_enc_interned_str_cstr and fall back
Truffle Ruby doesn't implement this function yet, so we need to check for it and then fall back if it's not there.
1 parent bb63f86 commit b6dc749

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

ext/sqlite3/extconf.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ def configure_extension
109109

110110
abort_could_not_find(libname) unless find_library(libname, "sqlite3_libversion_number", "sqlite3.h")
111111

112+
# Truffle Ruby doesn't support this yet:
113+
# https://github.com/oracle/truffleruby/issues/3408
114+
have_func("rb_enc_interned_str_cstr")
115+
112116
# Functions defined in 1.9 but not 1.8
113117
have_func("rb_proc_arity")
114118

ext/sqlite3/statement.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,22 @@ column_count(VALUE self)
364364
return INT2NUM(sqlite3_column_count(ctx->st));
365365
}
366366

367+
#if HAVE_RB_ENC_INTERNED_STR_CSTR
368+
static VALUE
369+
interned_utf8_cstr(const char * str)
370+
{
371+
return rb_enc_interned_str_cstr(str, rb_utf8_encoding());
372+
}
373+
#else
374+
static VALUE
375+
interned_utf8_cstr(const char * str)
376+
{
377+
VALUE rb_str = rb_utf8_str_new_cstr(str);
378+
rb_funcall(rb_str, rb_intern("-@"), 0);
379+
return rb_str;
380+
}
381+
#endif
382+
367383
/* call-seq: stmt.column_name(index)
368384
*
369385
* Get the column name at +index+. 0 based.
@@ -382,7 +398,7 @@ column_name(VALUE self, VALUE index)
382398
VALUE ret = Qnil;
383399

384400
if (name) {
385-
ret = rb_enc_interned_str_cstr(name, rb_utf8_encoding());
401+
ret = interned_utf8_cstr(name);
386402
}
387403
return ret;
388404
}

0 commit comments

Comments
 (0)