Jump to page: 1 2
Thread overview
February 19
#importc now successfully converts function-like C macros to #dlang function templates:

```C
#define ADD(a, b) a + b
```

is converted to a D function template:

```D
auto ADD(T1, T2)(T1 a, T2 b) { return a + b; }
```

which opens up a lot more automatic support for C macro use.

https://github.com/dlang/dmd/pull/16199

Thanks to @ibuclaw, @dkorpel, @thewilsonator, @Herringway, @ntrel, @tim-dlang for helping me get it over the finish line.
February 20
On Tuesday, 20 February 2024 at 02:07:45 UTC, Walter Bright wrote:
> #importc now successfully converts function-like C macros to #dlang function templates:
>
> ```C
> #define ADD(a, b) a + b
> ```
>
> is converted to a D function template:
>
> ```D
> auto ADD(T1, T2)(T1 a, T2 b) { return a + b; }
> ```
>
> which opens up a lot more automatic support for C macro use.
>
> https://github.com/dlang/dmd/pull/16199
>
> Thanks to @ibuclaw, @dkorpel, @thewilsonator, @Herringway, @ntrel, @tim-dlang for helping me get it over the finish line.

Yes!!!! Thanks to all for all of the hard work
February 20
On Tuesday, 20 February 2024 at 02:07:45 UTC, Walter Bright wrote:
> Thanks to @ibuclaw, @dkorpel, @thewilsonator, @Herringway, @ntrel, @tim-dlang for helping me get it over the finish line.

Great work (TM).
February 20
On 2/20/2024 2:13 PM, Bradley Chatha wrote:
> Great work (TM).

Thank you. I've known how to make it work for a while, and finally got around to getting it done. It's very satisfying to see it work.
February 21
On Tuesday, 20 February 2024 at 02:07:45 UTC, Walter Bright wrote:
> #importc now successfully converts function-like C macros to #dlang function templates:
>
> ```C
> #define ADD(a, b) a + b
> ```
>
> is converted to a D function template:
>
> ```D
> auto ADD(T1, T2)(T1 a, T2 b) { return a + b; }
> ```
>
> which opens up a lot more automatic support for C macro use.
>
> https://github.com/dlang/dmd/pull/16199
>
> Thanks to @ibuclaw, @dkorpel, @thewilsonator, @Herringway, @ntrel, @tim-dlang for helping me get it over the finish line.

Thanks 😇
February 21
On Tuesday, 20 February 2024 at 02:07:45 UTC, Walter Bright wrote:
> #importc now successfully converts function-like C macros to #dlang function templates:
>
> ```C
> #define ADD(a, b) a + b
> ```
>
> is converted to a D function template:
>
> ```D
> auto ADD(T1, T2)(T1 a, T2 b) { return a + b; }
> ```
>
> which opens up a lot more automatic support for C macro use.
>
> https://github.com/dlang/dmd/pull/16199
>
> Thanks to @ibuclaw, @dkorpel, @thewilsonator, @Herringway, @ntrel, @tim-dlang for helping me get it over the finish line.

Amazing! Congratulations to all concerned.
February 21

On Tuesday, 20 February 2024 at 02:07:45 UTC, Walter Bright wrote:

>

#importc now successfully converts function-like C macros to #dlang function templates:

#define ADD(a, b) a + b

is converted to a D function template:

auto ADD(T1, T2)(T1 a, T2 b) { return a + b; }

ImportC is now fantastically useful! However, does Exception connected behavior limit this?

The ImportC documentation says for Exception Handling that "ImportC is assumed to never throw exceptions. setjmp and longjmp are not supported".

I am unclear under what circumstances D throwing exceptions in the presence of ImportC works.

Reading that sentence carefully, it does not seem to imply that exceptions cannot occur in D code linked to C code compiled with ImportC in all cases. Of course if executing D code hasn't got ImportC code in its call chain then exception handling will work. But there are two other cases.

  1. I imagine that if C code calls D code which throws and the exception is caught in D code without unwinding the C part of the call stack this is OK. In some sense ImportC did not throw an exception in this case, even though it executed a call chain to do so, which could be interpreted as ImportC throwing an exception.

  2. What if D throws an exception that would supposedly unwind the C part of the call stack and be caught from D further up? I might guess this counts as ImportC throwing an exception and so is not OK, but I hope I am wrong.

Could you please explain the actual situation of ImportC in these cases?

February 21
On 2/21/2024 7:40 AM, Carl Sturtivant wrote:
> Could you please explain the actual situation of ImportC in these cases?

You can throw an exception in D code called by C code that is caught by D code.

C code does not have any constructs that require unwinding support, other than setjmp/longjmp which is not supported by ImportC.
February 21
On Wednesday, 21 February 2024 at 18:41:17 UTC, Walter Bright wrote:
> On 2/21/2024 7:40 AM, Carl Sturtivant wrote:
>> Could you please explain the actual situation of ImportC in these cases?
>
> You can throw an exception in D code called by C code that is caught by D code.
>
> C code does not have any constructs that require unwinding support, other than setjmp/longjmp which is not supported by ImportC.

Fantastic! I think we could informally call this no limitation at all.
February 28

On Tuesday, 20 February 2024 at 02:07:45 UTC, Walter Bright wrote:

>

#importc now successfully converts function-like C macros to #dlang function templates:

#define ADD(a, b) a + b

is converted to a D function template:

auto ADD(T1, T2)(T1 a, T2 b) { return a + b; }

which opens up a lot more automatic support for C macro use.

https://github.com/dlang/dmd/pull/16199

Thanks to @ibuclaw, @dkorpel, @thewilsonator, @Herringway, @ntrel, @tim-dlang for helping me get it over the finish line.

Hi Walter, Thanks for the great work.

I want to ask you to speedup the process for this ImportC issue: https://issues.dlang.org/show_bug.cgi?id=23926

I am use importC for a huge C header(700KB), with dmd nightly most of code work well.

without fix #23926, there is no easy way to fix this huge c code header that change constantly by upstream, this header is generate by amalgamation scripts.

There is 14K lines code, and so much function that accept nont-const struct pointer mixed const struct pointer. It is not impractical to add so much cast(Message*) into D code.

Please let me know what I can do to speedup the process to fix this problem.

Thanks in advance.

« First   ‹ Prev
1 2