+ return NULL;
+}
+static void psi_ffi_struct_type_dtor(void *type) {
+ ffi_type *strct = type;
+
+ if (strct->elements) {
+ ffi_type **ptr;
+
+ for (ptr = strct->elements; *ptr; ++ptr) {
+ free(*ptr);
+ }
+ free(strct->elements);
+ }
+ free(strct);
+}
+
+static ffi_type **psi_ffi_struct_type_elements(decl_struct *strct) {
+ size_t i, j, argc = strct->args->count << 2, nels = 0, offset = 0, align, padding;
+ ffi_type **els = calloc(argc + 1, sizeof(*els));
+
+ for (i = 0; i < strct->args->count; ++i) {
+ decl_arg *darg = strct->args->args[i];
+ ffi_type *type = malloc(sizeof(*type));
+
+ memcpy(type, psi_ffi_decl_arg_type(darg), sizeof(*type));
+
+ if (darg->layout->pos > offset) {
+ padding = darg->layout->pos - offset;
+ align = ((padding - 1) | (type->alignment - 1)) + 1;
+ if (align >= padding) {
+ padding = 0;
+ }
+ } else {
+ align = 0;
+ padding = 0;
+ }
+
+ if (padding) {
+ for (j = 0; j < padding; ++j) {
+ ffi_type *pad = malloc(sizeof(*pad));
+
+ ZEND_ASSERT(nels + 1 < argc);
+ memcpy(pad, &ffi_type_schar, sizeof(*pad));
+ els[nels++] = pad;
+ }
+ }
+
+ ZEND_ASSERT(nels + 1 < argc);
+ els[nels++] = type;
+//fprintf(stderr, "%s o:%d, a:%d, p:%d l:%d\n", darg->var->name, offset, align, padding, darg->layout->len);
+ offset += MAX(align, padding) + darg->layout->len;
+ }
+//fprintf(stderr, "%s s:%d o=%d\n", strct->name, strct->size, offset);
+ ZEND_ASSERT(offset <= strct->size);
+ if (offset < strct->size) {
+ padding = strct->size - offset;
+ for (j = 0; j < padding; ++j) {
+ ffi_type *pad = malloc(sizeof(*pad));
+
+ ZEND_ASSERT(nels + 1 < argc);
+ memcpy(pad, &ffi_type_schar, sizeof(*pad));
+ els[nels++] = pad;
+ }
+ }
+
+ return els;