Re: ffi:make-pointer failed on mingw64 build

Daniel KochmaƄski <[email protected]> Mon, 22 Jun 2026 08:07:06 +0000
Newsgroups gmane.lisp.ecl.general
Message-ID <yNArYrnf7UAUdGCLP9zRB2UNiV2Hh_eWGJgn9pMzX74anZgeHl9q8OEMe3RUjAKo6ImZ6hzvmvJXw7tBNZPaGMPjd9H_NedtyQ2kvdQQo6k=@turtleware.eu>
Hello Yuguo,

thanks for the report.

> I'm testing a cl-opengl project.
>=20
> An make-pointer error raised when submit data to OpenGL using
> gl:BufferData,.
>=20
> After some digging, I found it's caused by the function
>=20
> (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))
>=20
> in src/ffi.lsp.
>=20
>=20
> the native type of 3rd argument is specified as :unsigned-long,
>=20
> 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

>=20
> so a value bigger than ffi:c-ulong-max failed internal test.
>=20
>=20
> you can reproduce this issue on a window 64 platform(msys2)
>=20
>  >(ffi:make-pointer (+ 0 ffi:c-ulong-max) :void)
>=20
> #<foreign :VOID 0xffffffff>
>=20
>  > (ffi:make-pointer (+ 1 ffi:c-ulong-max) :void)
>=20
> Condition of type: TYPE-ERROR
> 4294967296 is not of type (INTEGER 0 4294967295).
> Available restarts:
>=20
> 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>.
>=20
>=20
> more testing:
>=20
>  > (ffi:with-foreign-object (name '(:array :char 256))
>     (ffi:make-pointer (ffi:pointer-address name) :pointer-void))
>=20
> Condition of type: TYPE-ERROR
> 1598320958464 is not of type (INTEGER 0 4294967295).
> Available restarts:
>=20
> 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>.
>  >>
>=20
>=20
> with the following fix, just passed the test temporarily
>=20
> (defun make-pointer (addr type)
>    (c-inline (type (size-of-foreign-type type) addr) (:object
> :unsigned-long #+win64 :unsigned-long-long #-win64 :unsigned-long) :objec=
t
>              "ecl_make_foreign_data(#0, #1, (void*)#2)"
>              :side-effects t
>              :one-liner t))
>=20
> for the pointer type, I think this is not a good solution.
>=20

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 us=
e that. A similar issue is reported here:

https://gitlab.com/embeddable-common-lisp/ecl/-/work_items/679

Best regards,
Daniel