The Meson Build System
http://mesonbuild.com/
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.
103 lines
2.0 KiB
103 lines
2.0 KiB
8 years ago
|
|
||
|
#include <stdio.h>
|
||
|
|
||
|
int func_from_language_runtime(void);
|
||
|
typedef int (*fptr) (void);
|
||
|
|
||
8 years ago
|
#ifdef _WIN32
|
||
|
|
||
8 years ago
|
#include <windows.h>
|
||
|
|
||
|
wchar_t*
|
||
|
win32_get_last_error (void)
|
||
|
{
|
||
|
wchar_t *msg = NULL;
|
||
|
|
||
|
FormatMessageW (FORMAT_MESSAGE_ALLOCATE_BUFFER
|
||
|
| FORMAT_MESSAGE_IGNORE_INSERTS
|
||
|
| FORMAT_MESSAGE_FROM_SYSTEM,
|
||
|
NULL, GetLastError (), 0,
|
||
|
(LPWSTR) &msg, 0, NULL);
|
||
|
return msg;
|
||
|
}
|
||
|
|
||
|
int
|
||
|
main (int argc, char **argv)
|
||
|
{
|
||
|
HINSTANCE handle;
|
||
|
fptr importedfunc;
|
||
|
int expected, actual;
|
||
|
int ret = 1;
|
||
|
|
||
|
handle = LoadLibraryA (argv[1]);
|
||
|
if (!handle) {
|
||
|
wchar_t *msg = win32_get_last_error ();
|
||
|
printf ("Could not open %s: %S\n", argv[1], msg);
|
||
|
goto nohandle;
|
||
|
}
|
||
|
|
||
|
importedfunc = (fptr) GetProcAddress (handle, "func");
|
||
|
if (importedfunc == NULL) {
|
||
|
wchar_t *msg = win32_get_last_error ();
|
||
|
printf ("Could not find 'func': %S\n", msg);
|
||
|
goto out;
|
||
|
}
|
||
|
|
||
|
actual = importedfunc ();
|
||
|
expected = func_from_language_runtime ();
|
||
|
if (actual != expected) {
|
||
|
printf ("Got %i instead of %i\n", actual, expected);
|
||
|
goto out;
|
||
|
}
|
||
|
|
||
|
ret = 0;
|
||
|
out:
|
||
|
FreeLibrary (handle);
|
||
|
nohandle:
|
||
|
return ret;
|
||
8 years ago
|
}
|
||
|
|
||
|
#else
|
||
|
|
||
|
#include<dlfcn.h>
|
||
|
#include<assert.h>
|
||
|
|
||
|
int main(int argc, char **argv) {
|
||
|
void *dl;
|
||
8 years ago
|
fptr importedfunc;
|
||
|
int expected, actual;
|
||
8 years ago
|
char *error;
|
||
8 years ago
|
int ret = 1;
|
||
8 years ago
|
|
||
|
dlerror();
|
||
|
dl = dlopen(argv[1], RTLD_LAZY);
|
||
|
error = dlerror();
|
||
|
if(error) {
|
||
|
printf("Could not open %s: %s\n", argv[1], error);
|
||
8 years ago
|
goto nodl;
|
||
8 years ago
|
}
|
||
8 years ago
|
|
||
|
importedfunc = (fptr) dlsym(dl, "func");
|
||
|
if (importedfunc == NULL) {
|
||
|
printf ("Could not find 'func'\n");
|
||
|
goto out;
|
||
|
}
|
||
|
|
||
8 years ago
|
assert(importedfunc != func_from_language_runtime);
|
||
8 years ago
|
|
||
|
actual = (*importedfunc)();
|
||
|
expected = func_from_language_runtime ();
|
||
|
if (actual != expected) {
|
||
|
printf ("Got %i instead of %i\n", actual, expected);
|
||
|
goto out;
|
||
|
}
|
||
|
|
||
|
ret = 0;
|
||
|
out:
|
||
8 years ago
|
dlclose(dl);
|
||
8 years ago
|
nodl:
|
||
|
return ret;
|
||
8 years ago
|
}
|
||
|
|
||
|
#endif
|