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

parser: make C struct fields public by default #22706

Merged
merged 5 commits into from
Oct 31, 2024
Merged

parser: make C struct fields public by default #22706

merged 5 commits into from
Oct 31, 2024

Conversation

StunxFS
Copy link
Contributor

@StunxFS StunxFS commented Oct 30, 2024

This PR makes public all the fields that are declared in a C struct (struct declarations are not namespaced in C, and their fields are accessible from everywhere (if you do not use partial declarations and separate compilation)).

Fix #22695.

module main

import fontstash

fn main() {
	params := &C.FONSparams{
		width:        512
		height:       512
		flags:        0
		userPtr:      unsafe { nil }
		renderCreate: fn (uptr voidptr, width int, height int) int {
			return 1
		}
		renderResize: fn (uptr voidptr, width int, height int) int {
			return 1
		}
		renderUpdate: fn (uptr voidptr, rect &int, data &u8) {}
		renderDraw: fn (uptr voidptr, verts &f32, tcoords &f32, colors &u32, nverts int) {}
		renderDelete: fn (uptr voidptr) {}
	}

	context := fontstash.create_internal(params)
	eprintln(context)
}
$ v run main.v
fontstash.Context(C.FONScontext{})

Huly®: V_0.6-21154

@StunxFS StunxFS changed the title parser: C struct fields are public by default parser: make C struct fields are public by default Oct 30, 2024
@StunxFS StunxFS changed the title parser: make C struct fields are public by default parser: make C struct fields public by default Oct 30, 2024
Copy link
Member

@spytheman spytheman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work.

@StunxFS
Copy link
Contributor Author

StunxFS commented Oct 31, 2024

One thing to note is that when using v fmt, all C structs will automatically have a pub mut: section.

@spytheman
Copy link
Member

One thing to note is that when using v fmt, all C structs will automatically have a pub mut: section.

Even better - the committed code then will tend to closely reflect the reality, that they are public and mutable.

@spytheman spytheman merged commit b210278 into vlang:master Oct 31, 2024
78 checks passed
@StunxFS StunxFS deleted the c_fields_are_pub branch October 31, 2024 12:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Compiler says all fields are private when initializing c struct
2 participants