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

Sage Gerard <sage-nnKKxiom5Z1/[email protected]>
Newsgroups gmane.comp.lang.racket.user,gmane.lisp.scheme.plt
Message-ID <Qvf3As3o8XZfVDzqxjbotKeij1EeFTzZcPcG8RCcdrY006ZQdTB_EonLLO-xU0wQ6-Bfldte7WHm-c1Hq7EOf9ZTkEZqb0merKX0eRE3CKQ=@sagegerard.com>
Found the issue.

I am populating a [VkPhysicalDeviceProperties](https://www.khronos.org/registry/vulkan/specs/1.1-extensions/man/html/VkPhysicalDeviceProperties.html) 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 ‐‐‐‐‐‐‐
On Wednesday, October 23, 2019 11:04 AM, Sage Gerard <sage-nnKKxiom5Z1/[email protected]> wrote:

> 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 < [email protected]> 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
>>
>> On Tue, Oct 22, 2019 at 4:52 PM Sage Gerard <sage-nnKKxiom5Z1/[email protected]> wrote:
>>>
>>> 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:
>>> https://github.com/zyrolasting/racket-vulkan/blob/master/unsafe.rkt#L1008
>>>
>>> I expect I misused a pointer and ended up with corrupted memory. But what is #<variable-code>, anyway? How did I produce it?
>>>
>>> ~slg
>>>
>>>
>>> --
>>> 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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
>>> 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.
>>
>> --
>> 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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
>> To view this discussion on the web visit [https://groups.google.com/d/msgid/racket-users/jk8PKgoSwaioairnI9lmNa_mZtjRPQ4kEoBgarwc7J6NwKg46Ij2Adz9fNhXPzqTWEwwoY1jS2jxCcYNElmroGGR8vTijVTAKNTjJLMqLdk%3D%40sagegerard.com](https://groups.google.com/d/msgid/racket-users/jk8PKgoSwaioairnI9lmNa_mZtjRPQ4kEoBgarwc7J6NwKg46Ij2Adz9fNhXPzqTWEwwoY1jS2jxCcYNElmroGGR8vTijVTAKNTjJLMqLdk%3D%40sagegerard.com?utm_medium=email&utm_source=footer).

-- 
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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/Qvf3As3o8XZfVDzqxjbotKeij1EeFTzZcPcG8RCcdrY006ZQdTB_EonLLO-xU0wQ6-Bfldte7WHm-c1Hq7EOf9ZTkEZqb0merKX0eRE3CKQ%3D%40sagegerard.com.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.