SiegeLord / DAllegro5

D binding to the Allegro5 game development library
Other
42 stars 15 forks source link

`in`-Parameters in `extern(C)`: Many Warnings Since DMD 2.104.0 #53

Closed SimonN closed 1 year ago

SimonN commented 1 year ago

DAllegro5 4.0.4 for Allegro 5.2.0

The D keyword in for function parameters means scope const ref and DMD 2.104.0, released 2023-06-01, is beginning to warn about using in during extern(C). More information:

Using DMD 2.104.0, DAllegro5 now builds with many warnings:

Starting Performing "unittest" build using /usr/bin/dmd for x86_64.
Building allegro 4.0.4+5.2.0: building configuration [allegro-test-no-libs]
allegro5/al_debug.d(5,7): Deprecation: using `in` parameters with `extern(C)` functions is deprecated
allegro5/al_debug.d(5,7):        parameter `expr` declared as `in` here
allegro5/al_debug.d(5,7): Deprecation: using `in` parameters with `extern(C)` functions is deprecated
allegro5/al_debug.d(5,7):        parameter `file` declared as `in` here
allegro5/al_debug.d(5,7): Deprecation: using `in` parameters with `extern(C)` functions is deprecated
allegro5/al_debug.d(5,7):        parameter `func` declared as `in` here
allegro5/al_debug.d(6,7): Deprecation: using `in` parameters with `extern(C)` functions is deprecated
allegro5/al_debug.d(6,7):        parameter `__anonymous_param` declared as `in` here
allegro5/bitmap_io.d(18,2): Deprecation: using `in` parameters with `extern(C)` functions is deprecated
allegro5/bitmap_io.d(18,2):        parameter `filename` declared as `in` here
allegro5/bitmap_io.d(20,2): Deprecation: using `in` parameters with `extern(C)` functions is deprecated
allegro5/bitmap_io.d(20,2):        parameter `filename` declared as `in` here
[... many more of these ...]
SimonN commented 1 year ago

Typical violation:

R al_foo(in X* x);

Here, X can be void, int, char, ALLEGRO_USTR, ...

With what should we replace in X*? I believe it should be const(X)* because C is happy when we forward-declare a function with parameter const X* and implement it using const X const*. Or do you have other ideas?

SiegeLord commented 1 year ago

Yes, I think const(X)* is most appropriate. Technically D's const is transitive and C's const is head-const, so I don't know precisely whether using D's const for C bindings is even appropriate, but it's probably fine since we're dealing with opaque and primitive types here.

Thanks for looking into this.