This should technically be correct, no? pasted by zilti on Mon Oct 5 00:18:08 2020

(define dos_parameterdefinition_create
  (foreign-lambda* scheme-object ((c-string name)
                                  (int metaType))
    "struct ParameterDefinition pd = {.name = name, .metaType = metaType};"
    "C_word* ptr = C_alloc(1);"
    "C_return(C_structure(&ptr,C_SIZEOF_STRUCTURE(3),pd));"))

Second version pasted by zilti on Mon Oct 5 01:18:29 2020

(define dos_parameterdefinition_create
  (foreign-lambda* scheme-object ((c-string name)
                                  (int metaType))
    "struct ParameterDefinition pd = {.name = name, .metaType = metaType};"
    "C_word* ptr = C_alloc(C_SIZEOF_STRING(sizeof(pd)));"
    "C_return(C_bytevector(&ptr,sizeof(pd),(char*)&pd));"))

Final version? pasted by zilti on Mon Oct 5 01:28:01 2020

(define dos_parameterdefinition_create
  (foreign-primitive scheme-object ((c-string name)
                                    (int metaType))
    "struct ParameterDefinition pd = {.name = name, .metaType = metaType};"
    "C_word* ptr = C_alloc(C_SIZEOF_STRING(sizeof(pd)));"
    "C_return(C_bytevector(&ptr,sizeof(pd),(char*)&pd));"))

It segfaults pasted by zilti on Mon Oct 5 10:52:48 2020

(define dos_parameterdefinition_create
  (foreign-primitive scheme-object ((c-string name)
                                    (int metaType))
    "struct ParameterDefinition pd = {.name = name, .metaType = metaType};"
    "char pdc[sizeof(pd)];"
    "memcpy(pdc, &pd, sizeof(pdc));"
    "C_word* ptr = C_alloc(C_SIZEOF_STRING(sizeof(pdc)));"
    "C_return(C_bytevector(&ptr,C_SIZEOF_STRING(sizeof(pdc)),pdc));"))

(define dos_parameterdefinition_name
  (foreign-lambda* c-string ((blob sobj))
    "struct ParameterDefinition pd;"
    "memcpy(&pd, sobj, sizeof(sobj));"
    "C_return(pd.name);"))

It segfaults pasted by zilti on Mon Oct 5 11:17:18 2020

(define dos_parameterdefinition_create
  (foreign-primitive scheme-object ((c-string name)
                                    (int metaType))
    "char* pdname = (char*) C_alloc(strlen(name));"
    "memcpy(&pdname, name, strlen(name));"
    "struct ParameterDefinition pd = {.name = pdname, .metaType = metaType};"
    "char pdc[sizeof(pd)];"
    "memcpy(pdc, &pd, sizeof(pdc));"
    "C_word* ptr = C_alloc(C_SIZEOF_STRING(sizeof(pdc)));"
    "C_return(C_bytevector(&ptr,C_SIZEOF_STRING(sizeof(pdc)),pdc));"))

(define dos_parameterdefinition_name
  (foreign-lambda* c-string ((blob sobj))
    "C_return(((struct ParameterDefinition*)sobj)->name);"))

this seems to work added by Bunny351 on Mon Oct 5 11:38:20 2020

(import (chicken foreign))

#>
struct PD {char *name; int metaType;};
<#

(define dos_parameterdefinition_create
  (foreign-primitive scheme-object ((c-string name)
                                    (int metaType))
    "char* pdname = (char*) malloc(strlen(name)+1);"
    "strcpy(pdname, name);"
    "struct PD pd = {.name = pdname, .metaType = metaType};"
    "char pdc[sizeof(pd)];"
    "memcpy(pdc, &pd, sizeof(pdc));"
    "C_word* ptr = C_alloc(C_SIZEOF_STRING(sizeof(pdc)));"
    "C_return(C_bytevector(&ptr,sizeof(pdc),pdc));"))

(define dos_parameterdefinition_name
  (foreign-lambda* c-string ((blob sobj))
    "C_return(((struct PD*)sobj)->name);"))

(define x (dos_parameterdefinition_create "foo" 33))
(print (dos_parameterdefinition_name x))