f87e7c4a31d5cb25782c59918da4ec4c71e022d2
[p5sagit/p5-mst-13.2.git] / ext / Thread / Thread.xs
1 #define PERL_NO_GET_CONTEXT
2 #include "EXTERN.h"
3 #include "perl.h"
4 #include "XSUB.h"
5
6 /* Magic signature for Thread's mg_private is "Th" */ 
7 #define Thread_MAGIC_SIGNATURE 0x5468
8
9 #ifdef __cplusplus
10 #ifdef I_UNISTD
11 #include <unistd.h>
12 #endif
13 #endif
14 #include <fcntl.h>
15                         
16 static int sig_pipe[2];
17             
18 #ifndef THREAD_RET_TYPE
19 #define THREAD_RET_TYPE void *
20 #define THREAD_RET_CAST(x) ((THREAD_RET_TYPE) x)
21 #endif
22
23 static void
24 remove_thread(pTHX_ Thread t)
25 {
26 #ifdef USE_THREADS
27     DEBUG_S(WITH_THR(PerlIO_printf(Perl_debug_log,
28                                    "%p: remove_thread %p\n", thr, t)));
29     MUTEX_LOCK(&PL_threads_mutex);
30     MUTEX_DESTROY(&t->mutex);
31     PL_nthreads--;
32     t->prev->next = t->next;
33     t->next->prev = t->prev;
34     SvREFCNT_dec(t->oursv);
35     COND_BROADCAST(&PL_nthreads_cond);
36     MUTEX_UNLOCK(&PL_threads_mutex);
37 #endif
38 }
39
40 static THREAD_RET_TYPE
41 threadstart(void *arg)
42 {
43 #ifdef USE_THREADS
44 #ifdef FAKE_THREADS
45     Thread savethread = thr;
46     LOGOP myop;
47     dSP;
48     I32 oldscope = PL_scopestack_ix;
49     I32 retval;
50     AV *av;
51     int i;
52
53     DEBUG_S(PerlIO_printf(Perl_debug_log, "new thread %p starting at %s\n",
54                           thr, SvPEEK(TOPs)));
55     thr = (Thread) arg;
56     savemark = TOPMARK;
57     thr->prev = thr->prev_run = savethread;
58     thr->next = savethread->next;
59     thr->next_run = savethread->next_run;
60     savethread->next = savethread->next_run = thr;
61     thr->wait_queue = 0;
62     thr->private = 0;
63
64     /* Now duplicate most of perl_call_sv but with a few twists */
65     PL_op = (OP*)&myop;
66     Zero(PL_op, 1, LOGOP);
67     myop.op_flags = OPf_STACKED;
68     myop.op_next = Nullop;
69     myop.op_flags |= OPf_KNOW;
70     myop.op_flags |= OPf_WANT_LIST;
71     PL_op = pp_entersub(ARGS);
72     DEBUG_S(if (!PL_op)
73             PerlIO_printf(Perl_debug_log, "thread starts at Nullop\n"));
74     /*
75      * When this thread is next scheduled, we start in the right
76      * place. When the thread runs off the end of the sub, perl.c
77      * handles things, using savemark to figure out how much of the
78      * stack is the return value for any join.
79      */
80     thr = savethread;           /* back to the old thread */
81     return 0;
82 #else
83     Thread thr = (Thread) arg;
84     LOGOP myop;
85     dSP;
86     I32 oldmark = TOPMARK;
87     I32 oldscope = PL_scopestack_ix;
88     I32 retval;
89     SV *sv;
90     AV *av;
91     int i, ret;
92     dJMPENV;
93
94 #if defined(MULTIPLICITY)
95     PERL_SET_INTERP(thr->interp);
96 #endif
97
98     DEBUG_S(PerlIO_printf(Perl_debug_log, "new thread %p waiting to start\n",
99                           thr));
100
101     /*
102      * Wait until our creator releases us. If we didn't do this, then
103      * it would be potentially possible for out thread to carry on and
104      * do stuff before our creator fills in our "self" field. For example,
105      * if we went and created another thread which tried to JOIN with us,
106      * then we'd be in a mess.
107      */
108     MUTEX_LOCK(&thr->mutex);
109     MUTEX_UNLOCK(&thr->mutex);
110
111     /*
112      * It's safe to wait until now to set the thread-specific pointer
113      * from our pthread_t structure to our struct perl_thread, since
114      * we're the only thread who can get at it anyway.
115      */
116     PERL_SET_THX(thr);
117
118     DEBUG_S(PerlIO_printf(Perl_debug_log, "new thread %p starting at %s\n",
119                           thr, SvPEEK(TOPs)));
120
121     av = newAV();
122     sv = POPs;
123     PUTBACK;
124     ENTER;
125     SAVETMPS;
126     perl_call_sv(sv, G_ARRAY|G_EVAL);
127     SPAGAIN;
128     retval = SP - (PL_stack_base + oldmark);
129     SP = PL_stack_base + oldmark + 1;
130     if (SvCUR(thr->errsv)) {
131         MUTEX_LOCK(&thr->mutex);
132         thr->flags |= THRf_DID_DIE;
133         MUTEX_UNLOCK(&thr->mutex);
134         av_store(av, 0, &PL_sv_no);
135         av_store(av, 1, newSVsv(thr->errsv));
136         DEBUG_S(PerlIO_printf(Perl_debug_log, "%p died: %s\n",
137                               thr, SvPV(thr->errsv, PL_na)));
138     }
139     else {
140         DEBUG_S(STMT_START {
141             for (i = 1; i <= retval; i++) {
142                 PerlIO_printf(Perl_debug_log, "%p return[%d] = %s\n",
143                                 thr, i, SvPEEK(SP[i - 1]));
144             }
145         } STMT_END);
146         av_store(av, 0, &PL_sv_yes);
147         for (i = 1; i <= retval; i++, SP++)
148             sv_setsv(*av_fetch(av, i, TRUE), SvREFCNT_inc(*SP));
149     }
150     FREETMPS;
151     LEAVE;
152
153   finishoff:
154 #if 0    
155     /* removed for debug */
156     SvREFCNT_dec(PL_curstack);
157 #endif
158     SvREFCNT_dec(thr->cvcache);
159     SvREFCNT_dec(thr->threadsv);
160     SvREFCNT_dec(thr->specific);
161     SvREFCNT_dec(thr->errsv);
162
163     /*Safefree(cxstack);*/
164     while (PL_curstackinfo->si_next)
165         PL_curstackinfo = PL_curstackinfo->si_next;
166     while (PL_curstackinfo) {
167         PERL_SI *p = PL_curstackinfo->si_prev;
168         SvREFCNT_dec(PL_curstackinfo->si_stack);
169         Safefree(PL_curstackinfo->si_cxstack);
170         Safefree(PL_curstackinfo);
171         PL_curstackinfo = p;
172     }    
173     Safefree(PL_markstack);
174     Safefree(PL_scopestack);
175     Safefree(PL_savestack);
176     Safefree(PL_retstack);
177     Safefree(PL_tmps_stack);
178     SvREFCNT_dec(PL_ofs_sv);
179
180     SvREFCNT_dec(PL_rs);
181     SvREFCNT_dec(PL_nrs);
182     SvREFCNT_dec(PL_statname);
183     SvREFCNT_dec(PL_errors);
184     Safefree(PL_screamfirst);
185     Safefree(PL_screamnext);
186     Safefree(PL_reg_start_tmp);
187     SvREFCNT_dec(PL_lastscream);
188     SvREFCNT_dec(PL_defoutgv);
189     Safefree(PL_reg_poscache);
190
191     MUTEX_LOCK(&thr->mutex);
192     thr->thr_done = 1;
193     DEBUG_S(PerlIO_printf(Perl_debug_log,
194                           "%p: threadstart finishing: state is %u\n",
195                           thr, ThrSTATE(thr)));
196     switch (ThrSTATE(thr)) {
197     case THRf_R_JOINABLE:
198         ThrSETSTATE(thr, THRf_ZOMBIE);
199         MUTEX_UNLOCK(&thr->mutex);
200         DEBUG_S(PerlIO_printf(Perl_debug_log,
201                               "%p: R_JOINABLE thread finished\n", thr));
202         break;
203     case THRf_R_JOINED:
204         ThrSETSTATE(thr, THRf_DEAD);
205         MUTEX_UNLOCK(&thr->mutex);
206         remove_thread(aTHX_ thr);
207         DEBUG_S(PerlIO_printf(Perl_debug_log,
208                               "%p: R_JOINED thread finished\n", thr));
209         break;
210     case THRf_R_DETACHED:
211         ThrSETSTATE(thr, THRf_DEAD);
212         MUTEX_UNLOCK(&thr->mutex);
213         SvREFCNT_dec(av);
214         DEBUG_S(PerlIO_printf(Perl_debug_log,
215                               "%p: DETACHED thread finished\n", thr));
216         remove_thread(aTHX_ thr);       /* This might trigger main thread to finish */
217         break;
218     default:
219         MUTEX_UNLOCK(&thr->mutex);
220         croak("panic: illegal state %u at end of threadstart", ThrSTATE(thr));
221         /* NOTREACHED */
222     }
223     return THREAD_RET_CAST(av); /* Available for anyone to join with */
224                                         /* us unless we're detached, in which */
225                                         /* case noone sees the value anyway. */
226 #endif    
227 #else
228     return THREAD_RET_CAST(NULL);
229 #endif
230 }
231
232 static SV *
233 newthread (pTHX_ SV *startsv, AV *initargs, char *classname)
234 {
235 #ifdef USE_THREADS
236     dSP;
237     Thread savethread;
238     int i;
239     SV *sv;
240     int err;
241 #ifndef THREAD_CREATE
242     static pthread_attr_t attr;
243     static int attr_inited = 0;
244     sigset_t fullmask, oldmask;
245     static int attr_joinable = PTHREAD_CREATE_JOINABLE;
246 #endif
247
248     savethread = thr;
249     thr = new_struct_thread(thr);
250     /* temporarily pretend to be the child thread in case the
251      * XPUSHs() below want to grow the child's stack.  This is
252      * safe, since the other thread is not yet created, and we
253      * are the only ones who know about it */
254     PERL_SET_THX(thr);
255     SPAGAIN;
256     DEBUG_S(PerlIO_printf(Perl_debug_log,
257                           "%p: newthread (%p), tid is %u, preparing stack\n",
258                           savethread, thr, thr->tid));
259     /* The following pushes the arg list and startsv onto the *new* stack */
260     PUSHMARK(SP);
261     /* Could easily speed up the following greatly */
262     for (i = 0; i <= AvFILL(initargs); i++)
263         XPUSHs(SvREFCNT_inc(*av_fetch(initargs, i, FALSE)));
264     XPUSHs(SvREFCNT_inc(startsv));
265     PUTBACK;
266
267     /* On your marks... */
268     PERL_SET_THX(savethread);
269     MUTEX_LOCK(&thr->mutex);
270
271 #ifdef THREAD_CREATE
272     err = THREAD_CREATE(thr, threadstart);
273 #else    
274     /* Get set...  */
275     sigfillset(&fullmask);
276     if (sigprocmask(SIG_SETMASK, &fullmask, &oldmask) == -1)
277         croak("panic: sigprocmask");
278     err = 0;
279     if (!attr_inited) {
280         attr_inited = 1;
281         err = pthread_attr_init(&attr);
282 #  ifdef PTHREAD_ATTR_SETDETACHSTATE
283         if (err == 0)
284             err = PTHREAD_ATTR_SETDETACHSTATE(&attr, attr_joinable);
285
286 #  else
287         croak("panic: can't pthread_attr_setdetachstate");
288 #  endif
289     }
290     if (err == 0)
291         err = PTHREAD_CREATE(&thr->self, attr, threadstart, (void*) thr);
292 #endif
293
294     if (err) {
295         MUTEX_UNLOCK(&thr->mutex);
296         DEBUG_S(PerlIO_printf(Perl_debug_log,
297                               "%p: create of %p failed %d\n",
298                               savethread, thr, err));
299         /* Thread creation failed--clean up */
300         SvREFCNT_dec(thr->cvcache);
301         remove_thread(aTHX_ thr);
302         for (i = 0; i <= AvFILL(initargs); i++)
303             SvREFCNT_dec(*av_fetch(initargs, i, FALSE));
304         SvREFCNT_dec(startsv);
305         return NULL;
306     }
307
308 #ifdef THREAD_POST_CREATE
309     THREAD_POST_CREATE(thr);
310 #else
311     if (sigprocmask(SIG_SETMASK, &oldmask, 0))
312         croak("panic: sigprocmask");
313 #endif
314
315     sv = newSViv(thr->tid);
316     sv_magic(sv, thr->oursv, '~', 0, 0);
317     SvMAGIC(sv)->mg_private = Thread_MAGIC_SIGNATURE;
318     sv = sv_bless(newRV_noinc(sv), gv_stashpv(classname, TRUE));
319
320     /* Go */
321     MUTEX_UNLOCK(&thr->mutex);
322
323     return sv;
324 #else
325     croak("No threads in this perl");
326     return &PL_sv_undef;
327 #endif
328 }
329
330 static Signal_t handle_thread_signal (int sig);
331
332 static Signal_t
333 handle_thread_signal(int sig)
334 {
335     dTHXo;
336     unsigned char c = (unsigned char) sig;
337     /*
338      * We're not really allowed to call fprintf in a signal handler
339      * so don't be surprised if this isn't robust while debugging
340      * with -DL.
341      */
342     DEBUG_S(PerlIO_printf(Perl_debug_log,
343             "handle_thread_signal: got signal %d\n", sig););
344     write(sig_pipe[1], &c, 1);
345 }
346
347 MODULE = Thread         PACKAGE = Thread
348 PROTOTYPES: DISABLE
349
350 void
351 new(classname, startsv, ...)
352         char *          classname
353         SV *            startsv
354         AV *            av = av_make(items - 2, &ST(2));
355     PPCODE:
356         XPUSHs(sv_2mortal(newthread(aTHX_ startsv, av, classname)));
357
358 void
359 join(t)
360         Thread  t
361         AV *    av = NO_INIT
362         int     i = NO_INIT
363     PPCODE:
364 #ifdef USE_THREADS
365         if (t == thr)
366             croak("Attempt to join self");
367         DEBUG_S(PerlIO_printf(Perl_debug_log, "%p: joining %p (state %u)\n",
368                               thr, t, ThrSTATE(t)););
369         MUTEX_LOCK(&t->mutex);
370         switch (ThrSTATE(t)) {
371         case THRf_R_JOINABLE:
372         case THRf_R_JOINED:
373             ThrSETSTATE(t, THRf_R_JOINED);
374             MUTEX_UNLOCK(&t->mutex);
375             break;
376         case THRf_ZOMBIE:
377             ThrSETSTATE(t, THRf_DEAD);
378             MUTEX_UNLOCK(&t->mutex);
379             remove_thread(aTHX_ t);
380             break;
381         default:
382             MUTEX_UNLOCK(&t->mutex);
383             croak("can't join with thread");
384             /* NOTREACHED */
385         }
386         JOIN(t, &av);
387
388         sv_2mortal((SV*)av);
389
390         if (SvTRUE(*av_fetch(av, 0, FALSE))) {
391             /* Could easily speed up the following if necessary */
392             for (i = 1; i <= AvFILL(av); i++)
393                 XPUSHs(*av_fetch(av, i, FALSE));
394         }
395         else {
396             STRLEN n_a;
397             char *mess = SvPV(*av_fetch(av, 1, FALSE), n_a);
398             DEBUG_S(PerlIO_printf(Perl_debug_log,
399                                   "%p: join propagating die message: %s\n",
400                                   thr, mess));
401             croak(mess);
402         }
403 #endif
404
405 void
406 detach(t)
407         Thread  t
408     CODE:
409 #ifdef USE_THREADS
410         DEBUG_S(PerlIO_printf(Perl_debug_log, "%p: detaching %p (state %u)\n",
411                               thr, t, ThrSTATE(t)););
412         MUTEX_LOCK(&t->mutex);
413         switch (ThrSTATE(t)) {
414         case THRf_R_JOINABLE:
415             ThrSETSTATE(t, THRf_R_DETACHED);
416             /* fall through */
417         case THRf_R_DETACHED:
418             DETACH(t);
419             MUTEX_UNLOCK(&t->mutex);
420             break;
421         case THRf_ZOMBIE:
422             ThrSETSTATE(t, THRf_DEAD);
423             DETACH(t);
424             MUTEX_UNLOCK(&t->mutex);
425             remove_thread(aTHX_ t);
426             break;
427         default:
428             MUTEX_UNLOCK(&t->mutex);
429             croak("can't detach thread");
430             /* NOTREACHED */
431         }
432 #endif
433
434 void
435 equal(t1, t2)
436         Thread  t1
437         Thread  t2
438     PPCODE:
439         PUSHs((t1 == t2) ? &PL_sv_yes : &PL_sv_no);
440
441 void
442 flags(t)
443         Thread  t
444     PPCODE:
445 #ifdef USE_THREADS
446         PUSHs(sv_2mortal(newSViv(t->flags)));
447 #endif
448
449 void
450 done(t)
451         Thread  t
452     PPCODE:
453 #ifdef USE_THREADS
454         PUSHs(t->thr_done ? &PL_sv_yes : &PL_sv_no);
455 #endif
456
457 void
458 self(classname)
459         char *  classname
460     PREINIT:
461         SV *sv;
462     PPCODE:        
463 #ifdef USE_THREADS
464         sv = newSViv(thr->tid);
465         sv_magic(sv, thr->oursv, '~', 0, 0);
466         SvMAGIC(sv)->mg_private = Thread_MAGIC_SIGNATURE;
467         PUSHs(sv_2mortal(sv_bless(newRV_noinc(sv),
468                                   gv_stashpv(classname, TRUE))));
469 #endif
470
471 U32
472 tid(t)
473         Thread  t
474     CODE:
475 #ifdef USE_THREADS
476         MUTEX_LOCK(&t->mutex);
477         RETVAL = t->tid;
478         MUTEX_UNLOCK(&t->mutex);
479 #else 
480         RETVAL = 0;
481 #endif
482     OUTPUT:
483         RETVAL
484
485 void
486 DESTROY(t)
487         SV *    t
488     PPCODE:
489         PUSHs(&PL_sv_yes);
490
491 void
492 yield()
493     CODE:
494 {
495 #ifdef USE_THREADS
496         YIELD;
497 #endif
498 }
499
500 void
501 cond_wait(sv)
502         SV *    sv
503         MAGIC * mg = NO_INIT
504 CODE:                       
505 #ifdef USE_THREADS
506         if (SvROK(sv))
507             sv = SvRV(sv);
508
509         mg = condpair_magic(sv);
510         DEBUG_S(PerlIO_printf(Perl_debug_log, "%p: cond_wait %p\n", thr, sv));
511         MUTEX_LOCK(MgMUTEXP(mg));
512         if (MgOWNER(mg) != thr) {
513             MUTEX_UNLOCK(MgMUTEXP(mg));
514             croak("cond_wait for lock that we don't own\n");
515         }
516         MgOWNER(mg) = 0;
517         COND_SIGNAL(MgOWNERCONDP(mg));
518         COND_WAIT(MgCONDP(mg), MgMUTEXP(mg));
519         while (MgOWNER(mg))
520             COND_WAIT(MgOWNERCONDP(mg), MgMUTEXP(mg));
521         MgOWNER(mg) = thr;
522         MUTEX_UNLOCK(MgMUTEXP(mg));
523 #endif
524
525 void
526 cond_signal(sv)
527         SV *    sv
528         MAGIC * mg = NO_INIT
529 CODE:
530 #ifdef USE_THREADS
531         if (SvROK(sv))
532             sv = SvRV(sv);
533
534         mg = condpair_magic(sv);
535         DEBUG_S(PerlIO_printf(Perl_debug_log, "%p: cond_signal %p\n",thr,sv));
536         MUTEX_LOCK(MgMUTEXP(mg));
537         if (MgOWNER(mg) != thr) {
538             MUTEX_UNLOCK(MgMUTEXP(mg));
539             croak("cond_signal for lock that we don't own\n");
540         }
541         COND_SIGNAL(MgCONDP(mg));
542         MUTEX_UNLOCK(MgMUTEXP(mg));
543 #endif
544
545 void
546 cond_broadcast(sv)
547         SV *    sv
548         MAGIC * mg = NO_INIT
549 CODE: 
550 #ifdef USE_THREADS
551         if (SvROK(sv))
552             sv = SvRV(sv);
553
554         mg = condpair_magic(sv);
555         DEBUG_S(PerlIO_printf(Perl_debug_log, "%p: cond_broadcast %p\n",
556                               thr, sv));
557         MUTEX_LOCK(MgMUTEXP(mg));
558         if (MgOWNER(mg) != thr) {
559             MUTEX_UNLOCK(MgMUTEXP(mg));
560             croak("cond_broadcast for lock that we don't own\n");
561         }
562         COND_BROADCAST(MgCONDP(mg));
563         MUTEX_UNLOCK(MgMUTEXP(mg));
564 #endif
565
566 void
567 list(classname)
568         char *  classname
569     PREINIT:
570         Thread  t;
571         AV *    av;
572         SV **   svp;
573         int     n = 0;
574     PPCODE:
575 #ifdef USE_THREADS
576         av = newAV();
577         /*
578          * Iterate until we have enough dynamic storage for all threads.
579          * We mustn't do any allocation while holding threads_mutex though.
580          */
581         MUTEX_LOCK(&PL_threads_mutex);
582         do {
583             n = PL_nthreads;
584             MUTEX_UNLOCK(&PL_threads_mutex);
585             if (AvFILL(av) < n - 1) {
586                 int i = AvFILL(av);
587                 for (i = AvFILL(av); i < n - 1; i++) {
588                     SV *sv = newSViv(0);        /* fill in tid later */
589                     sv_magic(sv, 0, '~', 0, 0); /* fill in other magic later */
590                     av_push(av, sv_bless(newRV_noinc(sv),
591                                          gv_stashpv(classname, TRUE)));
592         
593                 }
594             }
595             MUTEX_LOCK(&PL_threads_mutex);
596         } while (n < PL_nthreads);
597         n = PL_nthreads;        /* Get the final correct value */
598
599         /*
600          * At this point, there's enough room to fill in av.
601          * Note that we are holding threads_mutex so the list
602          * won't change out from under us but all the remaining
603          * processing is "fast" (no blocking, malloc etc.)
604          */
605         t = thr;
606         svp = AvARRAY(av);
607         do {
608             SV *sv = (SV*)SvRV(*svp);
609             sv_setiv(sv, t->tid);
610             SvMAGIC(sv)->mg_obj = SvREFCNT_inc(t->oursv);
611             SvMAGIC(sv)->mg_flags |= MGf_REFCOUNTED;
612             SvMAGIC(sv)->mg_private = Thread_MAGIC_SIGNATURE;
613             t = t->next;
614             svp++;
615         } while (t != thr);
616         /*  */
617         MUTEX_UNLOCK(&PL_threads_mutex);
618         /* Truncate any unneeded slots in av */
619         av_fill(av, n - 1);
620         /* Finally, push all the new objects onto the stack and drop av */
621         EXTEND(SP, n);
622         for (svp = AvARRAY(av); n > 0; n--, svp++)
623             PUSHs(*svp);
624         (void)sv_2mortal((SV*)av);
625 #endif
626
627
628 MODULE = Thread         PACKAGE = Thread::Signal
629
630 void
631 kill_sighandler_thread()
632     PPCODE:
633         write(sig_pipe[1], "\0", 1);
634         PUSHs(&PL_sv_yes);
635
636 void
637 init_thread_signals()
638     PPCODE:
639         PL_sighandlerp = handle_thread_signal;
640         if (pipe(sig_pipe) == -1)
641             XSRETURN_UNDEF;
642         PUSHs(&PL_sv_yes);
643
644 void
645 await_signal()
646     PREINIT:
647         unsigned char c;
648         SSize_t ret;
649     CODE:
650         do {
651             ret = read(sig_pipe[0], &c, 1);
652         } while (ret == -1 && errno == EINTR);
653         if (ret == -1)
654             croak("panic: await_signal");
655         ST(0) = sv_newmortal();
656         if (ret)
657             sv_setsv(ST(0), c ? PL_psig_ptr[c] : &PL_sv_no);
658         DEBUG_S(PerlIO_printf(Perl_debug_log,
659                               "await_signal returning %s\n", SvPEEK(ST(0))););
660
661 MODULE = Thread         PACKAGE = Thread::Specific
662
663 void
664 data(classname = "Thread::Specific")
665         char *  classname
666     PPCODE:
667 #ifdef USE_THREADS
668         if (AvFILL(thr->specific) == -1) {
669             GV *gv = gv_fetchpv("Thread::Specific::FIELDS", TRUE, SVt_PVHV);
670             av_store(thr->specific, 0, newRV((SV*)GvHV(gv)));
671         }
672         XPUSHs(sv_bless(newRV((SV*)thr->specific),gv_stashpv(classname,TRUE)));
673 #endif