What's "#<variable-code>"?

45 views
Skip to first unread message

Sage Gerard

unread,
Oct 22, 2019, 4:52:50 PM10/22/19
to users\@racket-lang.org
Here's a Vulkan app that prints the properties of the first physical device on the system: https://github.com/zyrolasting/racket-vulkan/blob/master/examples/mandelbrot.rkt#L39

If you comment out the call to `vkGetPhysicalDeviceProperties`, the main module works. I create a Vulkan instance, print out a blank version of a struct, then destroy the instance. If I leave it in, I get:

; ptr-ref: contract violation
;   expected: cpointer?
;   given: #<variable-code>
;   argument position: 1st

I bind `vkGetPhysicalDeviceProperties` using _pointer so I can learn how to work with the raw API:

I expect I misused a pointer and ended up with corrupted memory. But what is #<variable-code>, anyway? How did I produce it?

~slg


Sage Gerard

unread,
Oct 23, 2019, 11:04:22 AM10/23/19
to sa...@cs.indiana.edu, us...@racket-lang.org
Alright, thanks. I have a couple of leads on what happened, but since the implementation details are private I'm unsure of the best troubleshooting technique in this context.

For now I am making a minimal C project that builds a shared library and follows the same allocation pattern and FFI use.

I noticed that switching "_pointer" back to a tagged pointer type makes the program raise an error, but I suspect that's due to a tag being missing from the (malloc) call.

Once I learn my mistake I will share it here.

~slg




-------- Original Message --------
On Oct 23, 2019, 10:58 AM, Sam Tobin-Hochstadt < sa...@cs.indiana.edu> wrote:

`#<variable-code>` is how a representation of one of the internal AST
types for the compiler is printed. When you see it, it definitely
means some memory got corrupted.

Sam

> --
> You received this message because you are subscribed to the Google Groups "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/kOdM__5k_2CVKSt5cmEUjb8Ci-00MtOsPUnBvetk5puetw-rGEyH95lFrYNQ-rgKdEOJQ7eo7boVEz9ua4RHPeUb1O9OdzsDdkQjwhuM9pA%3D%40sagegerard.com.

Sage Gerard

unread,
Oct 23, 2019, 1:22:23 PM10/23/19
to Sage Gerard, sa...@cs.indiana.edu, us...@racket-lang.org
Found the issue.

I am populating a VkPhysicalDeviceProperties struct. On my system, C reports this structure as 824 bytes. (ctype-sizeof), on the other hand, says it's 312. Hardcoding 824 removed the error.

As for how this happened: My generated (define-cstruct) unconditionally declared members of struct instance types as pointers to those struct types.

Takeaway for visitors: Verify that sizes are correct by comparing output from C's sizeof with Racket's (ctype-sizeof).

~slg


‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐

Reply all
Reply to author
Forward
0 new messages