Bug 22880 – importC: support __restrict__ __signed__ __asm__

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-03-15T16:35:21Z
Last change time
2022-03-25T22:32:48Z
Keywords
ImportC, pull
Assigned to
No Owner
Creator
Andrea Fontana

Comments

Comment #0 by trikkuz — 2022-03-15T16:35:21Z
It seems that both gcc and clang on linux use __restrict as keyword. gcc -c test.c cat test.c ---- int * restrict a; int * __restrict b; int * __restrict__ c; ---- gcc -std=c11 -E test.c > test.i cat test.i --- # 0 "test.c" # 0 "<built-in>" # 0 "<command-line>" # 1 "/usr/include/stdc-predef.h" 1 3 4 # 0 "<command-line>" 2 # 1 "test.c" int * restrict a; int * __restrict b; int * __restrict__ c; --- But: dmd test.i --- test.c(2): Error: missing comma or semicolon after declaration of `__restrict`, found `b` instead test.c(3): Error: missing comma or semicolon after declaration of `__restrict__`, found `c` instead ---
Comment #1 by trikkuz — 2022-03-15T16:50:20Z
The same goes for __asm__ __extension__ and so on...
Comment #2 by trikkuz — 2022-03-16T09:59:41Z
(using libtcc preprocessing could be done automatically from dmd in a few lines)
Comment #3 by bugzilla — 2022-03-19T06:20:10Z
The idea is to #include <importc.h> when preprocessing. This file, https://github.com/dlang/druntime/blob/master/src/importc.h defines a bunch of macros to deal with extensions used by various compilers. gcc's system #includes only use `__restrict` as far as I can tell, and there's a macro for it: https://github.com/dlang/druntime/blob/master/src/importc.h#L21 __restrict__ isn't there. If you find __restrict__ being used in system #includes, please let us know. In the meantime, you can just: #define __restrict__ __restrict or something like that to get things moving for you.
Comment #4 by trikkuz — 2022-03-19T13:25:37Z
Hi Walter! tl;dr: missing #define __asm__ asm #define __signed__ ---- I did the same trick, using a file with a lot of define. I was trying to compile some (single file) c libraries in c. It almost works with your "importc.h" . For example mongoose https://github.com/cesanta/mongoose (8k+ stars on github) is just a simple two-files library. Using tinycc as preprocessor (tcc -E) I can actually embed it in a d project (not only the .h but the whole library). I use tcc since it generates simpler preprocessed files (with few extra keyboards). For this library the only missing define is __asm__ (also for gcc, clang) This work: cat test.c: // NOT: #define __asm__ #define __asm__ asm #include "importc.h" #include "mongoose.c" tcc -E test.c > mongoose.i dmd -c mongoose.i With another similar project the problem is with __signed__ on a standard header
Comment #5 by dlang-bot — 2022-03-24T07:35:10Z
@WalterBright created dlang/druntime pull request #3785 "fix Issue 22880 - importC: support __restrict__ __signed__ __asm__" fixing this issue: - fix Issue 22880 - importC: support __restrict__ __signed__ __asm__ https://github.com/dlang/druntime/pull/3785
Comment #6 by dlang-bot — 2022-03-25T22:32:48Z
dlang/druntime pull request #3785 "fix Issue 22880 - importC: support __restrict__ __signed__ __asm__" was merged into master: - 9b8de8d85b2a1213741a1401313c61827e410ea8 by Walter Bright: fix Issue 22880 - importC: support __restrict__ __signed__ __asm__ https://github.com/dlang/druntime/pull/3785