Skip to content

Commit

Permalink
Update a Strings handle on mutation
Browse files Browse the repository at this point in the history
Abstracting slot access wins again! One place to change for all code
that changes the size and data to go through! PARTY!
  • Loading branch information
evanphx committed Feb 8, 2012
1 parent be4853e commit 358f819
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
12 changes: 12 additions & 0 deletions vm/builtin/string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@

#include "ontology.hpp"

#include "capi/handle.hpp"
#include "builtin/nativemethod.hpp"

#include <gdtoa.h>

#include <unistd.h>
Expand Down Expand Up @@ -150,6 +153,15 @@ namespace rubinius {
return s;
}

void String::update_handle() {
if(!inflated_header_p()) return;

capi::Handle* handle = inflated_header()->handle();
if(!handle) return;

handle->update(NativeMethodEnvironment::get());
}

static bool byte_compatible_p(Encoding* enc) {
return enc->nil_p() || ONIGENC_MBC_MAXLEN(enc->get_encoding()) == 1;
}
Expand Down
21 changes: 19 additions & 2 deletions vm/builtin/string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,26 @@ namespace rubinius {
public:
/* accessors */

attr_accessor(num_bytes, Fixnum);
attr_reader(num_bytes, Fixnum);
attr_reader(data, ByteArray);

void update_handle();

template <class T>
void num_bytes(T state, Fixnum* obj) {
num_bytes_ = obj;
update_handle();
}

template <class T>
void data(T state, ByteArray* obj) {
data_ = obj;
if(zone() == MatureObjectZone) this->write_barrier(state, obj);

update_handle();
}

attr_accessor(num_chars, Fixnum);
attr_accessor(data, ByteArray);
attr_accessor(hash_value, Fixnum);
attr_accessor(shared, Object);
attr_accessor(encoding, Encoding);
Expand Down

0 comments on commit 358f819

Please sign in to comment.