xiaoyafeng has asked for the wisdom of the Perl Monks concerning the following question:
I've tried to embed perl into a winform program written in C++/CLI recently. but got stuck with an conflict between managed style main function and PERL_SYS_INIT3 macro. the issue is compiler always complain if I put PERL_SYS_INIT3 into managed main body.(of course, it can't find any argc,argv adress in CLI). However what make me surprised, if I comment it everything seems OK. I mean, program could be compiled, and run correctly. Below is partial codes:
int main(array<System::String ^> ^args) { //PERL_SYS_INIT3(0,'ss','dd'); my_perl = perl_alloc(); perl_construct(my_perl); PL_exit_flags |= PERL_EXIT_DESTRUCT_END; // Enabling Windows XP visual effects before any controls are crea +ted Application::EnableVisualStyles(); Application::SetCompatibleTextRenderingDefault(false); // Create the main window and run it Application::Run(gcnew Form1()); // perl_destruct(my_perl); perl_free(my_perl); PERL_SYS_TERM(); return 0; }
here is said in perl api:
The macros PERL_SYS_INIT3() and PERL_SYS_TERM() provide system-specific tune up of the C runtime environment necessary to run Perl interpreters; they should only be called once regardless of how many interpreters you create or destroy. Call PERL_SYS_INIT3() before you create your first interpreter, and PERL_SYS_TERM() after you free your last interpreter. So what these 2 macros do behind? it does tune up? will it bring some issues when I comments it?thanks in advance!
In addition, perl_destruct(my_perl) can't be uncommented too,otherwise it will throw:
First-chance exception at 0x7c84cd02 in perl_form.exe: 0xC0000005: Acc +ess violation writing location 0x00000014. A first chance exception of type 'System.AccessViolationException' occ +urred in perl_form.exe An unhandled exception of type 'System.AccessViolationException' occur +red in perl_form.exe Additional information: Attempted to read or write protected memory. T +his is often an indication that other memory is corrupt.
UPDATE:
thank patcat88, it's like that PERL_SYS_INIT3 JUST run InitializeCriticalSection (&(*Perl_Gperlio_mutex_ptr (0))); So I pass NULL to it and by far everything seems ok. I'll do more tests.
int main(array<System::String ^> ^args) { PERL_SYS_INIT3((int *)NULL,(char ***)NULL,(char ***)NULL); my_perl = perl_alloc(); perl_construct(my_perl); PL_exit_flags |= PERL_EXIT_DESTRUCT_END; // Enabling Windows XP visual effects before any controls are crea +ted Application::EnableVisualStyles(); Application::SetCompatibleTextRenderingDefault(false); // Create the main window and run it Application::Run(gcnew Form1()); perl_destruct(my_perl); perl_free(my_perl); PERL_SYS_TERM(); return 0; }
I am trying to improve my English skills, if you see a mistake please feel free to reply or /msg me a correction
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: what do PERL_SYS_INIT3() and PERL_SYS_TERM() do?
by patcat88 (Deacon) on Dec 31, 2011 at 05:30 UTC |