From: Andreas Haas Date: 2006-06-02T09:22:31+09:00 Subject: How to pass const char *vect[] to C via Ruby/DL? Hi all, I'm having problems to understand how to build-up "const char *vect[]" data for passing to a C function that I wish to call via Ruby/DL: # ----------------- int setv(const char *ids[]) { while (*ids) { printf("setv: %s\n", ids[0]); ids++; } } # ----------------- My current Ruby program looks like this: # ----------------- #!/usr/bin/ruby require 'dl/import' def setv(ary) setv = $lib['setv', 'IP'] ids = DL.malloc(DL.sizeof('S')*(ary.size + 1)) i = 0 ary.each do |s| ids[DL.sizeof('S')*i] = s.to_ptr i += 1 end # ids[3] = nil ? r,r1 = setv.call(ids.ref) end $lib = DL.dlopen('lib.dylib') setv(["1", "2", "3"]) # ----------------- but I get a SEGV and it is not complete anyways. Instead of ids[DL.sizeof('S')*i] = s.to_ptr I already tried ids[DL.sizeof('S')*i] = s and other variations I could think of ... You know: I can imagine there were better means for passing string vectors to C, yet the C function interface as such is given. So any help or hint is greatly appreciated! Best regards, Andreas