Skip to content

cgen,cheaders: move _vinit_caller()/_vcleanup_caller() fn declare forword#23507

Merged
spytheman merged 3 commits into
vlang:masterfrom
kbkpbot:fix-vinit_caller
Jan 20, 2025
Merged

cgen,cheaders: move _vinit_caller()/_vcleanup_caller() fn declare forword#23507
spytheman merged 3 commits into
vlang:masterfrom
kbkpbot:fix-vinit_caller

Conversation

@kbkpbot

@kbkpbot kbkpbot commented Jan 18, 2025

Copy link
Copy Markdown
Contributor

Fix issue #23496

This PR will make V's dll can be called by other program.
But the v function should call _vinit_caller()/_vcleanup_caller() directly....

example:

fn C._vinit_caller()
fn C._vcleanup_caller()

@[export: 'func']
fn func() {
	C._vinit_caller()          // must call first
	println('Begin DLL')
	for i in 0 .. 10 {
		println('${i}')
	}
	println('End DLL')
	C._vcleanup_caller()    // must call last,  note, currently , it is an empty function....
}

@huly-for-github

Copy link
Copy Markdown

Connected to Huly®: V_0.6-21936

@spytheman

Copy link
Copy Markdown
Contributor

(the CI failure is unrelated and already fixed on master)

Comment thread vlib/v/gen/c/cheaders.v
Comment on lines +539 to +544
#ifdef _WIN32
// workaround for windows, export _vinit_caller/_vcleanup_caller, let dl.open()/dl.close() call it
// NOTE: This is hardcoded in vlib/dl/dl_windows.c.v!
VV_EXPORTED_SYMBOL void _vinit_caller();
VV_EXPORTED_SYMBOL void _vcleanup_caller();
#endif

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I fail to see, what the benefit of this is, compared to the previous approach, of only generating those lines conditionally.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This will make user's v function can call the _vinit_caller/_vcleanup_caller, or the compiler will issue error message "implicit declaration of function"

@spytheman

Copy link
Copy Markdown
Contributor

(the CI errors are not related)

@spytheman spytheman merged commit c713ece into vlang:master Jan 20, 2025
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.

2 participants