You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@perl.apache.org by Steve Hay <st...@uk.radan.com> on 2005/02/01 10:09:19 UTC

Re: [PATCH] Re: What Perl configuration is required for mp2 on Win32?

Philippe M. Chiasson wrote:

>Steve Hay wrote:
>  
>
>>>>>Steve Hay wrote:
>>>>>
>>>>>          
>>>>>
>>>>>>Therefore, I want to configure my Perl with MULTIPLICITY and 
>>>>>>USE_ITHREADS, but not PERL_IMPLICIT_SYS.  That way, I can enable 
>>>>>>PERL_MALLOC.
>>>>>>
>>>>>>I've tried doing exactly this, but it doesn't seem to work.  Perl 
>>>>>>(5.8.6) itself built and tested without error, and mp2 (RC4) also built 
>>>>>>without error.  However, the mp2 test suite won't even get off the ground.
>>>>>>            
>>>>>>
>>Your comment made me start looking at how to reproduce the segfault 
>>without mp2 being involved (otherwise it'd be hard to get p5p 
>>interested), which turned out to be very simple:  The following tiny 
>>program, taken from an example in the perlembed manpage is all that it took:
>>
>>#include "EXTERN.h"
>>#include "perl.h"
>>static PerlInterpreter *my_perl;
>>int main(int argc, char **argv, char **env) {
>>    PERL_SYS_INIT3(&argc, &argv, &env);
>>    my_perl = perl_alloc();
>>    perl_construct(my_perl);
>>    perl_destruct(my_perl);
>>    perl_free(my_perl);
>>    PERL_SYS_TERM();
>>}
>>
>>The above program works fine (using my ithreads-but-no-impsys perl), but 
>>segfaults in the same way as apache/mp2 if I omit the PERL_SYS_INIT3() 
>>(and PERL_SYS_TERM) call(s):
>>
>>Perl_malloc(unsigned int 1020) line 1458
>>S_more_sv(interpreter * 0x00853fe0) line 315 + 10 bytes
>>Perl_newSV(interpreter * 0x00853fe0, unsigned int 79) line 4561 + 76 bytes
>>perl_construct(interpreter * 0x00853fe0) line 267 + 11 bytes
>>main(int 1, char * * 0x00852bf0, char * * 0x00852fd0) line 7 + 11 bytes
>>EMBED! mainCRTStartup + 227 bytes
>>KERNEL32! 77e8141a()
>>
>>Now, looking at the mp2 source, I see that modperl_startup() (the 
>>function which calls perl_construct()) does not have a PERL_SYS_INIT3() 
>>call in it.  Adding one as per the attached patch (against svn rev 
>>149266) fixes my problem.  The entire test suite now passes all tests OK 
>>in this configuration.  (I had to SKIP t/perl/ithreads*.t again, though 
>>-- it crashed the server again the first time I tried with them still in 
>>place :-s  Not sure if this patch re-introduces that failure, or if it 
>>never really went away.  Maybe I've just been lucky with it working 
>>recently?)
>>
>>However, we presumably now need to add a corresponding PERL_SYS_TERM() 
>>somewhere?
>>    
>>
>
>PERL_SYS_(TERM|INIT) needs to be called only once in the parent process.
>Can you give this patch a spin ?
>  
>
Didn't work, I'm afraid :(

Firstly, it complains about "Illegal indirection".  Also, 
PERL_SYS_INIT() is not documented anyway -- perlembed only refers to 
PERL_SYS_INIT3() (although that's just a wrapper to PERL_SYS_INIT 
anyway), so I changed

    PERL_SYS_INIT(0, NULL)

to

    PERL_SYS_INIT3(&argc, &argv, NULL)

where I have declared

    int argc = 1;
    char **argv;

However, it then crashes as follows on server startup:

Perl_mfree(void * 0x018fcfa0) line 2092
Perl_sv_clear(interpreter * 0x04cf9bd8, sv * 0x00000000) line 5232
Perl_sv_free(interpreter * 0x04cf9bd8, sv * 0x018d1298) line 5377
Perl_av_clear(interpreter * 0x04cf9bd8, av * 0x018e7984) line 470 + 9 bytes
modperl_xs_dl_handles_get(interpreter * 0x04cf9bd8) line 300 + 13 bytes
modperl_interp_destroy(modperl_interp_t * 0x04cdf400) line 143 + 9 bytes
modperl_interp_pool_destroy(void * 0x0098abc0) line 201 + 12 bytes
run_cleanups(cleanup_t * * 0x00982508) line 1952
apr_pool_destroy(apr_pool_t * 0x00401585) line 733
main(int 4201858, const char * const * 0x00000009) line 576
APACHE! mainCRTStartup + 227 bytes
KERNEL32! 77e8141a()

Have I done the PERL_SYS_INIT3() call wrong, or is this just no good anyway?

- Steve

>Index: src/modules/perl/mod_perl.c
>===================================================================
>--- src/modules/perl/mod_perl.c	(revision 149209)
>+++ src/modules/perl/mod_perl.c	(working copy)
>@@ -544,8 +544,8 @@
>  {
>      MP_TRACE_i(MP_FUNC, "mod_perl sys init\n");
>
>-#if 0 /*XXX*/
>      PERL_SYS_INIT(0, NULL);
>+#if 0 /*XXX*/
>
>  #ifdef PTHREAD_ATFORK
>      if (!ap_exists_config_define("PERL_PTHREAD_ATFORK_DONE")) {
>@@ -581,9 +581,7 @@
>
>      modperl_perl_pp_unset_all();
>
>-#if 0 /*XXX*/
>      PERL_SYS_TERM();
>-#endif
>      return APR_SUCCESS;
>  }
>  
>



------------------------------------------------
Radan Computational Ltd.

The information contained in this message and any files transmitted with it are confidential and intended for the addressee(s) only.  If you have received this message in error or there are any problems, please notify the sender immediately.  The unauthorized use, disclosure, copying or alteration of this message is strictly forbidden.  Note that any views or opinions presented in this email are solely those of the author and do not necessarily represent those of Radan Computational Ltd.  The recipient(s) of this message should check it and any attached files for viruses: Radan Computational will accept no liability for any damage caused by any virus transmitted by this email.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: [PATCH] Re: What Perl configuration is required for mp2 on Win32?

Posted by Steve Hay <st...@uk.radan.com>.
Stas Bekman wrote:

>>OK, new patch attached.  This compiles cleanly and fixes the perl-malloc 
>>issues for me.  Hope it's OK for you too.
>>    
>>
>
>Almost there. env needs to be **env. 
>
Oops.  Yes, of course.  Thanks.

- Steve

>Here is the patch that I've committed:
>
>Index: src/modules/perl/mod_perl.c
>===================================================================
>--- src/modules/perl/mod_perl.c (revision 151089)
>+++ src/modules/perl/mod_perl.c (working copy)
>@@ -542,11 +542,17 @@
>   */
>  static apr_status_t modperl_sys_init(void)
>  {
>+    int argc = 0;
>+    char **argv = NULL, **env = NULL;
>+
>      MP_TRACE_i(MP_FUNC, "mod_perl sys init\n");
>
>+    /* not every OS uses those vars in PERL_SYS_INIT3 macro */
>+    argc = argc; argv = argv; env = env;
>+
>+    PERL_SYS_INIT3(&argc, &argv, &env);
>+
>  #if 0 /*XXX*/
>-    PERL_SYS_INIT(0, NULL);
>-
>  #ifdef PTHREAD_ATFORK
>      if (!ap_exists_config_define("PERL_PTHREAD_ATFORK_DONE")) {
>          PTHREAD_ATFORK(Perl_atfork_lock,
>@@ -581,9 +587,8 @@
>
>      modperl_perl_pp_unset_all();
>
>-#if 0 /*XXX*/
>      PERL_SYS_TERM();
>-#endif
>+
>      return APR_SUCCESS;
>  }
>  
>



------------------------------------------------
Radan Computational Ltd.

The information contained in this message and any files transmitted with it are confidential and intended for the addressee(s) only.  If you have received this message in error or there are any problems, please notify the sender immediately.  The unauthorized use, disclosure, copying or alteration of this message is strictly forbidden.  Note that any views or opinions presented in this email are solely those of the author and do not necessarily represent those of Radan Computational Ltd.  The recipient(s) of this message should check it and any attached files for viruses: Radan Computational will accept no liability for any damage caused by any virus transmitted by this email.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: [PATCH] Re: What Perl configuration is required for mp2 on Win32?

Posted by Stas Bekman <st...@stason.org>.
> OK, new patch attached.  This compiles cleanly and fixes the perl-malloc 
> issues for me.  Hope it's OK for you too.

Almost there. env needs to be **env. Here is the patch that I've committed:

Index: src/modules/perl/mod_perl.c
===================================================================
--- src/modules/perl/mod_perl.c (revision 151089)
+++ src/modules/perl/mod_perl.c (working copy)
@@ -542,11 +542,17 @@
   */
  static apr_status_t modperl_sys_init(void)
  {
+    int argc = 0;
+    char **argv = NULL, **env = NULL;
+
      MP_TRACE_i(MP_FUNC, "mod_perl sys init\n");

+    /* not every OS uses those vars in PERL_SYS_INIT3 macro */
+    argc = argc; argv = argv; env = env;
+
+    PERL_SYS_INIT3(&argc, &argv, &env);
+
  #if 0 /*XXX*/
-    PERL_SYS_INIT(0, NULL);
-
  #ifdef PTHREAD_ATFORK
      if (!ap_exists_config_define("PERL_PTHREAD_ATFORK_DONE")) {
          PTHREAD_ATFORK(Perl_atfork_lock,
@@ -581,9 +587,8 @@

      modperl_perl_pp_unset_all();

-#if 0 /*XXX*/
      PERL_SYS_TERM();
-#endif
+
      return APR_SUCCESS;
  }




-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: [PATCH] Re: What Perl configuration is required for mp2 on Win32?

Posted by Steve Hay <st...@uk.radan.com>.
Stas Bekman wrote:

>Steve Hay wrote:
>
>  
>
>>>Index: src/modules/perl/mod_perl.c
>>>===================================================================
>>>--- src/modules/perl/mod_perl.c	(revision 151089)
>>>+++ src/modules/perl/mod_perl.c	(working copy)
>>>@@ -544,9 +544,9 @@
>>>{
>>>    MP_TRACE_i(MP_FUNC, "mod_perl sys init\n");
>>>
>>>-#if 0 /*XXX*/
>>>-    PERL_SYS_INIT(0, NULL);
>>>+    PERL_SYS_INIT3(0, NULL, NULL);
>>>
>>>
>>>      
>>>
>>No -- as I said in my last mail (quoted above) that gives an "Illegal 
>>indirection" error, which is why I was moved to supply some variables 
>>instead.
>>
>>The full error text is this:
>>
>>mod_perl.c(547) : error C2100: illegal indirection
>>mod_perl.c(547) : error C2100: illegal indirection
>>NMAKE : fatal error U1077: 'cl' : return code '0x2'
>>Stop.
>>NMAKE : fatal error U1077: 'cd' : return code '0x2'
>>Stop.
>>
>>The MSDN docs describe compiler error "C2100: illegal indirection" as 
>>follows:
>>
>>    "The indirection operator (*) was applied to a nonpointer value."
>>
>>The reason is that on Win32 PERL_SYS_INIT3(a,b,c) is
>>
>>    MALLOC_CHECK_TAINT2(*a,*b);
>>    Perl_win32_init(a,b);
>>
>>so it's the *a and *b in the MALLOC_CHECK_TAINT2() call which it's 
>>whining about in the case where a and b were non-pointers.  So the 
>>obvious fix seemed to be:
>>
>>    PERL_SYS_INIT3((int *)NULL, (char ***)NULL, (char ***)NULL);
>>
>>This compiles cleanly, but then crashes on startup because now it's 
>>trying to resolve the NULL pointer values!
>>
>>Explicitly calling
>>
>>    MALLOC_CHECK_TAINT2(0, (char **)NULL);
>>    Perl_win32_init((int *)0, (char ***)NULL);
>>
>>works (both compiling and running), but that's cheating (and also won't 
>>work on Linux ;)
>>
>>Any other ideas?  If not then can you live with the warnings about 
>>unused variables?  That's at least better than the situation for me 
>>without a PERL_SYS_INIT3() call at all ;)
>>    
>>
>
>sure, just add to your patch:
>
>     /* not every OS uses those vars in PERL_SYS_INIT3 macro */
>     argc = argc; argv = argv; env = env;
>
>in which case it's fine.
>
OK, new patch attached.  This compiles cleanly and fixes the perl-malloc 
issues for me.  Hope it's OK for you too.

- Steve


------------------------------------------------
Radan Computational Ltd.

The information contained in this message and any files transmitted with it are confidential and intended for the addressee(s) only.  If you have received this message in error or there are any problems, please notify the sender immediately.  The unauthorized use, disclosure, copying or alteration of this message is strictly forbidden.  Note that any views or opinions presented in this email are solely those of the author and do not necessarily represent those of Radan Computational Ltd.  The recipient(s) of this message should check it and any attached files for viruses: Radan Computational will accept no liability for any damage caused by any virus transmitted by this email.

Re: [PATCH] Re: What Perl configuration is required for mp2 on Win32?

Posted by Stas Bekman <st...@stason.org>.
Steve Hay wrote:

>>Index: src/modules/perl/mod_perl.c
>>===================================================================
>>--- src/modules/perl/mod_perl.c	(revision 151089)
>>+++ src/modules/perl/mod_perl.c	(working copy)
>>@@ -544,9 +544,9 @@
>> {
>>     MP_TRACE_i(MP_FUNC, "mod_perl sys init\n");
>>
>>-#if 0 /*XXX*/
>>-    PERL_SYS_INIT(0, NULL);
>>+    PERL_SYS_INIT3(0, NULL, NULL);
>> 
>>
> 
> No -- as I said in my last mail (quoted above) that gives an "Illegal 
> indirection" error, which is why I was moved to supply some variables 
> instead.
> 
> The full error text is this:
> 
> mod_perl.c(547) : error C2100: illegal indirection
> mod_perl.c(547) : error C2100: illegal indirection
> NMAKE : fatal error U1077: 'cl' : return code '0x2'
> Stop.
> NMAKE : fatal error U1077: 'cd' : return code '0x2'
> Stop.
> 
> The MSDN docs describe compiler error "C2100: illegal indirection" as 
> follows:
> 
>     "The indirection operator (*) was applied to a nonpointer value."
> 
> The reason is that on Win32 PERL_SYS_INIT3(a,b,c) is
> 
>     MALLOC_CHECK_TAINT2(*a,*b);
>     Perl_win32_init(a,b);
> 
> so it's the *a and *b in the MALLOC_CHECK_TAINT2() call which it's 
> whining about in the case where a and b were non-pointers.  So the 
> obvious fix seemed to be:
> 
>     PERL_SYS_INIT3((int *)NULL, (char ***)NULL, (char ***)NULL);
> 
> This compiles cleanly, but then crashes on startup because now it's 
> trying to resolve the NULL pointer values!
> 
> Explicitly calling
> 
>     MALLOC_CHECK_TAINT2(0, (char **)NULL);
>     Perl_win32_init((int *)0, (char ***)NULL);
> 
> works (both compiling and running), but that's cheating (and also won't 
> work on Linux ;)
> 
> Any other ideas?  If not then can you live with the warnings about 
> unused variables?  That's at least better than the situation for me 
> without a PERL_SYS_INIT3() call at all ;)

sure, just add to your patch:

     /* not every OS uses those vars in PERL_SYS_INIT3 macro */
     argc = argc; argv = argv; env = env;

in which case it's fine.



-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: [PATCH] Re: What Perl configuration is required for mp2 on Win32?

Posted by Steve Hay <st...@uk.radan.com>.
Stas Bekman wrote:

>Steve Hay wrote:
>[...]
>  
>
>>After further investigation, I've realised that actually Philippe's 
>>patch DOES fix the problem.
>>
>>[...]
>>So could somebody please apply the attached patch.  (This version 
>>updates PERL_SYS_INIT() to PERL_SYS_INIT3() as per perlembed, and fixes 
>>an "Illegal indirection" error which simply calling PERL_SYS_INIT3(0, 
>>NULL, NULL) produces.)
>>    
>>
>
>>Index: src/modules/perl/mod_perl.c
>>===================================================================
>>--- src/modules/perl/mod_perl.c	(revision 149511)
>>+++ src/modules/perl/mod_perl.c	(working copy)
>>@@ -542,11 +542,14 @@
>>  */
>> static apr_status_t modperl_sys_init(void)
>> {
>>+    int argc = 0;
>>+    char **argv = NULL, env = NULL;
>>+
>>     MP_TRACE_i(MP_FUNC, "mod_perl sys init\n");
>> 
>>+    PERL_SYS_INIT3(&argc, &argv, &env);
>>    
>>
>
>As on unix the above macro expands to something that doesn't use either of 
>these 3 arguments we get:
>
>mod_perl.c: In function `modperl_sys_init':
>mod_perl.c:545: warning: unused variable `argc'
>mod_perl.c:546: warning: unused variable `argv'
>mod_perl.c:546: warning: unused variable `env'
>  
>
Damn.  Didn't think of that.

>Please try this patch instead:
>
>Index: src/modules/perl/mod_perl.c
>===================================================================
>--- src/modules/perl/mod_perl.c	(revision 151089)
>+++ src/modules/perl/mod_perl.c	(working copy)
>@@ -544,9 +544,9 @@
>  {
>      MP_TRACE_i(MP_FUNC, "mod_perl sys init\n");
>
>-#if 0 /*XXX*/
>-    PERL_SYS_INIT(0, NULL);
>+    PERL_SYS_INIT3(0, NULL, NULL);
>  
>
No -- as I said in my last mail (quoted above) that gives an "Illegal 
indirection" error, which is why I was moved to supply some variables 
instead.

The full error text is this:

mod_perl.c(547) : error C2100: illegal indirection
mod_perl.c(547) : error C2100: illegal indirection
NMAKE : fatal error U1077: 'cl' : return code '0x2'
Stop.
NMAKE : fatal error U1077: 'cd' : return code '0x2'
Stop.

The MSDN docs describe compiler error "C2100: illegal indirection" as 
follows:

    "The indirection operator (*) was applied to a nonpointer value."

The reason is that on Win32 PERL_SYS_INIT3(a,b,c) is

    MALLOC_CHECK_TAINT2(*a,*b);
    Perl_win32_init(a,b);

so it's the *a and *b in the MALLOC_CHECK_TAINT2() call which it's 
whining about in the case where a and b were non-pointers.  So the 
obvious fix seemed to be:

    PERL_SYS_INIT3((int *)NULL, (char ***)NULL, (char ***)NULL);

This compiles cleanly, but then crashes on startup because now it's 
trying to resolve the NULL pointer values!

Explicitly calling

    MALLOC_CHECK_TAINT2(0, (char **)NULL);
    Perl_win32_init((int *)0, (char ***)NULL);

works (both compiling and running), but that's cheating (and also won't 
work on Linux ;)

Any other ideas?  If not then can you live with the warnings about 
unused variables?  That's at least better than the situation for me 
without a PERL_SYS_INIT3() call at all ;)

- Steve


------------------------------------------------
Radan Computational Ltd.

The information contained in this message and any files transmitted with it are confidential and intended for the addressee(s) only.  If you have received this message in error or there are any problems, please notify the sender immediately.  The unauthorized use, disclosure, copying or alteration of this message is strictly forbidden.  Note that any views or opinions presented in this email are solely those of the author and do not necessarily represent those of Radan Computational Ltd.  The recipient(s) of this message should check it and any attached files for viruses: Radan Computational will accept no liability for any damage caused by any virus transmitted by this email.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: [PATCH] Re: What Perl configuration is required for mp2 on Win32?

Posted by Stas Bekman <st...@stason.org>.
Steve Hay wrote:
[...]
> After further investigation, I've realised that actually Philippe's 
> patch DOES fix the problem.
> 
> The reason that I didn't see it before was that in my original 
> PERL_SYS_INIT() patch I was looking around for a place to put a 
> corresponding PERL_SYS_TERM(), and had tried placing one in 
> modperl_perl_destruct().  I'd forgotten that I'd done that, and it was 
> causing Philippe's patch to not work because modperl_perl_destruct() is 
> called more than once and was destroying the (global) perl malloc mutex 
> which PERL_SYS_INIT had created!  (Hence the crash on a subsequent call 
> to MALLOC_LOCK.)
> 
> So could somebody please apply the attached patch.  (This version 
> updates PERL_SYS_INIT() to PERL_SYS_INIT3() as per perlembed, and fixes 
> an "Illegal indirection" error which simply calling PERL_SYS_INIT3(0, 
> NULL, NULL) produces.)
> 
> The use of PERL_SYS_INIT() is essential to running mp2 with Perl's 
> malloc(), at least on Win32.  (PERL_SYS_INIT() calls Perl_win32_init(), 
> which calls MALLOC_INIT, without which the MALLOC_LOCK/MALLO_UNLOCK's 
> done by Perl's malloc() don't work.)

> Index: src/modules/perl/mod_perl.c
> ===================================================================
> --- src/modules/perl/mod_perl.c	(revision 149511)
> +++ src/modules/perl/mod_perl.c	(working copy)
> @@ -542,11 +542,14 @@
>   */
>  static apr_status_t modperl_sys_init(void)
>  {
> +    int argc = 0;
> +    char **argv = NULL, env = NULL;
> +
>      MP_TRACE_i(MP_FUNC, "mod_perl sys init\n");
>  
> +    PERL_SYS_INIT3(&argc, &argv, &env);

As on unix the above macro expands to something that doesn't use either of 
these 3 arguments we get:

mod_perl.c: In function `modperl_sys_init':
mod_perl.c:545: warning: unused variable `argc'
mod_perl.c:546: warning: unused variable `argv'
mod_perl.c:546: warning: unused variable `env'

Please try this patch instead:

Index: src/modules/perl/mod_perl.c
===================================================================
--- src/modules/perl/mod_perl.c	(revision 151089)
+++ src/modules/perl/mod_perl.c	(working copy)
@@ -544,9 +544,9 @@
  {
      MP_TRACE_i(MP_FUNC, "mod_perl sys init\n");

-#if 0 /*XXX*/
-    PERL_SYS_INIT(0, NULL);
+    PERL_SYS_INIT3(0, NULL, NULL);

+#if 0 /*XXX*/
  #ifdef PTHREAD_ATFORK
      if (!ap_exists_config_define("PERL_PTHREAD_ATFORK_DONE")) {
          PTHREAD_ATFORK(Perl_atfork_lock,
@@ -581,9 +581,8 @@

      modperl_perl_pp_unset_all();

-#if 0 /*XXX*/
      PERL_SYS_TERM();
-#endif
+
      return APR_SUCCESS;
  }


-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: [PATCH] Re: What Perl configuration is required for mp2 on Win32?

Posted by Steve Hay <st...@uk.radan.com>.
Steve Hay wrote:

>Steve Hay wrote:
>
>  
>
>>Philippe M. Chiasson wrote:
>>
>> 
>>
>>    
>>
>>>Steve Hay wrote:
>>>
>>>
>>>   
>>>
>>>      
>>>
>>>>>>>Steve Hay wrote:
>>>>>>>
>>>>>>>        
>>>>>>>
>>>>>>>           
>>>>>>>
>>>>>>>              
>>>>>>>
>>>>>>>>Therefore, I want to configure my Perl with MULTIPLICITY and 
>>>>>>>>USE_ITHREADS, but not PERL_IMPLICIT_SYS.  That way, I can enable 
>>>>>>>>PERL_MALLOC.
>>>>>>>>
>>>>>>>>I've tried doing exactly this, but it doesn't seem to work.  Perl 
>>>>>>>>(5.8.6) itself built and tested without error, and mp2 (RC4) also built 
>>>>>>>>without error.  However, the mp2 test suite won't even get off the ground.
>>>>>>>>          
>>>>>>>>
>>>>>>>>             
>>>>>>>>
>>>>>>>>                
>>>>>>>>
>>>>Your comment made me start looking at how to reproduce the segfault 
>>>>without mp2 being involved (otherwise it'd be hard to get p5p 
>>>>interested), which turned out to be very simple:  The following tiny 
>>>>program, taken from an example in the perlembed manpage is all that it took:
>>>>
>>>>#include "EXTERN.h"
>>>>#include "perl.h"
>>>>static PerlInterpreter *my_perl;
>>>>int main(int argc, char **argv, char **env) {
>>>>  PERL_SYS_INIT3(&argc, &argv, &env);
>>>>  my_perl = perl_alloc();
>>>>  perl_construct(my_perl);
>>>>  perl_destruct(my_perl);
>>>>  perl_free(my_perl);
>>>>  PERL_SYS_TERM();
>>>>}
>>>>
>>>>The above program works fine (using my ithreads-but-no-impsys perl), but 
>>>>segfaults in the same way as apache/mp2 if I omit the PERL_SYS_INIT3() 
>>>>(and PERL_SYS_TERM) call(s):
>>>>
>>>>Perl_malloc(unsigned int 1020) line 1458
>>>>S_more_sv(interpreter * 0x00853fe0) line 315 + 10 bytes
>>>>Perl_newSV(interpreter * 0x00853fe0, unsigned int 79) line 4561 + 76 bytes
>>>>perl_construct(interpreter * 0x00853fe0) line 267 + 11 bytes
>>>>main(int 1, char * * 0x00852bf0, char * * 0x00852fd0) line 7 + 11 bytes
>>>>EMBED! mainCRTStartup + 227 bytes
>>>>KERNEL32! 77e8141a()
>>>>
>>>>Now, looking at the mp2 source, I see that modperl_startup() (the 
>>>>function which calls perl_construct()) does not have a PERL_SYS_INIT3() 
>>>>call in it.  Adding one as per the attached patch (against svn rev 
>>>>149266) fixes my problem.  The entire test suite now passes all tests OK 
>>>>in this configuration.  (I had to SKIP t/perl/ithreads*.t again, though 
>>>>-- it crashed the server again the first time I tried with them still in 
>>>>place :-s  Not sure if this patch re-introduces that failure, or if it 
>>>>never really went away.  Maybe I've just been lucky with it working 
>>>>recently?)
>>>>
>>>>However, we presumably now need to add a corresponding PERL_SYS_TERM() 
>>>>somewhere?
>>>>  
>>>>
>>>>     
>>>>
>>>>        
>>>>
>>>PERL_SYS_(TERM|INIT) needs to be called only once in the parent process.
>>>Can you give this patch a spin ?
>>>
>>>
>>>   
>>>
>>>      
>>>
>>Didn't work, I'm afraid :(
>> 
>>
>>    
>>
>No replies to this one, then :(
>
>Are people still pondering it, or does nobody know how to resolve this?
>
After further investigation, I've realised that actually Philippe's 
patch DOES fix the problem.

The reason that I didn't see it before was that in my original 
PERL_SYS_INIT() patch I was looking around for a place to put a 
corresponding PERL_SYS_TERM(), and had tried placing one in 
modperl_perl_destruct().  I'd forgotten that I'd done that, and it was 
causing Philippe's patch to not work because modperl_perl_destruct() is 
called more than once and was destroying the (global) perl malloc mutex 
which PERL_SYS_INIT had created!  (Hence the crash on a subsequent call 
to MALLOC_LOCK.)

So could somebody please apply the attached patch.  (This version 
updates PERL_SYS_INIT() to PERL_SYS_INIT3() as per perlembed, and fixes 
an "Illegal indirection" error which simply calling PERL_SYS_INIT3(0, 
NULL, NULL) produces.)

The use of PERL_SYS_INIT() is essential to running mp2 with Perl's 
malloc(), at least on Win32.  (PERL_SYS_INIT() calls Perl_win32_init(), 
which calls MALLOC_INIT, without which the MALLOC_LOCK/MALLO_UNLOCK's 
done by Perl's malloc() don't work.)

- Steve


------------------------------------------------
Radan Computational Ltd.

The information contained in this message and any files transmitted with it are confidential and intended for the addressee(s) only.  If you have received this message in error or there are any problems, please notify the sender immediately.  The unauthorized use, disclosure, copying or alteration of this message is strictly forbidden.  Note that any views or opinions presented in this email are solely those of the author and do not necessarily represent those of Radan Computational Ltd.  The recipient(s) of this message should check it and any attached files for viruses: Radan Computational will accept no liability for any damage caused by any virus transmitted by this email.

Re: [PATCH] Re: What Perl configuration is required for mp2 on Win32?

Posted by Steve Hay <st...@uk.radan.com>.
Steve Hay wrote:

>Philippe M. Chiasson wrote:
>
>  
>
>>Steve Hay wrote:
>> 
>>
>>    
>>
>>>>>>Steve Hay wrote:
>>>>>>
>>>>>>         
>>>>>>
>>>>>>            
>>>>>>
>>>>>>>Therefore, I want to configure my Perl with MULTIPLICITY and 
>>>>>>>USE_ITHREADS, but not PERL_IMPLICIT_SYS.  That way, I can enable 
>>>>>>>PERL_MALLOC.
>>>>>>>
>>>>>>>I've tried doing exactly this, but it doesn't seem to work.  Perl 
>>>>>>>(5.8.6) itself built and tested without error, and mp2 (RC4) also built 
>>>>>>>without error.  However, the mp2 test suite won't even get off the ground.
>>>>>>>           
>>>>>>>
>>>>>>>              
>>>>>>>
>>>Your comment made me start looking at how to reproduce the segfault 
>>>without mp2 being involved (otherwise it'd be hard to get p5p 
>>>interested), which turned out to be very simple:  The following tiny 
>>>program, taken from an example in the perlembed manpage is all that it took:
>>>
>>>#include "EXTERN.h"
>>>#include "perl.h"
>>>static PerlInterpreter *my_perl;
>>>int main(int argc, char **argv, char **env) {
>>>   PERL_SYS_INIT3(&argc, &argv, &env);
>>>   my_perl = perl_alloc();
>>>   perl_construct(my_perl);
>>>   perl_destruct(my_perl);
>>>   perl_free(my_perl);
>>>   PERL_SYS_TERM();
>>>}
>>>
>>>The above program works fine (using my ithreads-but-no-impsys perl), but 
>>>segfaults in the same way as apache/mp2 if I omit the PERL_SYS_INIT3() 
>>>(and PERL_SYS_TERM) call(s):
>>>
>>>Perl_malloc(unsigned int 1020) line 1458
>>>S_more_sv(interpreter * 0x00853fe0) line 315 + 10 bytes
>>>Perl_newSV(interpreter * 0x00853fe0, unsigned int 79) line 4561 + 76 bytes
>>>perl_construct(interpreter * 0x00853fe0) line 267 + 11 bytes
>>>main(int 1, char * * 0x00852bf0, char * * 0x00852fd0) line 7 + 11 bytes
>>>EMBED! mainCRTStartup + 227 bytes
>>>KERNEL32! 77e8141a()
>>>
>>>Now, looking at the mp2 source, I see that modperl_startup() (the 
>>>function which calls perl_construct()) does not have a PERL_SYS_INIT3() 
>>>call in it.  Adding one as per the attached patch (against svn rev 
>>>149266) fixes my problem.  The entire test suite now passes all tests OK 
>>>in this configuration.  (I had to SKIP t/perl/ithreads*.t again, though 
>>>-- it crashed the server again the first time I tried with them still in 
>>>place :-s  Not sure if this patch re-introduces that failure, or if it 
>>>never really went away.  Maybe I've just been lucky with it working 
>>>recently?)
>>>
>>>However, we presumably now need to add a corresponding PERL_SYS_TERM() 
>>>somewhere?
>>>   
>>>
>>>      
>>>
>>PERL_SYS_(TERM|INIT) needs to be called only once in the parent process.
>>Can you give this patch a spin ?
>> 
>>
>>    
>>
>Didn't work, I'm afraid :(
>  
>
No replies to this one, then :(

Are people still pondering it, or does nobody know how to resolve this?

It seems to me that mp2 really should be calling PERL_SYS_INIT3() and 
PERL_SYS_TERM().  All the examples in perlembed.pod show these macros 
being used, and I have a trivial C program (posted previously) that 
breaks without them.  Their omission is very likely at least part of the 
cause for mp2 not working in my setup, and I'd really like to get it 
sorted out somehow.

- Steve


------------------------------------------------
Radan Computational Ltd.

The information contained in this message and any files transmitted with it are confidential and intended for the addressee(s) only.  If you have received this message in error or there are any problems, please notify the sender immediately.  The unauthorized use, disclosure, copying or alteration of this message is strictly forbidden.  Note that any views or opinions presented in this email are solely those of the author and do not necessarily represent those of Radan Computational Ltd.  The recipient(s) of this message should check it and any attached files for viruses: Radan Computational will accept no liability for any damage caused by any virus transmitted by this email.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org