stuchlej
(Mikoláš Stuchlík)
1
Hi,
I'm writing a program that heavily relies on types declared in C. I was wondering, whether there is a way to differentiate C types and Swift types.
Let's say I want to bind a pointer to a type but I only want to do it, if the type was declared in C and throw exception otherwise. So far the only difference I have noticed is, that all the C types belong to a module called __C.
To be more specific, I don't mind Swift types per-se. I just need to be sure, that the layout is done "the C way" and no calls to Swift runtime are made (so no retains etc.). At this time, the only thing stopping a programmer from invoking the code with incorrect type is a warning in documentation. Which seems insufficient to me when the result of incorrect usage of the code may lead to baaaad corruption.
dnadoba
(David Nadoba)
2
There is the unofficial _isPOD(_:) function you can use. As with all underscore APIs from swift this function might change or go away at any time.
1 Like
stuchlej
(Mikoláš Stuchlík)
3
Oh super useful, thanks!
I'm working on debugging tool, so it will need constant validation against language and library versions anyway :)
1 Like
tera
4
Note that "_isPOD" can return true for swift types. Those would be "ARC free" perhaps, but not necessarily "C-layout" compatible (should that matter).
2 Likes
stuchlej
(Mikoláš Stuchlík)
5
I have briefly reviewed the Builtin.swift file. What an incredible source of power
I can now do all kinds of things. This really made me happy!
1 Like
stuchlej
(Mikoláš Stuchlík)
6
Yes, thanks for pointing this out. I don't mind 
Edit: I think I can handle the layout issue with Mirror and MemoryLayout 
1 Like