Re: ffi:make-pointer failed on mingw64 build
Yuguo Zhang <[email protected]> Mon, 22 Jun 2026 21:08:44 +0800
| Newsgroups | gmane.lisp.ecl.general |
|---|---|
| Message-ID | <[email protected]> |
Thanks, have tried uintptr_t, but ecl does not recognize it now . also noticed you are working on function pointer. I found this article is helpful, Divergent 64-bit Integer Sizes Across Platforms: ILP64, LP64, and LLP64 Explained https://sqlpey.com/c++/divergent-64bit-integer-sizes/ On 6/22/2026 16:07, Daniel KochmaĆski wrote: > Hello Yuguo, > > thanks for the report. > >> 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, > I think that the correct solution is to define uintptr_t that seems to > be the correct type here. Moreover, it is part of C99, so we can rely on it. > There is semi-related ticket for that here: > > https://gitlab.com/embeddable-common-lisp/ecl/-/work_items/768 > >> 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. >> > I agree -your conclusion is correct. The proper solution will be to include uintptr_t type in base types, as :uintptr-t, and update make-pointer to use that. A similar issue is reported here: > > https://gitlab.com/embeddable-common-lisp/ecl/-/work_items/679 > > Best regards, > Daniel >