Consider python code below – it seems that calling .dll’s function is assuming long time for some reason (system is windows x64 if it’s important).
Why it’s doing this? Is there way to disable it? Will it get in the way in other cases, e.g. if I’m going to pass long long
arguments or initialize structs using long long
s?
<code>import ctypes
hello_lib = ctypes.CDLL("./hello.dll")
n = 13
# returns 1932053504 instead of 6227020800
print(hello_lib.factorial(n))
# for some reason result type is long,
# though it's declared as long long in .dll
# <class 'ctypes.c_long'>
print(hello_lib.factorial.restype)
hello_lib.factorial.restype = ctypes.c_longlong
# return 6227020800, changing result type helped
print(hello_lib.factorial(n))
</code>
<code>import ctypes
hello_lib = ctypes.CDLL("./hello.dll")
n = 13
# returns 1932053504 instead of 6227020800
print(hello_lib.factorial(n))
# for some reason result type is long,
# though it's declared as long long in .dll
# <class 'ctypes.c_long'>
print(hello_lib.factorial.restype)
hello_lib.factorial.restype = ctypes.c_longlong
# return 6227020800, changing result type helped
print(hello_lib.factorial(n))
</code>
import ctypes
hello_lib = ctypes.CDLL("./hello.dll")
n = 13
# returns 1932053504 instead of 6227020800
print(hello_lib.factorial(n))
# for some reason result type is long,
# though it's declared as long long in .dll
# <class 'ctypes.c_long'>
print(hello_lib.factorial.restype)
hello_lib.factorial.restype = ctypes.c_longlong
# return 6227020800, changing result type helped
print(hello_lib.factorial(n))
.dll code:
<code>// choco install mingw
// gcc -shared -o hello.dll hello.c
#include <stdio.h>
long long int factorial(int n) {
if (n>=1) {
return n*factorial(n-1);
}
return 1;
}
</code>
<code>// choco install mingw
// gcc -shared -o hello.dll hello.c
#include <stdio.h>
long long int factorial(int n) {
if (n>=1) {
return n*factorial(n-1);
}
return 1;
}
</code>
// choco install mingw
// gcc -shared -o hello.dll hello.c
#include <stdio.h>
long long int factorial(int n) {
if (n>=1) {
return n*factorial(n-1);
}
return 1;
}