-
Notifications
You must be signed in to change notification settings - Fork 616
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
intmax_t and uintmax_t problematic for some languages FFI #25
Comments
Yes, I've been thinking about that as well, though more for "warning: you're converting a larger type to a smaller type" reasons. I wonder if I could just make them |
Could use types like uint32_t or uint64_t |
In Rust I'm just mapping these to |
I'm tempted to just use int or maybe long, under the rationale that nothing should really exceed 2 billion objects anyway. I'm not sure if I'd be comfortable pinning to int64 if we ever move beyond 64-bit... I'm open to arguments for or against anything though :) |
For the Combobox, Box and Tab indices an unsigned int should be just fine The slider might benefit from using a floating point type for more flexibility, but I'm not sure of all the various OS backends support this. |
How does it deal with size_t? Could you do something like this? http://stackoverflow.com/a/9203792/3233 |
So what should it be, int or long? size_t might pose the same problems intmax_t pose; I'm not 100% sure. Anyone? @benpye? |
So the problem is that Define in your LibUI C config header: #ifndef UI_SIZE_T
#define UI_SIZE_T size_t
#endif
typedef UI_SIZE_T ui_size_t; Then in cmake config you allow a variable
In cmake config: if(BUILD_SIZE_T)
add_definitions("UI_SIZE_T=${BUILD_SIZE_T}")
endif() Then |
You can use the native integer size in C# with IntPtr but it's certainly not a brilliant solution. Using a fixed length integer would be the easiest for C# P/Invoke, either |
It's up to your which one you choose, I just chose 64 bit as it obviously supports 64 bit platforms, which are probably the default now. But I suspect it is unlikely sizes will exceed the range of max uint32_t. However if handles (e.g. opaque pointers) are necessary then 64 bit would be handy, or perhaps another type could be specified for this, but if/when necessary. As you say, |
If we have opaque pointers, then that really is when IntPtr is suitable. As On Mon, 6 Jun 2016 at 12:22 Billy Quith notifications@github.com wrote:
|
Leaning toward int, with a requirement that sizeof(int) >= 32 bits, as having 2 billion objects is already unrealistic and poses major usability problems. Design for the trivial case, after all. Any objections? This issue must be closed before an Alpha 4 can be released. I expect to tackle this and #88 in the short term. |
Do you mean as an addition to the change I suggested, or instead of? My suggestion seems to fix the C# issue. |
Which comment has the suggestion you are referring to? |
The one 3days ago. |
Ah. There are a few places where size_t is used right now for "size of C array" (such as uiDrawStrokeParams.Dashes/NumDashes). Every platform I know of has its own convention for dealing with array sizes. For instance, both C# and Go use But more important is that I can't just replace intmax_t with size_t because size_t is unsigned; I need to be able to represent -1, so that won't do. ssize_t is nonstandard. I'll probably just go with int. |
Switched all cases of |
I am currently writing a library for C# wrapping libui for .NET Core. I have generally found the library structured very well for being wrapped for usage in another language. One issue I have come across is the usage of
intmax_t
anduintmax_t
. C# has no equivalent for these types (and I suspect other languages also have this limitation), and as such I am currently assuming that they are 64 bit integers, but this could not be true. If the API could instead expose these as some fixed width integer then this would be much easier to deal with, especially when wanting to target any Windows, Linux or OS X system.The text was updated successfully, but these errors were encountered: