ffi:make-pointer failed on mingw64 build
Yuguo Zhang <[email protected]> Sun, 21 Jun 2026 12:40:11 +0800
| Newsgroups | gmane.lisp.ecl.general |
|---|---|
| Message-ID | <[email protected]> |
Hello, I'm testing a cl-opengl project. An make-pointer error raised when submit data to OpenGL using gl:BufferData,. After some digging, I found it's caused by the function (defun make-pointer (addr type) (c-inline (type (size-of-foreign-type type) addr) (:object :unsigned-long :unsigned-long) :object "ecl_make_foreign_data(#0, #1, (void*)#2)" :side-effects t :one-liner t)) in src/ffi.lsp. the native type of 3rd argument is specified as :unsigned-long, but on windows x64, (ffi:size-of-foreign-type :unsigned-long) is 4, not enough for a pointer, so a value bigger than ffi:c-ulong-max failed internal test. you can reproduce this issue on a window 64 platform(msys2) >(ffi:make-pointer (+ 0 ffi:c-ulong-max) :void) #<foreign :VOID 0xffffffff> > (ffi:make-pointer (+ 1 ffi:c-ulong-max) :void) Condition of type: TYPE-ERROR 4294967296 is not of type (INTEGER 0 4294967295). Available restarts: 1. (RESTART-TOPLEVEL) Go back to Top-Level REPL. Broken at SI:BYTECODES. [Evaluation of: (FFI:MAKE-POINTER (+ 1 FFI:C-ULONG-MAX) :VOID)] In: #<process TOP-LEVEL 0x174235a0f30>. more testing: > (ffi:with-foreign-object (name '(:array :char 256)) (ffi:make-pointer (ffi:pointer-address name) :pointer-void)) Condition of type: TYPE-ERROR 1598320958464 is not of type (INTEGER 0 4294967295). Available restarts: 1. (RESTART-TOPLEVEL) Go back to Top-Level REPL. Broken at SI:BYTECODES. [Evaluation of: (FFI:WITH-FOREIGN-OBJECT (NAME (QUOTE (:ARRAY :CHAR 256))) (FFI:MAKE-POINTER (FFI:POINTER-ADDRESS NAME) :POINTER-VOID))] In: #<process TOP-LEVEL 0x174235a0f30>. >> with the following fix, just passed the test temporarily (defun make-pointer (addr type) (c-inline (type (size-of-foreign-type type) addr) (:object :unsigned-long #+win64 :unsigned-long-long #-win64 :unsigned-long) :object "ecl_make_foreign_data(#0, #1, (void*)#2)" :side-effects t :one-liner t)) for the pointer type, I think this is not a good solution. Regars.