[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
OO2C problem
Hello all,
I am experiencing some unexpected behavior with OO2C. It could be that
my expectations are incorrect or that there is an error in OO2C. Would
you please enlighten me on which it is?
When I execute the following code compiled by OO2c v1.3.2 on RedHat
Linux v4.2:
MODULE Junk;
IMPORT
Out;
PROCEDURE Indirect (proc : PROCEDURE);
BEGIN
proc();
END Indirect;
PROCEDURE Test (a : INTEGER);
VAR
b : INTEGER;
PROCEDURE Write ();
BEGIN
Out.String("a = ");
Out.Int(a, 0);
Out.String(", b = ");
Out.Int(b, 0);
Out.Ln();
END Write;
BEGIN
b := a + 3;
Write();
Indirect(Write);
END Test;
BEGIN
Test(4);
END Junk.
I expect to see two identical lines written to stdout. Instead I get
the following:
; Junk
a = 4, b = 7
a = [status sigsegv]
In the actual code from which this snippet was constructed, the
program doesn't segfault but instead prints garbage. Looking at the
generated C code, it appears that the way our (to be praised highly)
compiler writers got around the lack of nested procedures in C is by
passing pointers to the parameters and local variables. However, as the
C code below shows, the pointers aren't getting passed along through
the indirection.
/* file generated by oo2c -- do not edit */
#include "__oo2c.h"
#include "__libc.h"
#include "Junk.d"
static _ModId _mid;
void Junk_Indirect(void(* proc)(void)) {
if (!(int)proc) _deref_of_nil(_P(84));
((void(*)(void))(int)proc)(); <=========== No integer ptr argument!
}
void Junk_Test_Write(short int *Junk_Test_a, short int *Junk_Test_b) {
register int i0;
Out_String((const unsigned char*)(int)_c0, 5);
i0 = *Junk_Test_a;
Out_Int((short int)i0, (int)0);
Out_String((const unsigned char*)(int)_c1, 7);
i0 = *Junk_Test_b;
Out_Int((short int)i0, (int)0);
Out_Ln();
}
void Junk_Test(short int a) {
register int i0;
short int b;
i0 = a + 3;
b = (short int)i0;
b = (short int)i0;
Junk_Test_Write(&a, &b);
Junk_Indirect((void(*)(void))(int)&Junk_Test_Write);
}
void Junk__init(void) {
_mid = _register_module(&Junk__md.md, NULL);
Junk_Test((short int)4);
}
Is my assessment of the situation correct? If so, how can OO2C be
modified to correct the problem?
Mark
--
Mark K. Gardner (mkgardne@cs.uiuc.edu)
University of Illinois at Urbana-Champaign
Real-Time Systems Laboratory
--