-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
size is not correct on struct_kinfo_proc from sys/sysctl.h #115
Comments
additional info: 8 bytes diff is on |
Hmm, sysctl is deprecated and removed from glibc. Unfortunately this means I don't have the header on my machine so I can't really debug this. Wild guess though is that those two builds end up linking against a slightly different version of |
I was trying to use it on my mac. Let me try to extract minimal headers/structs |
#define MAXCOMLEN 16
typedef int __int32_t;
typedef int boolean_t;
typedef long __darwin_time_t;
typedef __int32_t __darwin_suseconds_t;
typedef char * caddr_t;
typedef unsigned int u_int;
typedef unsigned int u_int32_t;
typedef u_int32_t fixpt_t;
typedef unsigned long long u_int64_t;
typedef u_int64_t u_quad_t;
typedef unsigned int __uint32_t;
typedef __uint32_t __darwin_sigset_t;
typedef __darwin_sigset_t sigset_t;
typedef unsigned char u_char;
typedef __int32_t __darwin_pid_t;
typedef __darwin_pid_t pid_t;
struct timeval
{
__darwin_time_t tv_sec; /* seconds */
__darwin_suseconds_t tv_usec; /* and microseconds */
};
struct itimerval {
struct timeval it_interval; /* timer interval */
struct timeval it_value; /* current value */
};
/* Exported fields for kern sysctls */
struct extern_proc4 {
union {
struct {
struct proc *__p_forw; /* Doubly-linked run/sleep queue. */
struct proc *__p_back;
} p_st1;
struct timeval __p_starttime; /* process start time */
} p_un;
struct vmspace *p_vmspace; /* Address space. */
struct sigacts *p_sigacts; /* Signal actions, state (PROC ONLY). */
int p_flag; /* P_* flags. */
char p_stat; /* S* process status. */
pid_t p_pid; /* Process identifier. */
pid_t p_oppid; /* Save parent pid during ptrace. XXX */
int p_dupfd; /* Sideways return value from fdopen. XXX */
/* Mach related */
caddr_t user_stack; /* where user stack was allocated */
void *exit_thread; /* XXX Which thread is exiting? */
int p_debugger; /* allow to debug */
boolean_t sigwait; /* indication to suspend */
/* scheduling */
u_int p_estcpu; /* Time averaged value of p_cpticks. */
int p_cpticks; /* Ticks of cpu time. */
fixpt_t p_pctcpu; /* %cpu for this process during p_swtime */
void *p_wchan; /* Sleep address. */
char *p_wmesg; /* Reason for sleep. */
u_int p_swtime; /* Time swapped in or out. */
u_int p_slptime; /* Time since last blocked. */
}; |
struct extern_proc4 {
u_int p_swtime; /* Time swapped in or out. */
u_int p_slptime; /* Time since last blocked. */
};
--added-- --added-- |
The type override system exists to allow people to manually wrap parts of code that Futhark might struggle with. This system also means that if Nim has an existing type that has the same name as a C defined type then the nim defined type will take precedence. In #115 it was discovered that defining `u_int` as `unsigned int` meant that Nims `uint` which is 64 bits long took precedence over the 32 bit long `u_int`. This caused structures to have incorrect sizes and invalid alignment. To help against this, and to warn users trying to implement their own types incorrectly, this warning has been added.
This adds the list of types defined in `system.nim` to the list of identifiers Futhark will consider as collisions. This means that the code from #115 will not redefine `u_int` to mean `uint` and break sizes and alignment, and hopefully avoid similar mistakes in the future.
Aha! Wow that's an inconvenient bug, and hard to catch. In 0.13.3 I've added a warning for when overridden types don't match in size, that should make these errors easier to catch in the future. I've also added a collision check for all the types in This last fix should mean that your code now works out of the box. Please try the code again and check. |
Did you ever get this tested? |
I changed my work macbook to lenovo. But if I remember correct it worked with simple example. Thank you |
nim-c-code:
nim-code:
Do you know what could be the reason? Thank you
The text was updated successfully, but these errors were encountered: