Attempt at DWT 64 bit port

Jacob Carlborg via Digitalmars-d-dwt digitalmars-d-dwt at puremagic.com
Tue Jun 24 12:06:10 PDT 2014


On 2014-06-24 02:30, ed wrote:
> I'm attempting a 64 bit port of DWT and I'd like some feedback on API
> changes.
>
> My initial preference was no changes to existing API in order to ease
> future updates from SWT proper. But of course that requires casts and I
> suspect they will bubble to the surface and be exposed to end-users of DWT.
>
> So now I'm leaning towards API changes of this sort:
>
>      /// Extension to String
>      public int indexOf( in char[] str,
>                          char searched,
>                          int fromIndex ){cast(int)...cast(int)...}
>
> becomes
>
>      /// Extension to String
>      public ptrdiff_t indexOf( in char[] str,
>                                char searched,
>                                ptrdiff_t fromIndex) {...}
>
>
> This maintains sign compatibility with the original API but may require
> some changes to existing code. For example:
>
> ---
> // Fails 64 bit, works 32 bit
> int idx = indexOf("astring", 't', 1);
>
>   // Works 64 bit, Fails 32 bit
> long idx = indexOf("astring", 't', 1);
>
> // Works 64 bit and 32 bit
> auto idx = indexOf("astring", 't', 1);
> ----
>
> Does anyone have an alternative preferred approach to portable 32/64 bit
> code?

I usually try to think like this, in some kind of priority list:

1. Follow system/native libraries - Example of this is when a system 
library uses pointers then the SWT code will use an "int/long". In DWT I 
would use the original pointer type

2. Follow the original SWT code - We want to make porting of future 
versions of SWT as easy as possible

3. Do what's most appropriate in D

In this case I would use "size_t" because that is the native type D uses 
for array indexes. This is what I've done in the Cocoa port, it's ported 
to support both 32bit and 64bit form the start.

> One possibility is separate code bases for 32 and 64 bit, as per SWT
> proper. This is not my preference but I am happy to do it if people feel
> it would be better this way.

I think it should be only one code base. SWT is actually only one code 
base. They have a tool that converts between 32bit and 64bit. They make 
separate releases but the it's only one repository. But D has language 
support that will make this easier: "alias", "version" and so on.

-- 
/Jacob Carlborg


More information about the Digitalmars-d-dwt mailing list