1 #define NEED_newRV_noinc_GLOBAL
2 #define NEED_sv_2pv_flags_GLOBAL
3 #define NEED_sv_2pv_nolen_GLOBAL
4 #define NEED_newSVpvn_flags_GLOBAL
8 mop_call_xs (pTHX_ XSPROTO(subaddr), CV *cv, SV **mark)
16 #if PERL_BCDVERSION >= 0x5010000
18 mop_check_package_cache_flag (pTHX_ HV *stash)
20 assert(SvTYPE(stash) == SVt_PVHV);
22 /* here we're trying to implement a c version of mro::get_pkg_gen($stash),
23 * however the perl core doesn't make it easy for us. It doesn't provide an
24 * api that just does what we want.
26 * However, we know that the information we want is, inside the core,
27 * available using HvMROMETA(stash)->pkg_gen. Unfortunately, although the
28 * HvMROMETA macro is public, it is implemented using Perl_mro_meta_init,
29 * which is not public and only available inside the core, as the mro
30 * interface as well as the structure returned by mro_meta_init isn't
31 * considered to be stable yet.
33 * Perl_mro_meta_init isn't declared static, so we could just define it
34 * ourselfs if perls headers don't do that for us, except that won't work
35 * on platforms where symbols need to be explicitly exported when linking
38 * So our, hopefully temporary, solution is to be even more evil and
39 * basically reimplement HvMROMETA in a very fragile way that'll blow up
40 * when the relevant parts of the mro implementation in core change.
46 return HvAUX(stash)->xhv_mro_meta
47 ? HvAUX(stash)->xhv_mro_meta->pkg_gen
51 #else /* pre 5.10.0 */
54 mop_check_package_cache_flag (pTHX_ HV *stash)
56 PERL_UNUSED_ARG(stash);
57 assert(SvTYPE(stash) == SVt_PVHV);
59 return PL_sub_generation;
64 mop_call0 (pTHX_ SV *const self, SV *const method)
73 call_sv(method, G_SCALAR | G_METHOD);
83 mop_call1 (pTHX_ SV *const self, SV *const method, SV* const arg1)
94 call_sv(method, G_SCALAR | G_METHOD);
105 mop_get_code_info (SV *coderef, char **pkg, char **name)
107 if (!SvOK(coderef) || !SvROK(coderef) || SvTYPE(SvRV(coderef)) != SVt_PVCV) {
111 coderef = SvRV(coderef);
113 /* sub is still being compiled */
114 if (!CvGV(coderef)) {
118 /* I think this only gets triggered with a mangled coderef, but if
119 we hit it without the guard, we segfault. The slightly odd return
120 value strikes me as an improvement (mst)
123 if ( isGV_with_GP(CvGV(coderef)) ) {
124 GV *gv = CvGV(coderef);
125 *pkg = HvNAME( GvSTASH(gv) ? GvSTASH(gv) : CvSTASH(coderef) );
126 *name = GvNAME( CvGV(coderef) );
128 *pkg = "__UNKNOWN__";
136 mop_get_package_symbols (HV *stash, type_filter_t filter, get_package_symbols_cb_t cb, void *ud)
141 (void)hv_iterinit(stash);
143 if (filter == TYPE_FILTER_NONE) {
144 while ( (he = hv_iternext(stash)) ) {
146 const char *key = HePV(he, keylen);
147 if (!cb(key, keylen, HeVAL(he), ud)) {
154 while ( (he = hv_iternext(stash)) ) {
155 GV * const gv = (GV*)HeVAL(he);
157 const char * const key = HePV(he, keylen);
162 case TYPE_FILTER_CODE: sv = (SV *)GvCVu(gv); break;
163 case TYPE_FILTER_ARRAY: sv = (SV *)GvAV(gv); break;
164 case TYPE_FILTER_IO: sv = (SV *)GvIO(gv); break;
165 case TYPE_FILTER_HASH: sv = (SV *)GvHV(gv); break;
166 case TYPE_FILTER_SCALAR: sv = (SV *)GvSV(gv); break;
168 croak("Unknown type");
171 /* expand the gv into a real typeglob if it
172 * contains stub functions or constants and we
173 * were asked to return CODE references */
174 else if (filter == TYPE_FILTER_CODE) {
175 gv_init(gv, stash, key, keylen, GV_ADDMULTI);
180 if (!cb(key, keylen, sv, ud)) {
188 collect_all_symbols (const char *key, STRLEN keylen, SV *val, void *ud)
193 if (!hv_store (hash, key, keylen, newRV_inc(val), 0)) {
194 croak("failed to store symbol ref");
201 mop_get_all_package_symbols (HV *stash, type_filter_t filter)
205 mop_get_package_symbols (stash, filter, collect_all_symbols, ret);
211 mop_mg_find(pTHX_ SV* const sv, const MGVTBL* const vtbl, I32 const flags){
215 for(mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic){
216 if(mg->mg_virtual == vtbl){
221 if(flags & MOPf_DIE_ON_FAIL){
222 croak("mop_mg_find: no MAGIC found for %"SVf, sv_2mortal(newRV_inc(sv)));