Fixed some C/C++ compiler errors due to stricter checks.
[rubinius.git] / machine / capi / regexp.cpp
blob76a0ec079712d8df0e528ff9bf76fd328f8638f6
1 #include "thread_state.hpp"
2 #include "object_utils.hpp"
3 #include "spinlock.hpp"
5 #include "class/array.hpp"
6 #include "class/fixnum.hpp"
7 #include "class/io.hpp"
8 #include "class/regexp.hpp"
9 #include "class/string.hpp"
10 #include "memory.hpp"
11 #include "primitives.hpp"
13 #include "capi/capi.hpp"
14 #include "capi/ruby.h"
16 using namespace rubinius;
17 using namespace rubinius::capi;
19 extern "C" {
21 VALUE rb_reg_new(const char *source, long len, int options) {
22 NativeMethodEnvironment* env = NativeMethodEnvironment::get();
23 String *pat = String::create_pinned(env->state(), source, len);
24 return rb_funcall(rb_cRegexp, rb_intern("new"), 2,
25 MemoryHandle::value(pat), Fixnum::from(options));
28 VALUE rb_reg_nth_match(long nth, VALUE match_data) {
29 if(NIL_P(match_data)) {
30 return Qnil;
32 return rb_funcall(match_data, rb_intern("[]"), 1, Fixnum::from(nth));
35 VALUE rb_reg_source(VALUE r) {
36 return rb_String(rb_funcall(r, rb_intern("source"), 0));
39 int rb_reg_options(VALUE r) {
40 return FIX2INT(rb_funcall(r, rb_intern("options"), 0));
43 VALUE rb_reg_regcomp(VALUE str) {
44 return rb_funcall(rb_cRegexp, rb_intern("new"), 1, str);
47 VALUE rb_reg_match(VALUE re, VALUE str) {
48 return rb_funcall(re, rb_intern("=~"), 1, str);
51 VALUE rb_backref_get(void) {
52 return rb_gv_get("$~");
55 static locks::spinlock_mutex onig_lock;
57 void capi_reg_lock() {
58 onig_lock.lock();
61 void capi_reg_unlock() {
62 onig_lock.unlock();