[Mono-dev] Fixing KeventWatcher: dealing with 32 / 64 bit operating systems

Robert Jordan robertj at gmx.net
Sat Sep 19 08:07:31 EDT 2009


Romain Tartière wrote:
> On Sat, Sep 19, 2009 at 11:46:06AM +0200, Robert Jordan wrote:
>> For *BSD, timespec is declared like this in native code:
>>
>> struct timespec {
>> 	time_t  tv_sec;         /* seconds */
>> 	long    tv_nsec;        /* and nanoseconds */
>> };
>>
>> while "time_t" is an "int32_t" on 32-bit and "int64_t" on 64-bit.
>> Long is "int32_t" on 32-bit and "int64_t" on 64-bit, so we can
>> use IntPtr in the C# p/invoke declaration:
>>
>> struct timespec {
>> 	public IntPtr tv_sec;
>> 	public IntPtr tv_usec;
>> }
> 
> Yes, I am examinating this.  I am just unsure about how ugly /
> acceptable it is to:
> 
>   - Replace "ev.data = 0" with "ev.data = IntPtr.Zero";
>   - Replace "ev.ident = fd" with "ev.ident = (IntPtr)fd".

It's far better than duplicating these structs. I wonder why
fd can't be declared as IntPtr as well, if it's not platform
agnostic.

> Another related point, the requests Hashtable keys are (depending of the
> instruction that use them) use with int (4 bytes, plateform agnostic) or
> long.  Is it okay to "requests [(IntPtr)fd] = data" ?

It's unrelated and irrelevant. Hashtable's keys are actually objects.

Robert



More information about the Mono-devel-list mailing list