-
Notifications
You must be signed in to change notification settings - Fork 15
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
Zero-cost const D wrapping of non-const C function, sane? #42
Comments
|
There's no chance of const causing a link error. I think it's fine to describe the API using D's typesystem in a way that goes beyond the C interfaces. |
|
Cool, thanks. Before changing DAllegro5 here, I'd like to discuss this with more Allegro 5 devs as a potential change in the Allegro 5 C API: Make the C API const-correct. C has If A5 doesn't get |
|
I've asked this in the D Learn forum and on allegro.cc's development forum. The problem with the Without guarantee (which should ideally end up in the C API), maybe we shouldn't change the bindings here, and instead I should continue to cast. |
|
I believe we shouldn't take According to Elias in the linked a.cc thread, A5 deliberately doesn't allow |
Consider
al_get_bitmap_width(ALLEGRO_BITMAP* b). This function doesn't mutateband should ideally be callable with aconst(ALLEGRO_BITMAP)*in usercode.Allegro 5 doesn't offer a const-correct API, but DAllegro5 has C linkage which looks only at the function's name.
constis merely a noble compile-time check in C. :-P I've abused this, and changed my local DAllegro5 to declare like this:I.e., I added
inbefore the bitmap arguments.Problems: I assume A5 will never modify
*b. A5 doesn't promise this (it is not const-correct) and the wrapper has no chance to detect an eventual change in A5, even though this is unlikely. I didn't get linker errors (Arch 64-bit, building with dmd), that makes me very happy, but who knows if some system out there will check more harshly.Would you consider such a modification sane for production? Or should const-correct user code cast its const bitmaps to mutable bitmaps before calling DAllegro5?
If this is sane, what functions would be OK to call with const bitmaps to not break any D const promises? Getting height and width, most likely. Maybe also drawing from const bitmap to nonconst bitmap?
The text was updated successfully, but these errors were encountered: