need help to use C++ callback from garnet

2024-05-29 Thread Dakota via Digitalmars-d-learn
I try use 
https://github.com/microsoft/garnet/blob/main/libs/storage/Tsavorite/cc/src/device/native_device_wrapper.cc from D



Not sure how to make this work with D:

```c++
	EXPORTED_SYMBOL FASTER::core::Status 
NativeDevice_ReadAsync(NativeDevice* device, uint64_t source, 
void* dest, uint32_t length, FASTER::core::AsyncIOCallback 
callback, void* context) {
		return device->ReadAsync(source, dest, length, callback, 
context);

}

	EXPORTED_SYMBOL FASTER::core::Status 
NativeDevice_WriteAsync(NativeDevice* device, const void* source, 
uint64_t dest, uint32_t length, FASTER::core::AsyncIOCallback 
callback, void* context) {
		return device->WriteAsync(source, dest, length, callback, 
context);

}
```

I need to define `FASTER::core::AsyncIOCallback callback` from D, 
any way to workaround ? (like modify garnet source code to 
support pass a C function callback)


I am newbie to C++ and D, any help will be appreciate


question about ctfe init importC zero length array of struct

2024-02-28 Thread Dakota via Digitalmars-d-learn

This is the type defined from c code import by importC:


```c
struct A {
   int count;
   int[] i;
}
```

This kind data need to be init as const to avoid runtime cost, 
and need to be done from D code.



how can I do this ?


To put code into D source,  I can use "-i=package" to 
automatically import the only need part without rebuild it, and 
avoid the problem of importC path search. (and there is type 
wrapper inside D code).


I can fix it with a template type, the cost is very slow build 
time. (because there is a lot diff auto generate type)



Any suggestions how to handle this fast and simple ?





Re: need help with simple importC

2024-02-26 Thread Dakota via Digitalmars-d-learn

On Monday, 26 February 2024 at 07:44:02 UTC, Dakota wrote:

I am use importC from linux, get this error:


```sh
/usr/include/x86_64-linux-gnu/bits/floatn-common.h(214): Error: 
illegal combination of type specifiers
/usr/include/x86_64-linux-gnu/bits/floatn-common.h(251): Error: 
illegal combination of type specifiers
/usr/include/x86_64-linux-gnu/bits/floatn-common.h(268): Error: 
illegal combination of type specifiers
/usr/include/x86_64-linux-gnu/bits/floatn-common.h(285): Error: 
illegal combination of type specifiers
/usr/include/x86_64-linux-gnu/bits/floatn-common.h(285): Error: 
illegal type combination

```

[...]



I use ldmd2 1.37.0-beta1 trigger this error.


change to dmd v2.107.1-rc.1 fix the problem.


Re: importC with gc-sections not work on linux

2024-02-26 Thread Dakota via Digitalmars-d-learn
On Monday, 26 February 2024 at 12:33:02 UTC, Richard (Rikki) 
Andrew Cattermole wrote:

On 27/02/2024 1:28 AM, Dakota wrote:
When I use importC to build a c library, there is a lot unused 
symbol missing.


I try add `-L--gc-sections` to dmd to workaround this issue.


This removes symbols, not keeps them.

You want the linker flag: ``--no-gc-sections``

"Enable garbage collection of unused input sections. It is 
ignored on targets that do not support this option. The default 
behaviour (of not performing this garbage collection) can be 
restored by specifying ‘--no-gc-sections’ on the command line. 
Note that garbage collection for COFF and PE format targets is 
supported, but the implementation is currently considered to be 
experimental."


https://sourceware.org/binutils/docs/ld/Options.html


I need remove symbol, since the problem is some symbol from 
importC reference to undefined symbol(need to be implement in d, 
but they will never used).



after remove the unused symbol,  I don't need to add the 
implement all of them.




importC with gc-sections not work on linux

2024-02-26 Thread Dakota via Digitalmars-d-learn
When I use importC to build a c library, there is a lot unused 
symbol missing.


I try add `-L--gc-sections` to dmd to workaround this issue.


I also try `-L-dead_strip` on macOS, it work as expected.


I do some google, some one suggestion use with 
`-ffunction-sections`, `-f fdata-sections`,  dmd seems not 
support it.



Any tips to work this around ?


Re: importC error Error: undefined identifier `__builtin_unreachable`

2024-02-26 Thread Dakota via Digitalmars-d-learn
On Monday, 26 February 2024 at 08:18:53 UTC, Richard (Rikki) 
Andrew Cattermole wrote:


On 26/02/2024 9:04 PM, Dakota wrote:

I try one more importC case, get this error:

```sh
Error: undefined identifier `__builtin_unreachable`
```

any tips to fix this?


Reported: https://issues.dlang.org/show_bug.cgi?id=24413


Thanks.

can you help add one more bugs:

```sh
 Error: undefined identifier `__builtin_clz`
```


importC error Error: undefined identifier `__builtin_unreachable`

2024-02-26 Thread Dakota via Digitalmars-d-learn

I try one more importC case, get this error:

```sh
Error: undefined identifier `__builtin_unreachable`
```

any tips to fix this?