Skip to content

Commit

Permalink
class: return const pointer results
Browse files Browse the repository at this point in the history
This prevents accidental modification of class data which should never
change after it has been loaded initially.

Signed-off-by: Vegard Nossum <[email protected]>
  • Loading branch information
Vegard Nossum committed Jun 5, 2008
1 parent f9ca163 commit 28ae1d5
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
8 changes: 4 additions & 4 deletions include/cafebabe/class.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ void cafebabe_class_deinit(struct cafebabe_class *c);
int cafebabe_class_constant_index_invalid(const struct cafebabe_class *c,
uint16_t i);
int cafebabe_class_constant_get_utf8(const struct cafebabe_class *c,
uint16_t i, struct cafebabe_constant_info_utf8 **r);
uint16_t i, const struct cafebabe_constant_info_utf8 **r);
int cafebabe_class_constant_get_class(const struct cafebabe_class *c,
uint16_t i, struct cafebabe_constant_info_class **r);
uint16_t i, const struct cafebabe_constant_info_class **r);

int cafebabe_class_get_field(const struct cafebabe_class *c,
const char *name, const char *descriptor,
struct cafebabe_field_info **r);
const struct cafebabe_field_info **r);
int cafebabe_class_get_method(const struct cafebabe_class *c,
const char *name, const char *descriptor,
struct cafebabe_method_info **r);
const struct cafebabe_method_info **r);

#endif
20 changes: 10 additions & 10 deletions src/cafebabe/class.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,12 @@ cafebabe_class_constant_index_invalid(const struct cafebabe_class *c,

int
cafebabe_class_constant_get_utf8(const struct cafebabe_class *c, uint16_t i,
struct cafebabe_constant_info_utf8 **r)
const struct cafebabe_constant_info_utf8 **r)
{
if (cafebabe_class_constant_index_invalid(c, i))
return 1;

struct cafebabe_constant_pool *pool = &c->constant_pool[i];
const struct cafebabe_constant_pool *pool = &c->constant_pool[i];
if (pool->tag != CAFEBABE_CONSTANT_TAG_UTF8)
return 1;

Expand All @@ -212,12 +212,12 @@ cafebabe_class_constant_get_utf8(const struct cafebabe_class *c, uint16_t i,

int
cafebabe_class_constant_get_class(const struct cafebabe_class *c, uint16_t i,
struct cafebabe_constant_info_class **r)
const struct cafebabe_constant_info_class **r)
{
if (cafebabe_class_constant_index_invalid(c, i))
return 1;

struct cafebabe_constant_pool *pool = &c->constant_pool[i];
const struct cafebabe_constant_pool *pool = &c->constant_pool[i];
if (pool->tag != CAFEBABE_CONSTANT_TAG_CLASS)
return 1;

Expand All @@ -228,10 +228,10 @@ cafebabe_class_constant_get_class(const struct cafebabe_class *c, uint16_t i,
int
cafebabe_class_get_field(const struct cafebabe_class *c,
const char *name, const char *descriptor,
struct cafebabe_field_info **r)
const struct cafebabe_field_info **r)
{
for (uint16_t i = 0; i < c->fields_count; ++i) {
struct cafebabe_constant_info_utf8 *field_name;
const struct cafebabe_constant_info_utf8 *field_name;
if (cafebabe_class_constant_get_utf8(c,
c->fields[i].name_index, &field_name))
{
Expand All @@ -241,7 +241,7 @@ cafebabe_class_get_field(const struct cafebabe_class *c,
if (cafebabe_constant_info_utf8_compare(field_name, name))
continue;

struct cafebabe_constant_info_utf8 *field_descriptor;
const struct cafebabe_constant_info_utf8 *field_descriptor;
if (cafebabe_class_constant_get_utf8(c,
c->fields[i].descriptor_index, &field_descriptor))
{
Expand All @@ -265,10 +265,10 @@ cafebabe_class_get_field(const struct cafebabe_class *c,
int
cafebabe_class_get_method(const struct cafebabe_class *c,
const char *name, const char *descriptor,
struct cafebabe_method_info **r)
const struct cafebabe_method_info **r)
{
for (uint16_t i = 0; i < c->methods_count; ++i) {
struct cafebabe_constant_info_utf8 *method_name;
const struct cafebabe_constant_info_utf8 *method_name;
if (cafebabe_class_constant_get_utf8(c,
c->methods[i].name_index, &method_name))
{
Expand All @@ -278,7 +278,7 @@ cafebabe_class_get_method(const struct cafebabe_class *c,
if (cafebabe_constant_info_utf8_compare(method_name, name))
continue;

struct cafebabe_constant_info_utf8 *method_descriptor;
const struct cafebabe_constant_info_utf8 *method_descriptor;
if (cafebabe_class_constant_get_utf8(c,
c->methods[i].descriptor_index, &method_descriptor))
{
Expand Down
12 changes: 6 additions & 6 deletions src/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ main(int argc, char *argv[])
printf("version: %d.%d\n", class.major_version, class.minor_version);

/* Look up class name */
struct cafebabe_constant_info_class *this_class;
const struct cafebabe_constant_info_class *this_class;
if (cafebabe_class_constant_get_class(&class, class.this_class,
&this_class))
{
Expand All @@ -67,7 +67,7 @@ main(int argc, char *argv[])
goto out_class;
}

struct cafebabe_constant_info_utf8 *this_class_name;
const struct cafebabe_constant_info_utf8 *this_class_name;
if (cafebabe_class_constant_get_utf8(&class, this_class->name_index,
&this_class_name))
{
Expand All @@ -80,7 +80,7 @@ main(int argc, char *argv[])
this_class_name->length, this_class_name->bytes);

/* Look up superclass name */
struct cafebabe_constant_info_class *super_class;
const struct cafebabe_constant_info_class *super_class;
if (cafebabe_class_constant_get_class(&class, class.super_class,
&super_class))
{
Expand All @@ -89,7 +89,7 @@ main(int argc, char *argv[])
goto out_class;
}

struct cafebabe_constant_info_utf8 *super_class_name;
const struct cafebabe_constant_info_utf8 *super_class_name;
if (cafebabe_class_constant_get_utf8(&class, super_class->name_index,
&super_class_name))
{
Expand All @@ -116,7 +116,7 @@ main(int argc, char *argv[])
super_class_name->length, super_class_name->bytes);

for(uint16_t i = 0; i < class.fields_count; ++i) {
struct cafebabe_constant_info_utf8 *field_name;
const struct cafebabe_constant_info_utf8 *field_name;
if (cafebabe_class_constant_get_utf8(&class,
class.fields[i].name_index, &field_name))
{
Expand All @@ -131,7 +131,7 @@ main(int argc, char *argv[])
}

for(uint16_t i = 0; i < class.methods_count; ++i) {
struct cafebabe_constant_info_utf8 *method_name;
const struct cafebabe_constant_info_utf8 *method_name;
if (cafebabe_class_constant_get_utf8(&class,
class.methods[i].name_index, &method_name))
{
Expand Down
2 changes: 1 addition & 1 deletion src/java.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ main(int argc, char *argv[])
goto out_stream;
}

struct cafebabe_method_info *main_method;
const struct cafebabe_method_info *main_method;
if (cafebabe_class_get_method(&class,
"main", "([Ljava/lang/String;)V", &main_method))
{
Expand Down

0 comments on commit 28ae1d5

Please sign in to comment.