You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Markus Bergholz 99bab6f7c8 update 5 years ago
codegen-A/lib crap 5 years ago
codegen-B/lib crap 5 years ago
codegen-non-modular/lib crap 5 years ago
README.md update 5 years ago
mainfunction.m crap 5 years ago
mainfunction.prj crap 5 years ago
subfunction.m crap 5 years ago
subfunction.prj crap 5 years ago

README.md

Matlab codgen disaster

  • codegen-A and codegen-B are modulized, calling subfunction() with coder.ceval().
    • codegen-B sefaults (like matlab documentation)
    • codegen-A buffer overflow or something like that
  • codegen-non-modulized includes subfunction() directly by codegen - and is the only working methode.

    >> mainfunction([1 2 3])
    
    ans =
    
               7.69529898097118
    

codegen-A

mainfunction.m

function ret = mainfunction (in) %#codegen
    ret = (sum(in));
    if coder.target ('MATLAB')
        ret = subfunction(ret);
    else
        ret = coder.ceval('subfunction', ret);
    end   
end

gcc - host linux

$ gcc -std=c99 -lm -I subfunction/ subfunction/subfunction.c mainfunction/*.c main.c -o main
$ ./main
input vector
 1.000000 2.000000 3.000000
output double: 986324705.000000

tcc - host linux

$ tcc -lm -I subfunction/ subfunction/subfunction.c mainfunction/*.c main.c -o main
$ ./main
input vector
 1.000000 2.000000 3.000000
output double: 159760432.000000

clang - host mac os x

$ clang -lm subfunction/subfunction.c mainfunction/*.c main.c -o macmain
$ ./macmain 
input vector
 1.000000 2.000000 3.000000
output double: 1.000000

codegen-B

mainfunction.m

function ret = mainfunction (in) %#codegen
    ret = (sum(in));
    if coder.target ('MATLAB')
        ret = subfunction(ret);
    else
        coder.ceval('subfunction_initialize')
        ret = coder.ceval('subfunction', ret);
        coder.ceval('subfunction_terminate')
    end
end

gcc - host linux

$ gcc -std=c99 -lm -I subfunction/ subfunction/subfunction*.c mainfunction/*.c 
$ ./main
input vector
 1.000000 2.000000 3.000000
Segmentation fault

tcc - host linux

$ tcc -lm -I subfunction/ subfunction/subfunction*.c mainfunction/*.c main.c -o main
$ ./main
input vector
 1.000000 2.000000 3.000000
Segmentation fault

clang - host mac os x

$ clang -lm subfunction/subfunction*.c mainfunction/*.c main.c -o macmain
$ ./macmain 
input vector
 1.000000 2.000000 3.000000
output double: 1.000000

codegen-non-modular

the only version which works fine!

mainfunction.m

function ret = mainfunction (in) %#codegen
    ret = (sum(in));
    ret = subfunction(ret);
end

gcc - host linux

$ gcc -std=c99 -lm mainfunction/*.c main.c -o main
$ ./main
input vector
 1.000000 2.000000 3.000000
output double: 7.695299

tcc - host linux

$ tcc -lm mainfunction/*.c main.c -o main
$ ./main
input vector
 1.000000 2.000000 3.000000
output double: 7.695299

clang - host mac os x

$ clang -lm mainfunction/*.c main.c -o macmain
$ ./macmain 
input vector
 1.000000 2.000000 3.000000
output double: 7.695299