Example with sprintf & %f from cffi manual crashes clisp on cygwin
Hello, The following example from section 10 of the cffi documentation is causing a segmentation fault on clisp on cygwin: (defcfun "sprintf" :int (str :pointer) (control :string) &rest) CFFI> (with-foreign-pointer-as-string (s 100) (sprintf s "%c %d %.2f %s" :char 90 :short 42 :float 3.1415 :string "super-locrian")) => "A 42 3.14 super-locrian" I replaced :float pi with :float 3.1415, as ``pi'' is long-float - I wanted to remove this as a possible cause. At first I thought it was the %s for the string, but it may actually be the %.2f. - By itself %f, it does not correctly process floats, emitting ``f''. - If followed by other codes, it swallows them - If followed by a string, causes a segmentation fault CL-USER> (cffi:with-foreign-pointer-as-string (s 100) (sprintf s "%s" :string "super-locrian")) "super-locrian" CL-USER> (cffi:with-foreign-pointer-as-string (s 200) (sprintf s "%.2f" :float 3.1415)) "f" CL-USER> (cffi:with-foreign-pointer-as-string (s 200) (sprintf s "%.2f %c" :float 3.1415 :char 65)) "f " CL-USER> (cffi:with-foreign-pointer-as-string (s 200) (sprintf s "%.2f %s %c" :float 3.1415 :string "five" :char 65)) Segmentation fault I'll try this on Linux/SBCL when I get back to work on Monday. Mirko
Mirko Vukovic <mirko.vukovic@gmail.com> writes:
The following example from section 10 of the cffi documentation is causing a segmentation fault on clisp on cygwin:
The varargs support in CFFI makes some assumptions that might not be true on Windows, I suppose. Is this x86 or x86-64? Cheers, Luís
On Mon, Jul 1, 2013 at 9:04 AM, Luís Oliveira <luismbo@gmail.com> wrote: > Mirko Vukovic <mirko.vukovic@gmail.com> writes: > > > The following example from section 10 of the cffi documentation is > > causing a segmentation fault on clisp on cygwin: > > The varargs support in CFFI makes some assumptions that might not be > true on Windows, I suppose. Is this x86 or x86-64? > > It's complicated: - The machine is X86-64 running Windows 7 - I am using clisp 2.48 which is part of the cygwin distribution - cygwin is 32-bit - I assume that clisp is also 32 bit - The version of gcc (for what it's worth) is 4.5.3 Mirko
On Mon, Jul 1, 2013 at 9:24 AM, Mirko Vukovic <mirko.vukovic@gmail.com>wrote: > On Mon, Jul 1, 2013 at 9:04 AM, Luís Oliveira <luismbo@gmail.com> wrote: > >> Mirko Vukovic <mirko.vukovic@gmail.com> writes: >> >> > The following example from section 10 of the cffi documentation is >> > causing a segmentation fault on clisp on cygwin: >> >> The varargs support in CFFI makes some assumptions that might not be >> true on Windows, I suppose. Is this x86 or x86-64? >> >> It's complicated: > - The machine is X86-64 running Windows 7 > - I am using clisp 2.48 which is part of the cygwin distribution > - cygwin is 32-bit > - I assume that clisp is also 32 bit > - The version of gcc (for what it's worth) is 4.5.3 > > Mirko > Your comment brings to mind another issue I had. I was trying to fetch a signed integer 32 variable that contained error codes. But I was getting large negative numbers. I only got reasonable results when I set the cffi code to look for an unsigned integer 32 variable. Maybe the two issues are related. Mirko
Mirko Vukovic <mirko.vukovic@gmail.com> writes:
Your comment brings to mind another issue I had. I was trying to fetch a signed integer 32 variable that contained error codes. But I was getting large negative numbers. I only got reasonable results when I set the cffi code to look for an unsigned integer 32 variable. Maybe the two issues are related.
Running the test suite should be a good way to weed out basic (possibly platform-specific) bugs in CLISP or CFFI. You'll have to manually compile libtest, I think. (Haven't tested with cygwin in several years.) Cheers, Luís
On Mon, Jul 1, 2013 at 11:27 AM, Luís Oliveira <luismbo@gmail.com> wrote:
Mirko Vukovic <mirko.vukovic@gmail.com> writes:
Your comment brings to mind another issue I had. I was trying to fetch a signed integer 32 variable that contained error codes. But I was getting large negative numbers. I only got reasonable results when I set the cffi code to look for an unsigned integer 32 variable. Maybe the two issues are related.
Running the test suite should be a good way to weed out basic (possibly platform-specific) bugs in CLISP or CFFI. You'll have to manually compile libtest, I think. (Haven't tested with cygwin in several years.)
Cheers, Luís
Good idea. I have a long weekend coming. Perfect relaxation :-)
participants (2)
-
Luís Oliveira
-
Mirko Vukovic