Skip to content

Instantly share code, notes, and snippets.

@kronos
Created May 18, 2011 16:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kronos/978974 to your computer and use it in GitHub Desktop.
Save kronos/978974 to your computer and use it in GitHub Desktop.
From a92ffb1947016df74169211d6bb962fd3da13f98 Mon Sep 17 00:00:00 2001
From: Ivan Samsonov <hronya@gmail.com>
Date: Wed, 18 May 2011 20:43:44 +0400
Subject: [PATCH] Provide size for converting byte_array. Fixes #887
---
vm/builtin/bytearray.cpp | 4 ++--
vm/builtin/bytearray.hpp | 2 +-
vm/builtin/string.cpp | 2 +-
vm/test/test_bytearray.hpp | 2 +-
4 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/vm/builtin/bytearray.cpp b/vm/builtin/bytearray.cpp
index 1b161bc..6bd65e7 100644
--- a/vm/builtin/bytearray.cpp
+++ b/vm/builtin/bytearray.cpp
@@ -61,8 +61,8 @@ namespace rubinius {
// @todo implement
}
- char* ByteArray::to_chars(STATE) {
- native_int sz = this->size(state)->to_native();
+ char* ByteArray::to_chars(STATE, Fixnum* size) {
+ native_int sz = size->to_native();
char* str = (char*)(this->bytes);
char* out = ALLOC_N(char, sz);
diff --git a/vm/builtin/bytearray.hpp b/vm/builtin/bytearray.hpp
index 7191def..0bc9999 100644
--- a/vm/builtin/bytearray.hpp
+++ b/vm/builtin/bytearray.hpp
@@ -76,7 +76,7 @@ namespace rubinius {
// Ruby.primitive :bytearray_reverse
ByteArray* reverse(STATE, Fixnum* start, Fixnum* total);
- char* to_chars(STATE);
+ char* to_chars(STATE, Fixnum* size);
class Info : public TypeInfo {
public:
diff --git a/vm/builtin/string.cpp b/vm/builtin/string.cpp
index be84827..91a015e 100644
--- a/vm/builtin/string.cpp
+++ b/vm/builtin/string.cpp
@@ -372,7 +372,7 @@ namespace rubinius {
double String::to_double(STATE) {
double value;
- char *ba = data_->to_chars(state);
+ char *ba = data_->to_chars(state, num_bytes_);
char *p, *n, *rest;
int e_seen = 0;
diff --git a/vm/test/test_bytearray.hpp b/vm/test/test_bytearray.hpp
index 60e646a..7f47847 100644
--- a/vm/test/test_bytearray.hpp
+++ b/vm/test/test_bytearray.hpp
@@ -53,7 +53,7 @@ class TestByteArray : public CxxTest::TestSuite, public VMTest {
void test_to_chars() {
String* s = String::create(state, "xy");
ByteArray* b = s->data();
- char* chars = b->to_chars(state);
+ char* chars = b->to_chars(state, Fixnum::from(2));
TS_ASSERT_SAME_DATA("xy", chars, 2);
}
--
1.7.3.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment