Joe Schaefer wrote: [...]
What the assembly dump is helpful for? do you think the C function wasn't
compiled properly?
gdb was acting very weird, and I was losing confidence in what I was seeing, but Joe cleared up the fog for me. Here's what happens on the bad request, letting it segfault this time (I recompiled perl-5.8.5 w/ -Doptimize="-gdwarf-2 -g3" to enable macro expansions in gdb):
Yeah, these are very cool options, these and others are documented here: http://perl.apache.org/docs/2.0/devel/debug/c.html#Expanding_C_Macros
0x0000002a967c486d in Perl_safesysmalloc (size=24) at util.c:75 (gdb) list Perl_safesysmalloc 54 55 /* paranoid version of system's malloc() */ 56 57 Malloc_t 58 Perl_safesysmalloc(MEM_SIZE size) 59 { 60 dTHX; 61 Malloc_t ptr; 62 #ifdef HAS_64K_LIMIT 63 if (size > 0xffff) { (gdb) macro expand dTHX expands to: PerlInterpreter *my_perl __attribute__((unused)) = ((PerlInterpreter *)pthread_getspecific(PL_thr_key)) (gdb) p PL_thr_key $1 = 3 (gdb) p my_perl $2 = (PerlInterpreter *) 0x0
So it seems Perl_safesysmalloc depends on PERL_SET_CONTEXT. This patch fixes the segfault, but I'm not sure it's an acceptable solution:
Index: src/modules/perl/modperl_module.c =================================================================== RCS file: /home/cvspublic/modperl-2.0/src/modules/perl/modperl_module.c,v retrieving revision 1.17 diff -u -r1.17 modperl_module.c --- src/modules/perl/modperl_module.c 4 Mar 2004 06:01:07 -0000 1.17 +++ src/modules/perl/modperl_module.c 2 Oct 2004 04:06:04 -0000 @@ -185,6 +185,7 @@ #ifdef USE_ITHREADS interp = modperl_interp_pool_select(p, s); aTHX = interp->perl; + PERL_SET_CONTEXT(aTHX); #endif
table = modperl_module_config_table_get(aTHX_ TRUE);
It is a perfectly correct solution. You can find quite a few other examples of the same thing in the mp2 code. The problem is that perl was originally written w/o multiplicity support. When later on that support was added, many of the internal functions (like malloc/free wrappers) were still relying on the global context, and no one has bothered to provide a new API that will accept aTHX as an argument. Not only it sucks that we have this kind of problem (we have bumped into and solved many of this kind before), the overhead of calling PERL_GET_CONTEXT in the threaded enviroment becomes pretty significant since functions like malloc/free are called very often. I was planning to provide that alternative set of API for perl for a long time already, but it probably won't happen until after mp2 is released.
What I'm interested in is why I can't reproduce that problem. And if you could come up with an explicit test that exposes that problem clearly and exercises just that, it's a good idea to add it to the test suite, so in the future we don't accidently "optimise" it away, when doing some refactoring.
-- __________________________________________________________________ Stas Bekman JAm_pH ------> Just Another mod_perl Hacker http://stason.org/ mod_perl Guide ---> http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
