I think that I found answer overnight:

low level FFI just with ptr, but a bit higher level looks the ptr and do free 
if necessary The main point was not to pass high level value, but pointer for 
it, so the final result is:
    
    
    type LdapInt = object
    type Ldap = object
      r: ptr Ldap
    
    proc `=destroy`(x: var Ldap) =
      ldap_memfree x.r
    
    proc ldap_initialize(ldp: ptr LdapInit, url: cstring) {.importc.}
    
    var ld: Ldap
    ldap_initialize(ld.r, "url")
    
    
    Run

Reply via email to