JuliaLang/julia — pull request #2818 by vtjnash (2013-04-10 21:55:20+00:00)
Title: WIP: types as C-structs

This is a first pass at giving pointers to julia types easy compatibility with C. This is done by "hiding" the type and GC information before the data, and shifting all references in the julia source by 1 to match. What this would mean for the user is that

```julia
type A
a::Int
end
type B
a::A
end
```
can be passed to a C function expecting:
```c
typedef struct _A {
int a;
} A;
typedef struct _B {
*A a;
} B;
```
If the user is receiving data from C (e.g. anything not created by Julia's GC), then they must instead declare it as `Ptr{A}` and access with unsafe_ref (I'm wondering if it might be more appropriate to introduce another type for this purpose, but thats a separate issue I'll go into later).

If @JeffBezanson approves of this, I'll go back through and clean this up some to make it ready to merge. TODO items include:
- [ ] remove some casts that are now no-ops
- [ ] figure out what emit_arraysize is doing (and replace with offsetof for better maintainability)
- [ ] finish fixing OVERLAP_TUPLE_LEN
- [ ] stop over-allocating types by sizeof(void*) bytes in alloc_big, and check if there's double counting anywhere else (or conversely, fully move it to alloc_big)