Signed-off-by: Tomek Grabiec <[email protected]>
---
include/vm/object.h | 12 ++++++++++++
vm/object.c | 9 ++++-----
vm/utf8.c | 7 +++----
3 files changed, 19 insertions(+), 9 deletions(-)
diff --git a/include/vm/object.h b/include/vm/object.h
index 6fcdfa0..a38a1d3 100644
--- a/include/vm/object.h
+++ b/include/vm/object.h
@@ -72,4 +72,16 @@ field_get_object(const struct vm_object *obj, const struct
vm_field *field)
return *(struct vm_object **) &obj->fields[field->offset];
}
+static inline void
+array_set_field_char(struct vm_object *obj, int index, uint16_t value)
+{
+ *(uint16_t *) &obj->fields[index * get_vmtype_size(J_CHAR)] = value;
+}
+
+static inline uint16_t
+array_get_field_char(struct vm_object *obj, int index)
+{
+ return *(uint16_t *) &obj->fields[index * get_vmtype_size(J_CHAR)];
+}
+
#endif
diff --git a/vm/object.c b/vm/object.c
index 7381f6b..0f96e62 100644
--- a/vm/object.c
+++ b/vm/object.c
@@ -228,9 +228,8 @@ vm_object_alloc_string_from_c(const char *bytes)
/* XXX: Need to handle code points >= 0x80 */
NOT_IMPLEMENTED;
- uint16_t *utf16_chars = (uint16_t *) &array->fields;
for (unsigned int i = 0; i < n; ++i) {
- utf16_chars[i] = bytes[i];
+ array_set_field_char(array, i, bytes[i]);
}
field_set_int32(string, vm_java_lang_String_offset, 0);
@@ -451,7 +450,6 @@ char *vm_string_to_cstr(const struct vm_object *string_obj)
{
struct vm_object *array_object;
struct string *str;
- int16_t *array;
int32_t offset;
int32_t count;
char *result;
@@ -459,7 +457,6 @@ char *vm_string_to_cstr(const struct vm_object *string_obj)
offset = field_get_int32(string_obj, vm_java_lang_String_offset);
count = field_get_int32(string_obj, vm_java_lang_String_count);
array_object = field_get_object(string_obj, vm_java_lang_String_value);
- array = (int16_t *) array_object->fields;
str = alloc_str();
if (!str)
@@ -468,9 +465,11 @@ char *vm_string_to_cstr(const struct vm_object *string_obj)
result = NULL;
for (int32_t i = 0; i < count; ++i) {
- int16_t ch = array[offset + i];
+ int16_t ch;
int err;
+ ch = array_get_field_char(array_object, offset + i);
+
if (ch < 128 && isprint(ch))
err = str_append(str, "%c", ch);
else
diff --git a/vm/utf8.c b/vm/utf8.c
index 36f914a..4ace133 100644
--- a/vm/utf8.c
+++ b/vm/utf8.c
@@ -58,17 +58,16 @@ struct vm_object *utf8_to_char_array(const uint8_t *bytes,
unsigned int n)
return array;
}
- uint16_t *utf16_chars = (uint16_t *) &array->fields;
for (unsigned int i = 0, j = 0; i < n; ++i) {
if (!(bytes[i] & 0x80)) {
- utf16_chars[j++] = bytes[i];
+ array_set_field_char(array, j++, bytes[i]);
continue;
}
if ((bytes[i] & 0xe0) == 0xc0) {
uint16_t ch = (uint16_t) (bytes[i++] & 0x1f) << 6;
ch += bytes[i++] & 0x3f;
- utf16_chars[j++] = ch;
+ array_set_field_char(array, j++, ch);
continue;
}
@@ -76,7 +75,7 @@ struct vm_object *utf8_to_char_array(const uint8_t *bytes,
unsigned int n)
uint16_t ch = (uint16_t) (bytes[i++] & 0xf) << 12;
ch += (uint16_t) (bytes[i++] & 0x3f) << 6;
ch += bytes[i++] & 0x3f;
- utf16_chars[j++] = ch;
+ array_set_field_char(array, j++, ch);
continue;
}
}
--
1.6.0.6
------------------------------------------------------------------------------
_______________________________________________
Jatovm-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jatovm-devel