Esempio n. 1
0
  VALUE capi_get_constant(CApiConstant type) {
    static CApiConstantHandleMap map;

    CApiConstantHandleMap::iterator entry = map.find(type);
    if(entry == map.end()) {
      VALUE val = rb_path2class(capi_get_constant_name(type).c_str());
      capi::Handle::from(val)->ref(); // Extra ref, since we save it in the map
      map[type] = val;
      return val;
    } else {
      return entry->second;
    }
  }
Esempio n. 2
0
  VALUE capi_get_constant(CApiConstant type) {
    static CApiConstantHandleMap map;

    CApiConstantHandleMap::iterator entry = map.find(type);
    if(entry == map.end()) {
      NativeMethodEnvironment* env = NativeMethodEnvironment::get();
      Object* obj = env->state()->globals.object.get()->get_const(env->state(),
          capi_get_constant_name(type).c_str());

      Handle handle = env->get_handle_global(obj);
      map[type] = handle;
      return handle;
    } else {
      return entry->second;
    }
  }
Esempio n. 3
0
  VALUE capi_get_constant(CApiConstant type) {
    NativeMethodEnvironment* env = NativeMethodEnvironment::get();

    env->shared().capi_constant_lock().lock();
    CApiConstantHandleMap map = env->state()->shared().capi_constant_handle_map();

    CApiConstantHandleMap::iterator entry = map.find(type);
    if(entry == map.end()) {
      std::string constant_name = capi_get_constant_name(type);

      VALUE val = rb_path2class(constant_name.c_str());
      capi::Handle* hdl = capi::Handle::from(val);
      hdl->ref(); // Extra ref, since we save it in the map
      map[type] = hdl;
      env->shared().capi_constant_lock().unlock();
      return val;
    } else {
      VALUE val = entry->second->as_value();
      env->shared().capi_constant_lock().unlock();
      return val;
    }
  }