Filter löschen
Filter löschen

loadlibrary produces invalid thunk code

2 Ansichten (letzte 30 Tage)
Krzysztof
Krzysztof am 17 Sep. 2013
Here are my sources:
an_out = fopen ('foobar.h', 'w');
fwrite (an_out, [ '#include <windows.h>', 10, 'int WINAPI foo (), bar ();', 10 ]);
fclose (an_out);
an_out = fopen ('foobar.c', 'w');
fwrite...
(an_out, ...
[ ...
'#include <windows.h>', 10, ...
'_declspec (dllexport) int WINAPI foo (), WINAPI bar ();', 10, ...
'#include "foobar.h"', 10, ...
'_declspec (dllexport) int WINAPI foo () { return 0; } _declspec (dllexport) int WINAPI bar () { return 01; }', 10 ]);
fclose (an_out);
! CL /LD foobar.c
loadlibrary foobar
MATLAB-generated thunk code causes the following compiler error:
foobar_thunk_pcwin64.c(25) : error C2143: syntax error : missing ')' before '('
Here is the relevant source:
#include "foobar.h"
/* int __stdcall foo (), bar (); */
EXPORT_EXTERN_C int32_T int32voidPtrbar(Thunk(void fcn(),const char *callstack,int stacksize)
{
void * p0;
bar ( p1;
p0=*(void * const *)callstack;
callstack+=sizeof(p0) % sizeof(size_t) ? ((sizeof(p0) / sizeof(size_t)) + 1) * sizeof(size_t):sizeof(p0);
p1=*(bar ( const *)callstack;
callstack+=sizeof(p1) % sizeof(size_t) ? ((sizeof(p1) / sizeof(size_t)) + 1) * sizeof(size_t):sizeof(p1);
return ((int32_T (*)(void * , bar ( ))fcn)(p0 , p1);
}
You may wish to observe that the generated function declaration does not make sense.

Akzeptierte Antwort

Philip Borghesani
Philip Borghesani am 17 Sep. 2013
Although legal c this header code is certainly bad form and I would not recommend it. Unfortunately loadlibarary only properly recognizes one function deceleration per statement. I consider this a bug in loadlibrary please file a bug report.
To work around change
int WINAPI foo (), bar ();
Make it
int WINAPI foo ();
int WINAPI bar();

Weitere Antworten (0)

Kategorien

Mehr zu C Shared Library Integration finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by