Where Online Learning is simpler!
The C and C++ Include Header Files
/usr/include/apache2/modperl_xs_util.h
$ cat -n /usr/include/apache2/modperl_xs_util.h 1 /* Licensed to the Apache Software Foundation (ASF) under one or more 2 * contributor license agreements. See the NOTICE file distributed with 3 * this work for additional information regarding copyright ownership. 4 * The ASF licenses this file to You under the Apache License, Version 2.0 5 * (the "License"); you may not use this file except in compliance with 6 * the License. You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef MODPERL_XS_H 18 #define MODPERL_XS_H 19 20 /* XXX: should be part of generation */ 21 #undef mp_xs_sv2_r /* defined in modperl_xs_sv_convert.h */ 22 #define mp_xs_sv2_r(sv) modperl_sv2request_rec(aTHX_ sv) 23 24 #undef mp_xs_sv2_APR__Table 25 #define mp_xs_sv2_APR__Table(sv) \ 26 (apr_table_t *)modperl_hash_tied_object(aTHX_ "APR::Table", sv) 27 28 #define mpxs_Apache2__RequestRec_pool(r) r->pool 29 #define mpxs_Apache2__Connection_pool(c) c->pool 30 #define mpxs_Apache2__URI_pool(u) ((modperl_uri_t *)u)->pool 31 #define mpxs_APR__URI_pool(u) ((modperl_uri_t *)u)->pool 32 33 #ifndef dAX 34 # define dAX I32 ax = mark - PL_stack_base + 1 35 #endif 36 37 #ifndef dITEMS 38 # define dITEMS I32 items = SP - MARK 39 #endif 40 41 #define mpxs_PPCODE(code) STMT_START { \ 42 SP -= items; \ 43 code; \ 44 PUTBACK; \ 45 } STMT_END 46 47 #define PUSHs_mortal_iv(iv) PUSHs(sv_2mortal(newSViv(iv))) 48 #define PUSHs_mortal_pv(pv) PUSHs(sv_2mortal(newSVpv((char *)pv,0))) 49 50 #define XPUSHs_mortal_iv(iv) EXTEND(SP, 1); PUSHs_mortal_iv(iv) 51 #define XPUSHs_mortal_pv(pv) EXTEND(SP, 1); PUSHs_mortal_pv(pv) 52 53 /* XXX: replace the old mpxs_sv_ macros with MP_Sv macros */ 54 55 #define mpxs_sv_grow(sv, len) MP_SvGROW(sv, len) 56 57 #define mpxs_sv_cur_set(sv, len) MP_SvCUR_set(sv, len) 58 59 #define mpxs_set_targ(func, arg) \ 60 STMT_START { \ 61 dXSTARG; \ 62 XSprePUSH; \ 63 func(aTHX_ TARG, arg); \ 64 PUSHTARG; \ 65 XSRETURN(1); \ 66 } STMT_END 67 68 #define mpxs_cv_name() \ 69 HvNAME(GvSTASH(CvGV(cv))), GvNAME(CvGV(cv)) 70 71 #define mpxs_sv_is_object(sv) \ 72 (SvROK(sv) && (SvTYPE(SvRV(sv)) == SVt_PVMG)) 73 74 #define mpxs_sv_object_deref(sv, type) \ 75 (mpxs_sv_is_object(sv) ? \ 76 INT2PTR(type *, SvIVX((SV*)SvRV(sv))) : NULL) 77 78 #define mpxs_sv2_obj(obj, sv) \ 79 (obj = mp_xs_sv2_##obj(sv)) 80 81 #define mpxs_usage_items_1(arg) \ 82 if (items != 1) { \ 83 Perl_croak(aTHX_ "usage: %s::%s(%s)", \ 84 mpxs_cv_name(), arg); \ 85 } 86 87 #define mpxs_usage_va(i, obj, msg) \ 88 if ((items < i) || !(mpxs_sv2_obj(obj, *MARK))) { \ 89 Perl_croak(aTHX_ "usage: %s", msg); \ 90 } \ 91 MARK++ 92 93 #define mpxs_usage_va_1(obj, msg) mpxs_usage_va(1, obj, msg) 94 95 #define mpxs_usage_va_2(obj, arg, msg) \ 96 mpxs_usage_va(2, obj, msg); \ 97 arg = *MARK++ 98 99 #define mpxs_write_loop(func, obj, name) \ 100 while (MARK <= SP) { \ 101 apr_size_t wlen; \ 102 char *buf = SvPV(*MARK, wlen); \ 103 MP_TRACE_o(MP_FUNC, "%d bytes [%s]", wlen, buf); \ 104 MP_RUN_CROAK(func(aTHX_ obj, buf, &wlen), name); \ 105 bytes += wlen; \ 106 MARK++; \ 107 } 108 109 /* custom pool objects created by modperl users (not internal like 110 * r->pool) are marked by magic in SvRV(obj) 111 */ 112 #define mpxs_pool_is_custom(pool) (mg_find(pool, PERL_MAGIC_ext) != NULL) 113 114 /* several methods need to ensure that the pool that they take as an 115 * object doesn't go out of scope before the object that they return, 116 * since if this happens, the data contained in the later object 117 * becomes corrupted. this macro is used in various xs files where 118 * it's needed */ 119 #if ((PERL_REVISION == 5) && (PERL_VERSION >= 8)) 120 /* sometimes the added magic is the second one (e.g. in case when 121 * the object is generated by modperl_hash_tie, so under 5.8+ 122 * need to use sv_magicext, since sv_magicext does only one magic 123 * of the same type at 5.8+ */ 124 #define mpxs_add_pool_magic_doit(obj, pool_obj) \ 125 sv_magicext(SvRV(obj), pool_obj, PERL_MAGIC_ext, NULL, (char *)NULL, -1) 126 #else 127 #define mpxs_add_pool_magic_doit(obj, pool_obj) \ 128 sv_magic(SvRV(obj), pool_obj, PERL_MAGIC_ext, (char *)NULL, -1) 129 #endif 130 131 /* add dependency magic only for custom pools. there are all kind of 132 * complications when more than one magic of the same type(in this 133 * case PERL_MAGIC_ext is added), luckily most of the PERL_MAGIC_ext 134 * magic used by modperl-core, uses (SV *)NULL as mg->mg_obj, therefore 135 * the following code tries to workaround the multiple magic issue, by 136 * simply hanging the pool object into the unused slot, incrementing 137 * its refcnt just like sv_magic does internally. In case we ever hit 138 * magic which already has mg->mg_obj taken we will deal with that, 139 * for now we just croak in such a case. 140 */ 141 #define mpxs_add_pool_magic(obj, pool_obj) \ 142 if (mpxs_pool_is_custom(SvRV(pool_obj))) { \ 143 MAGIC *mg = mg_find(SvRV(obj), PERL_MAGIC_ext); \ 144 if (mg) { \ 145 if (mg->mg_obj == (SV *)NULL) { \ 146 mg->mg_obj = SvREFCNT_inc(SvRV(pool_obj)); \ 147 mg->mg_flags |= MGf_REFCOUNTED; \ 148 } \ 149 else { \ 150 Perl_croak(aTHX_ "Fixme: don't know how to " \ 151 "handle magic w/ occupied mg->mg_obj"); \ 152 } \ 153 } \ 154 else { \ 155 mpxs_add_pool_magic_doit(obj, SvRV(pool_obj)); \ 156 } \ 157 } 158 159 160 #endif /* MODPERL_XS_H */ 161 162 /* 163 * Local Variables: 164 * c-basic-offset: 4 165 * indent-tabs-mode: nil 166 * End: 167 */
Contact us
|
About us
|
Term of use
|
Copyright © 2000-2025 MyWebUniversity.com ™