Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No TNimNode generated for cimport object [--mm:refc] #19484

Open
iacore opened this issue Feb 2, 2022 · 3 comments
Open

No TNimNode generated for cimport object [--mm:refc] #19484

iacore opened this issue Feb 2, 2022 · 3 comments
Labels
refc refc issues

Comments

@iacore
Copy link
Contributor

iacore commented Feb 2, 2022

This bug is very specific. I don't why it happens, but it happens. The Rectangle is a struct from C. Using the equivalent definition in Nim don't have this bug.

Example

(clone this with git)
https://gist.github.com/locriacyber/c797c39e5583745e13a4caed68a38453

Current Output

(disabled: false, shapepos: (x: 12.0, y: 34.0, width: 56.0, height: 78.0), inputs: @[(payload: 42)], outputs: @[], rails: @[])
@[(disabled: false, shapepos: (x: 0.0, y: 0.0, width: 0.0, height: 0.0), inputs: @[(payload: 42)], outputs: @[], rails: @[])]

Expected Output

The two output should be the same.

Additional Information

This issue exists in Nim version 1.2.0 too.

Nim Compiler Version 1.6.2 [Linux: amd64]
Compiled at 2021-12-17
Copyright (c) 2006-2021 by Andreas Rumpf

git hash: 9084d9bc02bcd983b81a4c76a05f27b9ce2707dd
active boot switches: -d:release

As Elegantbeef pointed out in #nim-lang:matrix.org that this bug only exists with --mm:refc, since other memory models don't need type info (TNimNode) at runtime for this example. Not sure if this will bite me back in the future, but I'll use --mm:orc for now.

@rightbrace
Copy link

rightbrace commented Feb 3, 2022

Related, also discovered while using nimraylib_now: #19482

@iacore
Copy link
Contributor Author

iacore commented Feb 3, 2022

So, I found a manual fix.

I changed TNimKind of Rectangle from tyObject to 0. And it works now.

NTIrectangle__tVlkfxUbqhSfCIz2T9aInUA_.size = sizeof(Rectangle);
NTIrectangle__tVlkfxUbqhSfCIz2T9aInUA_.align = NIM_ALIGNOF(Rectangle);
NTIrectangle__tVlkfxUbqhSfCIz2T9aInUA_.kind = 0; // previously 18
NTIrectangle__tVlkfxUbqhSfCIz2T9aInUA_.base = 0;
NTIrectangle__tVlkfxUbqhSfCIz2T9aInUA_.flags = 1;
NTIrectangle__tVlkfxUbqhSfCIz2T9aInUA_.node = &TM__rmH9bpP9b3ZIjFP4QhigizlA_0[3];

@iacore
Copy link
Contributor Author

iacore commented Feb 5, 2022

The problem is, mt.node of the cimport type is not assigned (all zeros in most c compiler). There is no generated TNimNode for cimport types.
https://gist.github.com/locriacyber/34d546150949ab58f322246a412d4a92#file-mbug-nim-c-L1108
https://gist.github.com/locriacyber/34d546150949ab58f322246a412d4a92#file-assign-nim-L55

@iacore iacore changed the title C struct member not copied on assignment of a big object No TNimNode generated for cimport object Feb 5, 2022
@iacore iacore changed the title No TNimNode generated for cimport object No TNimNode generated for cimport object [--mm:refc] Feb 16, 2022
@ringabout ringabout added the refc refc issues label Oct 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refc refc issues
Projects
None yet
Development

No branches or pull requests

3 participants