Fixed some C/C++ compiler errors due to stricter checks.
[rubinius.git] / machine / c_api.cpp
blob02331b3aa54b7351cf673adbb0031115dac16139
1 #include "c_api.hpp"
3 namespace rubinius {
4 C_API::C_API()
5 : capi_constant_name_map_()
6 , capi_constant_map_()
7 , capi_black_list_()
8 , capi_locks_()
9 , capi_lock_map_()
10 , use_capi_lock_(false)
11 , capi_ds_lock_()
12 , capi_locks_lock_()
13 , capi_constant_lock_()
15 initialize_capi_black_list();
16 setup_capi_constant_names();
19 void C_API::after_fork_child(STATE) {
20 // Reinit the locks for this object
21 new(&capi_ds_lock_) locks::spinlock_mutex;
22 new(&capi_locks_lock_) locks::spinlock_mutex;
23 new(&capi_constant_lock_) locks::spinlock_mutex;
26 void C_API::enter_capi(STATE, const char* file, int line) {
27 NativeMethodEnvironment* env = state->native_method_environment;
28 if(int lock_index = env->current_native_frame()->capi_lock_index()) {
29 capi_locks_[lock_index - 1]->lock();
33 void C_API::leave_capi(STATE) {
34 NativeMethodEnvironment* env = state->native_method_environment;
35 if(int lock_index = env->current_native_frame()->capi_lock_index()) {
36 capi_locks_[lock_index - 1]->unlock();
40 int C_API::capi_lock_index(std::string name) {
41 std::lock_guard<locks::spinlock_mutex> guard(capi_locks_lock_);
43 int existing = capi_lock_map_[name];
44 if(existing) return existing;
46 CApiBlackList::const_iterator blacklisted = capi_black_list_.find(name);
48 // Only disable locks if we have capi locks disabled
49 // and library is not in the blacklist.
50 if(!use_capi_lock_ && blacklisted == capi_black_list_.end()) {
51 capi_lock_map_[name] = 0;
52 return 0;
55 std::mutex* lock = new std::mutex;
56 capi_locks_.push_back(lock);
58 // We use a 1 offset index, so 0 can indicate no lock used
59 int lock_index = capi_locks_.size();
60 capi_lock_map_[name] = lock_index;
61 return lock_index;
64 void C_API::setup_capi_constant_names() {
65 capi_constant_name_map_.resize(cCApiMaxConstant + 1);
67 capi_constant_name_map_[cCApiArray] = "Array";
68 capi_constant_name_map_[cCApiBignum] = "Bignum";
69 capi_constant_name_map_[cCApiClass] = "Class";
70 capi_constant_name_map_[cCApiComparable] = "Comparable";
71 capi_constant_name_map_[cCApiData] = "Data";
72 capi_constant_name_map_[cCApiEnumerable] = "Enumerable";
73 capi_constant_name_map_[cCApiFalse] = "FalseClass";
74 capi_constant_name_map_[cCApiFile] = "File";
75 capi_constant_name_map_[cCApiFixnum] = "Fixnum";
76 capi_constant_name_map_[cCApiFloat] = "Float";
77 capi_constant_name_map_[cCApiHash] = "Hash";
78 capi_constant_name_map_[cCApiInteger] = "Integer";
79 capi_constant_name_map_[cCApiIO] = "IO";
80 capi_constant_name_map_[cCApiKernel] = "Kernel";
81 capi_constant_name_map_[cCApiMatch] = "MatchData";
82 capi_constant_name_map_[cCApiModule] = "Module";
83 capi_constant_name_map_[cCApiNil] = "NilClass";
84 capi_constant_name_map_[cCApiNumeric] = "Numeric";
85 capi_constant_name_map_[cCApiObject] = "Object";
86 capi_constant_name_map_[cCApiRange] = "Range";
87 capi_constant_name_map_[cCApiRegexp] = "Regexp";
88 capi_constant_name_map_[cCApiRubinius] = "Rubinius";
89 capi_constant_name_map_[cCApiString] = "String";
90 capi_constant_name_map_[cCApiStruct] = "Struct";
91 capi_constant_name_map_[cCApiSymbol] = "Symbol";
92 capi_constant_name_map_[cCApiThread] = "Thread";
93 capi_constant_name_map_[cCApiTime] = "Time";
94 capi_constant_name_map_[cCApiTrue] = "TrueClass";
95 capi_constant_name_map_[cCApiProc] = "Proc";
96 capi_constant_name_map_[cCApiGC] = "GC";
97 capi_constant_name_map_[cCApiCAPI] = "Rubinius::CAPI";
98 capi_constant_name_map_[cCApiMethod] = "Method";
99 capi_constant_name_map_[cCApiRational] = "Rational";
100 capi_constant_name_map_[cCApiComplex] = "Complex";
101 capi_constant_name_map_[cCApiEnumerator] = "Enumerator";
102 capi_constant_name_map_[cCApiMutex] = "Mutex";
103 capi_constant_name_map_[cCApiDir] = "Dir";
105 capi_constant_name_map_[cCApiArgumentError] = "ArgumentError";
106 capi_constant_name_map_[cCApiEOFError] = "EOFError";
107 capi_constant_name_map_[cCApiErrno] = "Errno";
108 capi_constant_name_map_[cCApiException] = "Exception";
109 capi_constant_name_map_[cCApiFatal] = "FatalError";
110 capi_constant_name_map_[cCApiFloatDomainError] = "FloatDomainError";
111 capi_constant_name_map_[cCApiIndexError] = "IndexError";
112 capi_constant_name_map_[cCApiInterrupt] = "Interrupt";
113 capi_constant_name_map_[cCApiIOError] = "IOError";
114 capi_constant_name_map_[cCApiLoadError] = "LoadError";
115 capi_constant_name_map_[cCApiLocalJumpError] = "LocalJumpError";
116 capi_constant_name_map_[cCApiNameError] = "NameError";
117 capi_constant_name_map_[cCApiNoMemoryError] = "NoMemoryError";
118 capi_constant_name_map_[cCApiNoMethodError] = "NoMethodError";
119 capi_constant_name_map_[cCApiNotImplementedError] = "NotImplementedError";
120 capi_constant_name_map_[cCApiRangeError] = "RangeError";
121 capi_constant_name_map_[cCApiRegexpError] = "RegexpError";
122 capi_constant_name_map_[cCApiRuntimeError] = "RuntimeError";
123 capi_constant_name_map_[cCApiScriptError] = "ScriptError";
124 capi_constant_name_map_[cCApiSecurityError] = "SecurityError";
125 capi_constant_name_map_[cCApiSignalException] = "SignalException";
126 capi_constant_name_map_[cCApiStandardError] = "StandardError";
127 capi_constant_name_map_[cCApiSyntaxError] = "SyntaxError";
128 capi_constant_name_map_[cCApiSystemCallError] = "SystemCallError";
129 capi_constant_name_map_[cCApiSystemExit] = "SystemExit";
130 capi_constant_name_map_[cCApiSystemStackError] = "SystemStackError";
131 capi_constant_name_map_[cCApiTypeError] = "TypeError";
132 capi_constant_name_map_[cCApiThreadError] = "ThreadError";
133 capi_constant_name_map_[cCApiZeroDivisionError] = "ZeroDivisionError";
135 capi_constant_name_map_[cCApiMathDomainError] = "Math::DomainError";
136 capi_constant_name_map_[cCApiEncoding] = "Encoding";
137 capi_constant_name_map_[cCApiEncCompatError] = "Encoding::CompatibilityError";
138 capi_constant_name_map_[cCApiWaitReadable] = "IO::WaitReadable";
139 capi_constant_name_map_[cCApiWaitWritable] = "IO::WaitWritable";
143 #define CAPI_BLACK_LIST(name) capi_black_list_.insert(std::string("Init_" # name))
144 void C_API::initialize_capi_black_list() {
145 CAPI_BLACK_LIST(nkf);
146 CAPI_BLACK_LIST(nokogiri);