digitalmars.D - importc and stb
- stb (6/6) Dec 16 2021 are we going to be able use https://github.com/nothings/stb with
- rikki cattermole (7/7) Dec 16 2021 In theory.
- Walter Bright (3/11) Dec 18 2021 We are having a problem with what to do with all the C extensions the sy...
- Adam D Ruppe (6/12) Dec 16 2021 note that some of these have already been ported to D like
- Guillaume Piolat (23/35) Dec 16 2021 More STB translations:
- Adam D Ruppe (10/13) Dec 16 2021 I might just steal that from you my image resizer has nice
- Guillaume Piolat (4/7) Dec 16 2021 Yup! STB do receive improvements over time for example more
- Guillaume Piolat (4/13) Dec 16 2021 So: another future win for ImportC! It is already receiving lots
- Walter Bright (2/6) Dec 18 2021 The updating problem is one of the major motivations for ImportC.
- bachmeier (22/28) Dec 16 2021 I just tried the first three files: stb_c_lexer.h, stb_divide.h
- Elronnd (3/6) Dec 16 2021 Oh, my, that's bad. GCC __builtins don't generally evaluate more
- bachmeier (4/11) Dec 16 2021 This is why most of us should stay away from C. I honestly don't
- Abdulhaq (4/17) Dec 16 2021 :-) it rotates the MSB right 8 places into the LSB, rotates the
- Patrick Schluter (3/16) Dec 17 2021 You're not serious, aren't you? Except for the typecast syntax
- Temtaime (3/3) Dec 18 2021 There is https://github.com/Temtaime/stb also
- bachmeier (9/37) Dec 16 2021 So over lunch I decided to take another look. I downloaded Ian's
- Walter Bright (2/5) Dec 18 2021 That is indeed the point of ImportC.
- stb (16/24) Dec 20 2021 i was waiting for this for about 10 years, better late than
- Walter Bright (3/9) Dec 20 2021 You're welcome!
are we going to be able use https://github.com/nothings/stb with importc? these are header only libraries and i use stb (and similar libraries) all the time. there is no reason for me to use c/c++ for tools if importc can pull this off.
Dec 16 2021
In theory. Recently Iain let me know that zlib's test suite is now passing with ImportC. So the things that are missing are the macro preprocessor and whatever extensions those files use. Once they have been sorted out (the macro preprocessor is the big one of the two), then sure, they should work, if not either it isn't C or its a bug.
Dec 16 2021
On 12/16/2021 2:44 AM, rikki cattermole wrote:In theory. Recently Iain let me know that zlib's test suite is now passing with ImportC. So the things that are missing are the macro preprocessor and whatever extensions those files use. Once they have been sorted out (the macro preprocessor is the big one of the two), then sure, they should work, if not either it isn't C or its a bug.We are having a problem with what to do with all the C extensions the system .h files rely on.
Dec 18 2021
On Thursday, 16 December 2021 at 10:38:38 UTC, stb wrote:are we going to be able use https://github.com/nothings/stb with importc? these are header only libraries and i use stb (and similar libraries) all the time. there is no reason for me to use c/c++ for tools if importc can pull this off.note that some of these have already been ported to D like https://github.com/adamdruppe/arsd/blob/master/ttf.d though i haven't updated it back from upstream for a while. but i think the import C should work with those if you can set up the macros in a separate file ahead of time.
Dec 16 2021
On Thursday, 16 December 2021 at 13:38:06 UTC, Adam D Ruppe wrote:On Thursday, 16 December 2021 at 10:38:38 UTC, stb wrote:More STB translations: - `stb_image.h` v2.27 => [D translation](https://github.com/AuburnSounds/Dplug/blob/master/graphics/dplug/graphics/pngload.d) I believe this is the fastest/resource efficient PNG loading available in D. That one is stripped for only PNG decoding only, it's useful if you want 16-bit PNG and the latest STB optimizations. - `stb_image_resize.h` v0.96: => [D translation](https://github.com/AuburnSounds/Dplug/blob/master/graphics/dplug/graphics/stb_image_resize.d) I believe this is the fastest/memory-aware image resizing available in D. It is an image resizer with an excellent quality. - `stb_truetype.h` v0.7: => [D translation](https://github.com/AuburnSounds/Dplug/blob/master/graphics/dplug/graphics/stb_truetype.d) - `stb_vorbis.h` v1.22: => [D translation](https://github.com/AuburnSounds/audio-formats/blob/master/source/audioformats/stb_vorbis2.d) Most of the translations can't be used as-is in our codebase anyway, so they were all tweaked to fit their D purpose (eg: original might have ARM intrinsics).are we going to be able use https://github.com/nothings/stb with importc? these are header only libraries and i use stb (and similar libraries) all the time. there is no reason for me to use c/c++ for tools if importc can pull this off.note that some of these have already been ported to D like https://github.com/adamdruppe/arsd/blob/master/ttf.d though i haven't updated it back from upstream for a while. but i think the import C should work with those if you can set up the macros in a separate file ahead of time.
Dec 16 2021
On Thursday, 16 December 2021 at 16:04:34 UTC, Guillaume Piolat wrote:- `stb_image_resize.h` v0.96:I might just steal that from you my image resizer has nice quality but is awfully slow...- `stb_truetype.h` v0.7:But you might want to steal my truetype thing cuz i have a much newer version than you do.- `stb_vorbis.h` v1.22:hah my stb_vorbis is 1.10 so maybe i'll take yours. though i've done bug fixes to mine.... come to think of it i think we worked on this together before, the bugfix was upstream, you updated and i just cherry picked it.
Dec 16 2021
On Thursday, 16 December 2021 at 16:47:00 UTC, Adam D Ruppe wrote:Yup! STB do receive improvements over time for example more recent stb_image had faster PNG loading. It could be nice if stb_truetype has eg. better antialiasing.- `stb_truetype.h` v0.7:But you might want to steal my truetype thing cuz i have a much newer version than you do.
Dec 16 2021
On Thursday, 16 December 2021 at 17:03:30 UTC, Guillaume Piolat wrote:On Thursday, 16 December 2021 at 16:47:00 UTC, Adam D Ruppe wrote:So: another future win for ImportC! It is already receiving lots of attention for a new feature.Yup! STB do receive improvements over time for example more recent stb_image had faster PNG loading. It could be nice if stb_truetype has eg. better antialiasing.- `stb_truetype.h` v0.7:But you might want to steal my truetype thing cuz i have a much newer version than you do.
Dec 16 2021
On 12/16/2021 5:38 AM, Adam D Ruppe wrote:note that some of these have already been ported to D like https://github.com/adamdruppe/arsd/blob/master/ttf.d though i haven't updated it back from upstream for a while.The updating problem is one of the major motivations for ImportC.
Dec 18 2021
On Thursday, 16 December 2021 at 10:38:38 UTC, stb wrote:are we going to be able use https://github.com/nothings/stb with importc? these are header only libraries and i use stb (and similar libraries) all the time. there is no reason for me to use c/c++ for tools if importc can pull this off.I just tried the first three files: stb_c_lexer.h, stb_divide.h and stb_ds.h. The first two compiled without issues: ``` gcc -E -P stb_c_lexer.h > stb_c_lexer_d.c ldmd2 -c stb_c_lexer_d.c gcc -E -P stb_divide.h > stb_divide_d.c ldmd2 -c stb_divide_d.c ``` The last gave errors: ``` gcc -E -P stb_ds.h > stb_ds_d.c ldmd2 -c stb_ds_d.c ``` The errors are due to the insertion of stuff in the preprocessing step that's not C11. There are solutions for some of these (such as https://github.com/ibuclaw/importC/blob/main/src/keywords.c.in) but I didn't dig into it any further, since I have never used those libraries. The first error that comes up is due to `__restrict` rather than plain `restrict`.
Dec 16 2021
On Thursday, 16 December 2021 at 14:26:42 UTC, bachmeier wrote:https://github.com/ibuclaw/importC/blob/main/src/keywords.c.in#define __builtin_bswap16(x) ((u_int16_t) ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8)))Oh, my, that's bad. GCC __builtins don't generally evaluate more than once. And this could just be an inline function anyway.
Dec 16 2021
On Thursday, 16 December 2021 at 18:38:10 UTC, Elronnd wrote:On Thursday, 16 December 2021 at 14:26:42 UTC, bachmeier wrote:This is why most of us should stay away from C. I honestly don't know what that incantation is doing, even though I've written a fair amount of C over the years.https://github.com/ibuclaw/importC/blob/main/src/keywords.c.in#define __builtin_bswap16(x) ((u_int16_t) ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8)))Oh, my, that's bad. GCC __builtins don't generally evaluate more than once. And this could just be an inline function anyway.
Dec 16 2021
On Thursday, 16 December 2021 at 19:04:21 UTC, bachmeier wrote:On Thursday, 16 December 2021 at 18:38:10 UTC, Elronnd wrote::-) it rotates the MSB right 8 places into the LSB, rotates the LSB left 8 places, and ORs/overlays them both together, to effectively swap the MSB and LSB bytesOn Thursday, 16 December 2021 at 14:26:42 UTC, bachmeier wrote:This is why most of us should stay away from C. I honestly don't know what that incantation is doing, even though I've written a fair amount of C over the years.https://github.com/ibuclaw/importC/blob/main/src/keywords.c.in#define __builtin_bswap16(x) ((u_int16_t) ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8)))Oh, my, that's bad. GCC __builtins don't generally evaluate more than once. And this could just be an inline function anyway.
Dec 16 2021
On Thursday, 16 December 2021 at 19:04:21 UTC, bachmeier wrote:On Thursday, 16 December 2021 at 18:38:10 UTC, Elronnd wrote:You're not serious, aren't you? Except for the typecast syntax the expression is also valid D.On Thursday, 16 December 2021 at 14:26:42 UTC, bachmeier wrote:This is why most of us should stay away from C. I honestly don't know what that incantation is doing, even though I've written a fair amount of C over the years.https://github.com/ibuclaw/importC/blob/main/src/keywords.c.in#define __builtin_bswap16(x) ((u_int16_t) ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8)))Oh, my, that's bad. GCC __builtins don't generally evaluate more than once. And this could just be an inline function anyway.
Dec 17 2021
There is https://github.com/Temtaime/stb also Outdated a little and missing some define macros, but i'll update it if someone needs it
Dec 18 2021
On Thursday, 16 December 2021 at 14:26:42 UTC, bachmeier wrote:On Thursday, 16 December 2021 at 10:38:38 UTC, stb wrote:So over lunch I decided to take another look. I downloaded Ian's fixes as fixes.h and then did ``` gcc -E -P stb_ds.h > stb_ds_d.c gcc -E -P -include fixes.h stb_ds_d.c > stb_ds_d2.c ldmd2 -c stb_ds_d2.c ``` Compiled without any error messages or warnings.are we going to be able use https://github.com/nothings/stb with importc? these are header only libraries and i use stb (and similar libraries) all the time. there is no reason for me to use c/c++ for tools if importc can pull this off.I just tried the first three files: stb_c_lexer.h, stb_divide.h and stb_ds.h. The first two compiled without issues: ``` gcc -E -P stb_c_lexer.h > stb_c_lexer_d.c ldmd2 -c stb_c_lexer_d.c gcc -E -P stb_divide.h > stb_divide_d.c ldmd2 -c stb_divide_d.c ``` The last gave errors: ``` gcc -E -P stb_ds.h > stb_ds_d.c ldmd2 -c stb_ds_d.c ``` The errors are due to the insertion of stuff in the preprocessing step that's not C11. There are solutions for some of these (such as https://github.com/ibuclaw/importC/blob/main/src/keywords.c.in) but I didn't dig into it any further, since I have never used those libraries. The first error that comes up is due to `__restrict` rather than plain `restrict`.
Dec 16 2021
On Thursday, 16 December 2021 at 19:00:20 UTC, bachmeier wrote:So over lunch I decided to take another look. I downloaded Ian's fixes as fixes.h and then did ``` gcc -E -P stb_ds.h > stb_ds_d.c gcc -E -P -include fixes.h stb_ds_d.c > stb_ds_d2.c ldmd2 -c stb_ds_d2.c ``` Compiled without any error messages or warnings.Since I'm looking for an opportunity to procrastinate, I created a repo. One file still results in errors from LDC. The others all compile. https://github.com/bachmeil/stb
Dec 16 2021
On Thursday, 16 December 2021 at 20:56:26 UTC, bachmeier wrote:On Thursday, 16 December 2021 at 19:00:20 UTC, bachmeier wrote:All but two functions in stb compile. Repo has been updated with the preprocessed C files in the unmodified/ directory.So over lunch I decided to take another look. I downloaded Ian's fixes as fixes.h and then did ``` gcc -E -P stb_ds.h > stb_ds_d.c gcc -E -P -include fixes.h stb_ds_d.c > stb_ds_d2.c ldmd2 -c stb_ds_d2.c ``` Compiled without any error messages or warnings.Since I'm looking for an opportunity to procrastinate, I created a repo. One file still results in errors from LDC. The others all compile. https://github.com/bachmeil/stb
Dec 19 2021
On 12/16/2021 2:38 AM, stb wrote:are we going to be able use https://github.com/nothings/stb with importc? these are header only libraries and i use stb (and similar libraries) all the time. there is no reason for me to use c/c++ for tools if importc can pull this off.That is indeed the point of ImportC.
Dec 18 2021
On Saturday, 18 December 2021 at 21:49:31 UTC, Walter Bright wrote:On 12/16/2021 2:38 AM, stb wrote:i was waiting for this for about 10 years, better late than never. some still won't understand how huge this feature is, talking about complexity added to the language. compared to its benefits the complexity (which could probably be deferred to llvm etc..) added is nothing. when matured, wrappers/wrapper-versions will be obsolete for 100% of the battle tested libraries, and going to reduce the work needed for the obscure/extension-heavy libraries. one of the bigger if not the biggest starting point of c++ was its c backwards compatibility. with importc you have best of both worlds. you have backwards/foreign compatibility with c libraries and since this is just an `include "path-to-c"` you do not contaminate d with c syntax. thank you walter!are we going to be able use https://github.com/nothings/stb with importc? these are header only libraries and i use stb (and similar libraries) all the time. there is no reason for me to use c/c++ for tools if importc can pull this off.That is indeed the point of ImportC.
Dec 20 2021
On 12/20/2021 3:01 AM, stb wrote:one of the bigger if not the biggest starting point of c++ was its c backwards compatibility. with importc you have best of both worlds. you have backwards/foreign compatibility with c libraries and since this is just an `include "path-to-c"` you do not contaminate d with c syntax. thank you walter!You're welcome! I'm mad at myself for not doing this long ago.
Dec 20 2021