Skip to content

Commit c086476

Browse files
committed
Add a dummy NULL entry to method table; fixes problems with tests for NULL function pointers
1 parent 316e672 commit c086476

File tree

5 files changed

+6
-3
lines changed

5 files changed

+6
-3
lines changed

Changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Version 7.0.1
22
- Fixed incorrect casts of arrays
3+
- Put a dummy entry at the beginning of the method table, to represent NULL
34

45
Version 7.0.0
56
- Added Spin2 structures (basically small objects)

backends/asm/assemble_ir.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ OutputDataBlob(Flexbuf *fb, Flexbuf *databuf, Flexbuf *relocbuf, const char *sta
561561
} else if (indexedFunc) {
562562
if (sym->kind == SYM_FUNCTION) {
563563
Function *F = (Function *)sym->v.ptr;
564-
indexForFunc = F->method_index - 1;
564+
indexForFunc = F->method_index;
565565
} else {
566566
indexForFunc = -1;
567567
}

backends/asm/outasm.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7293,6 +7293,8 @@ OutputAsmCode(const char *fname, Module *P, int outputMain)
72937293
Function *LastG = NULL;
72947294
Function *G;
72957295
EmitLabel(&hubdata, method_table_label);
7296+
if (F)
7297+
EmitLong(&hubdata, 0); // dummy NULL entry
72967298
while (F != LastG) {
72977299
for (G = F; G->next_method != LastG; G = G->next_method) {
72987300
}

backends/becommon.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ BuildMethodPointer(AST *ast)
7070
}
7171
// save off the current @ node
7272
if (IndexedMethodPtrs()) {
73-
funcaddr = AstInteger(func->method_index-1);
73+
funcaddr = AstInteger(func->method_index);
7474
} else {
7575
funcaddr = NewAST(AST_ADDROF, ast->left, ast->right);
7676
}

frontends/common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ typedef struct funcdef {
512512

513513
/* linked list of functions whose addresses are taken */
514514
/* used for building a jump table */
515-
int method_index; // index into jump table, +1
515+
int method_index; // index into jump table
516516
struct funcdef *next_method; // next in jump table
517517
} Function;
518518

0 commit comments

Comments
 (0)