Signed-off-by: Tomek Grabiec <[email protected]>
---
vm/class.c | 35 +++++++++++++++++++++++++++++++++++
vm/classloader.c | 5 +----
2 files changed, 36 insertions(+), 4 deletions(-)
diff --git a/vm/class.c b/vm/class.c
index 96405db..9efb7a7 100644
--- a/vm/class.c
+++ b/vm/class.c
@@ -33,6 +33,7 @@
#include <cafebabe/constant_pool.h>
#include <cafebabe/field_info.h>
#include <cafebabe/method_info.h>
+#include <cafebabe/stream.h>
#include <vm/class.h>
#include <vm/classloader.h>
@@ -121,6 +122,38 @@ setup_vtable(struct vm_class *vmc)
}
}
+static char *
+cafebabe_class_get_source_file_name(const struct cafebabe_class *class)
+{
+ const struct cafebabe_constant_info_utf8 *file_name;
+ const struct cafebabe_attribute_info *attrib;
+ unsigned int source_file_attrib_index;
+ struct cafebabe_stream stream;
+ uint16_t sourcefile_index;
+
+ source_file_attrib_index = 0;
+
+ if (cafebabe_attribute_array_get(&class->attributes, "SourceFile",
+ class, &source_file_attrib_index))
+ return NULL;
+
+ attrib = class->attributes.array + source_file_attrib_index;
+
+ cafebabe_stream_open_buffer(&stream,
+ attrib->info, attrib->attribute_length);
+ cafebabe_stream_read_uint16(&stream, &sourcefile_index);
+ cafebabe_stream_close_buffer(&stream);
+
+ if (cafebabe_class_constant_get_utf8(class, sourcefile_index,
+ &file_name))
+ {
+ return NULL;
+ }
+
+ return strndup((char*)file_name->bytes, file_name->length);
+}
+
+
extern struct vm_class *vm_java_lang_Class;
int vm_class_link(struct vm_class *vmc, const struct cafebabe_class *class)
@@ -146,6 +179,8 @@ int vm_class_link(struct vm_class *vmc, const struct
cafebabe_class *class)
vmc->name = strndup((char *) name->bytes, name->length);
+ vmc->source_file_name = cafebabe_class_get_source_file_name(class);
+
if (class->super_class) {
const struct cafebabe_constant_info_class *constant_super;
if (cafebabe_class_constant_get_class(class,
diff --git a/vm/classloader.c b/vm/classloader.c
index a615fa3..71af1bf 100644
--- a/vm/classloader.c
+++ b/vm/classloader.c
@@ -383,10 +383,7 @@ struct vm_class *load_class(const char *class_name)
}
out_filename:
- if (result)
- result->source_file_name = filename;
- else
- free(filename);
+ free(filename);
return result;
}
--
1.6.0.6
------------------------------------------------------------------------------
_______________________________________________
Jatovm-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jatovm-devel