Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Revert "Add encoding support for Symbol"

This reverts commit 239ce0c.

There are some weird issues when building with 1.9 / 2.0 that need to be
investigated first.
  • Loading branch information...
commit 3cd5d2a1d74e9c5dc603378e6b418946790ab4f0 1 parent 6263c40
@dbussink dbussink authored
View
10 vm/builtin/encoding.cpp
@@ -145,7 +145,6 @@ namespace rubinius {
Index index, OnigEncodingType* enc)
{
Encoding* e = create(state, enc);
- e->index_ = (int) index;
e->cache_index_ = (int) index;
Tuple* ref = encoding_reference(state, index);
@@ -170,7 +169,6 @@ namespace rubinius {
Array* list = encoding_list(state);
size_t index = list->size();
- e->index_ = (int)index;
Tuple* ref = encoding_reference(state, index);
encoding_map(state)->store(state, encoding_symbol(state, name), ref);
@@ -206,7 +204,7 @@ namespace rubinius {
encoding_map(state)->store(state, encoding_symbol(state, name), ref);
add_constant(state, name, from_index(state, index));
- return as<Encoding>(from_index(state, index));
+ return as<Encoding>(encoding_list(state)->get(state, index));
}
Encoding* Encoding::default_external(STATE) {
@@ -261,8 +259,8 @@ namespace rubinius {
str->encoding(state, enc);
} else if(Regexp* reg = try_as<Regexp>(obj)) {
reg->encoding(state, enc);
- } else if(try_as<Symbol>(obj)) {
- // Can't change the encoding of a symbol
+ } else if(Symbol* sym = try_as<Symbol>(obj)) {
+ sym->encoding(state, enc);
} else if(try_as<IO>(obj)) {
// TODO
} else {
@@ -452,7 +450,7 @@ namespace rubinius {
Encoding* Encoding::find(STATE, const char* name) {
int index = find_index(state, name);
if(index < 0) return nil<Encoding>();
- return as<Encoding>(from_index(state, index));
+ return as<Encoding>(encoding_list(state)->get(state, index));
}
// Encoding#replicate primitive
View
5 vm/builtin/encoding.hpp
@@ -33,7 +33,6 @@ namespace rubinius {
Object* dummy_; // slot
OnigEncodingType* encoding_;
- int index_;
int cache_index_;
bool managed_;
@@ -41,10 +40,6 @@ namespace rubinius {
attr_accessor(name, String);
attr_accessor(dummy, Object);
- int index() const {
- return index_;
- }
-
int cache_index() const {
return cache_index_;
}
View
8 vm/builtin/symbol.cpp
@@ -72,7 +72,13 @@ namespace rubinius {
}
Encoding* Symbol::encoding(STATE) {
- return Encoding::from_index(state, state->shared().symbols.lookup_encoding(this));
+ // TODO
+ return Encoding::usascii_encoding(state);
+ }
+
+ Encoding* Symbol::encoding(STATE, Encoding* enc) {
+ // TODO
+ return enc;
}
void Symbol::Info::show(STATE, Object* self, int level) {
View
2  vm/builtin/symbol.hpp
@@ -58,6 +58,8 @@ namespace rubinius {
// Rubinius.primitive+ :symbol_encoding
Encoding* encoding(STATE);
+ Encoding* encoding(STATE, Encoding* enc);
+
class Info : public TypeInfo {
public:
Info(object_type type)
View
15 vm/capi/encoding.cpp
@@ -176,7 +176,8 @@ extern "C" {
int index = rb_to_encoding_index(obj);
if(index < 0) return 0;
- Encoding* enc = try_as<Encoding>(Encoding::from_index(env->state(), index));
+ Encoding* enc = try_as<Encoding>(
+ Encoding::encoding_list(env->state())->get(env->state(), index));
if(!enc) return 0;
return enc->get_encoding();
@@ -215,7 +216,8 @@ extern "C" {
VALUE rb_enc_associate_index(VALUE obj, int index) {
NativeMethodEnvironment* env = NativeMethodEnvironment::get();
- Encoding* enc = try_as<Encoding>(Encoding::from_index(env->state(), index));
+ Encoding* enc = try_as<Encoding>(
+ Encoding::encoding_list(env->state())->get(env->state(), index));
if(!enc) return obj;
@@ -225,8 +227,8 @@ extern "C" {
str->encoding(env->state(), enc);
} else if(Regexp* reg = try_as<Regexp>(val)) {
reg->encoding(env->state(), enc);
- } else if(try_as<Symbol>(val)) {
- // Can't change encoding of symbol
+ } else if(Symbol* sym = try_as<Symbol>(val)) {
+ sym->encoding(env->state(), enc);
} else {
rb_raise(rb_eArgError, "object does not have an associated Encoding");
}
@@ -412,9 +414,8 @@ extern "C" {
}
}
+ // TODO: respect the encoding parameter
ID rb_intern3(const char* string, long len, rb_encoding* enc) {
- NativeMethodEnvironment* env = NativeMethodEnvironment::get();
-
- return reinterpret_cast<ID>(env->state()->symbol(string, len, rb_enc_to_index(enc)));
+ return rb_intern2(string, len);
}
}
View
4 vm/marshal.cpp
@@ -116,7 +116,7 @@ namespace rubinius {
char *data = stack_data;
size_t count;
- Encoding* enc = try_as<Encoding>(unmarshal());
+ try_as<Encoding>(unmarshal());
stream >> count;
stream.get();
@@ -129,7 +129,7 @@ namespace rubinius {
stream.read(data, count + 1);
data[count] = 0; // clamp
- Symbol* sym = state->symbol(data, count, enc->index());
+ Symbol* sym = state->symbol(data, count);
if(malloc_data) {
free(malloc_data);
View
4 vm/state.hpp
@@ -59,10 +59,6 @@ namespace rubinius {
return shared_.symbols.lookup(this, str, len);
}
- Symbol* symbol(const char* str, size_t len, int enc) {
- return shared_.symbols.lookup(this, str, len, enc);
- }
-
Symbol* symbol(std::string str) {
return shared_.symbols.lookup(this, str);
}
View
42 vm/symboltable.cpp
@@ -55,11 +55,10 @@ namespace rubinius {
return kinds[sym->index()];
}
- size_t SymbolTable::add(std::string str, int enc) {
+ size_t SymbolTable::add(std::string str) {
bytes_used_ += (str.size() + sizeof(str));
strings.push_back(str);
- encodings.push_back(enc);
kinds.push_back(detect_kind(str.data(), str.size()));
return strings.size() - 1;
}
@@ -70,16 +69,7 @@ namespace rubinius {
return NULL;
}
- return lookup(str, length, Encoding::eAscii, state->hash_seed());
- }
-
- Symbol* SymbolTable::lookup(STATE, const char* str, size_t length, int enc) {
- if(length == 0 && LANGUAGE_18_ENABLED) {
- Exception::argument_error(state, "Cannot create a symbol from an empty string");
- return NULL;
- }
-
- return lookup(str, length, enc, state->hash_seed());
+ return lookup(str, length, state->hash_seed());
}
struct SpecialOperator {
@@ -114,14 +104,14 @@ namespace rubinius {
}
Symbol* SymbolTable::lookup(SharedState* shared, const std::string& str) {
- return lookup(str.data(), str.size(), Encoding::eAscii, shared->hash_seed);
+ return lookup(str.data(), str.size(), shared->hash_seed);
}
Symbol* SymbolTable::lookup(STATE, const std::string& str) {
- return lookup(str.data(), str.size(), Encoding::eAscii, state->hash_seed());
+ return lookup(str.data(), str.size(), state->hash_seed());
}
- Symbol* SymbolTable::lookup(const char* str, size_t length, int enc, uint32_t seed) {
+ Symbol* SymbolTable::lookup(const char* str, size_t length, uint32_t seed) {
size_t sym;
if(const char* op = find_special(str, length)) {
@@ -137,18 +127,17 @@ namespace rubinius {
utilities::thread::SpinLock::LockGuard guard(lock_);
SymbolMap::iterator entry = symbols.find(hash);
if(entry == symbols.end()) {
- sym = add(std::string(str, length), enc);
+ sym = add(std::string(str, length));
SymbolIds v(1, sym);
symbols[hash] = v;
} else {
SymbolIds& v = entry->second;
for(SymbolIds::const_iterator i = v.begin(); i != v.end(); ++i) {
std::string& s = strings[*i];
- int e = encodings[*i];
- if(!strncmp(s.data(), str, length) && enc == e) return Symbol::from_index(*i);
+ if(!strncmp(s.data(), str, length)) return Symbol::from_index(*i);
}
- sym = add(std::string(str, length), enc);
+ sym = add(std::string(str, length));
v.push_back(sym);
}
}
@@ -167,8 +156,6 @@ namespace rubinius {
const char* bytes = (const char*) str->byte_address();
size_t size = str->byte_size();
- int enc = str->encoding(state)->index();
-
if(LANGUAGE_18_ENABLED) {
for(size_t i = 0; i < size; i++) {
if(bytes[i] == 0) {
@@ -177,13 +164,9 @@ namespace rubinius {
return NULL;
}
}
- } else {
- if(CBOOL(str->ascii_only_p(state))) {
- enc = Encoding::eAscii;
- }
}
- return lookup(bytes, size, enc, state->hash_seed());
+ return lookup(state, bytes, size);
}
String* SymbolTable::lookup_string(STATE, const Symbol* sym) {
@@ -197,9 +180,8 @@ namespace rubinius {
return NULL;
}
std::string& str = strings[sym_index];
- int enc = encodings[sym_index];
String* s = String::create(state, str.data(), str.size());
- s->encoding(state, Encoding::from_index(state, enc));
+ s->encoding(state, Encoding::usascii_encoding(state));
return s;
}
@@ -207,10 +189,6 @@ namespace rubinius {
return strings[sym->index()];
}
- int SymbolTable::lookup_encoding(const Symbol* sym) {
- return encodings[sym->index()];
- }
-
std::string SymbolTable::lookup_debug_string(const Symbol* sym) {
std::string str = lookup_cppstring(sym);
std::ostringstream os;
View
8 vm/symboltable.hpp
@@ -33,7 +33,6 @@ namespace rubinius {
class SharedState;
typedef std::vector<std::string> SymbolStrings;
- typedef std::vector<int> SymbolEncodings;
typedef std::vector<std::size_t> SymbolIds;
typedef std_unordered_map<hashval, SymbolIds> SymbolMap;
@@ -57,12 +56,11 @@ namespace rubinius {
private:
SymbolMap symbols;
SymbolStrings strings;
- SymbolEncodings encodings;
SymbolKinds kinds;
utilities::thread::SpinLock lock_;
size_t bytes_used_;
- Symbol* lookup(const char* str, size_t length, int enc, uint32_t seed);
+ Symbol* lookup(const char* str, size_t length, uint32_t seed);
public:
@@ -79,12 +77,10 @@ namespace rubinius {
Symbol* lookup(SharedState* shared, const std::string& str);
Symbol* lookup(STATE, const std::string& str);
Symbol* lookup(STATE, const char* str, size_t length);
- Symbol* lookup(STATE, const char* str, size_t length, int enc);
Symbol* lookup(STATE, String* str);
String* lookup_string(STATE, const Symbol* sym);
std::string& lookup_cppstring(const Symbol* sym);
- int lookup_encoding(const Symbol* sym);
std::string lookup_debug_string(const Symbol* sym);
size_t size() const;
@@ -94,7 +90,7 @@ namespace rubinius {
size_t byte_size() const;
- size_t add(std::string str, int enc);
+ size_t add(std::string str);
static Kind detect_kind(const char* str, size_t size);
};
};
Please sign in to comment.
Something went wrong with that request. Please try again.