Stas Bekman wrote:
[...]
If you really really feel the need to cheat then you have the choice of these:

#define xhv_keys xiv_u.xivu_iv

typedef struct {
    STRLEN    xhv_fill;    /* how full xhv_array currently is */
    STRLEN    xhv_max;    /* subscript of last element of xhv_array */
    union {
    IV    xivu_iv;    /* integer value or pv offset */
    UV    xivu_uv;
    void *    xivu_p1;
    }        xiv_u;
    MAGIC*    xmg_magic;    /* magic for scalar array */
    HV*        xmg_stash;    /* class package */
} xpvhv_allocated;


Only xmg_magic and xmg_stash aren't needed for the operation of a regular hash. I've no idea what modglobal_ptr gets used for throughout the perl codebase, but hanging something that isn't MAGIC* from xmg_magic feels like a bad plan.

While using xmg_magic or xmg_stash works most of the time, it fails perl_clone at run time, where it tries to clone the member which is not of a proper type (just a pointer cast into MAGIC*), resulting in a segfault:

#7  0xb7aaac57 in Perl_sv_dup (my_perl=0xba9bc88, sstr=0x5, param=0xb685ada0)
    at sv.c:10287
#8 0xb7aaa36a in Perl_mg_dup (my_perl=0xba9bc88, mg=0xadb9608, param=0xb685ada0)
    at sv.c:10056
#9 0xb7aab3bc in Perl_sv_dup (my_perl=0xba9bc88, sstr=0xb2b20c0, param=0xb685ada0)
    at sv.c:10477
#10 0xb7aaf785 in perl_clone (proto_perl=0xaa16dd8, flags=2) at sv.c:11531
#11 0xb7895a8a in Perl_ithread_create (my_perl=0xaa16dd8, obj=0x0,
    classname=0xba98910 "threads", init_function=0xbd412d8, params=0xbc551b8)
    at threads.xs:426

Besides the speed that I have mentioned before, there is another requirement: the get/set should work w/o needing aTHX, therefore using a real magic won't work.

More ideas?

Really, what we are after is the set/get mechanism used by ithreads.xs itself, but it needs to be faster and require no aTHX. If we find one we will be able to speed up ithreads as well. At the moment ithreads.xs does:

void Perl_ithread_set (pTHX_ ithread* thread)
{
  SV* thread_sv = newSViv(PTR2IV(thread));
  if(!hv_store(PL_modglobal, "threads::self", 12, thread_sv,0)) {
    croak("%s\n","Internal error, couldn't set TLS");
  }
}

ithread* Perl_ithread_get (pTHX) {
  SV** thread_sv = hv_fetch(PL_modglobal, "threads::self",12,0);
  if(!thread_sv) {
    croak("%s\n","Internal error, couldn't get TLS");
  }
  return INT2PTR(ithread*,SvIV(*thread_sv));
}


--
__________________________________________________________________
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

Reply via email to