24
24
#define mp_xs_sv2_APR__Table(sv) \
25
25
(apr_table_t *)modperl_hash_tied_object(aTHX_ "APR::Table", sv)
27
#define mpxs_Apache__RequestRec_pool(r) r->pool
28
#define mpxs_Apache__Connection_pool(c) c->pool
29
#define mpxs_Apache__URI_pool(u) ((modperl_uri_t *)u)->pool
27
#define mpxs_Apache2__RequestRec_pool(r) r->pool
28
#define mpxs_Apache2__Connection_pool(c) c->pool
29
#define mpxs_Apache2__URI_pool(u) ((modperl_uri_t *)u)->pool
30
30
#define mpxs_APR__URI_pool(u) ((modperl_uri_t *)u)->pool
70
70
#define mpxs_sv_is_object(sv) \
71
71
(SvROK(sv) && (SvTYPE(SvRV(sv)) == SVt_PVMG))
73
#define mpxs_sv_object_deref(sv, type) \
74
(mpxs_sv_is_object(sv) ? (type *)SvIVX((SV*)SvRV(sv)) : NULL)
73
#define mpxs_sv_object_deref(sv, type) \
74
(mpxs_sv_is_object(sv) ? \
75
INT2PTR(type *, SvIVX((SV*)SvRV(sv))) : NULL)
76
77
#define mpxs_sv2_obj(obj, sv) \
77
78
(obj = mp_xs_sv2_##obj(sv))
94
95
mpxs_usage_va(2, obj, msg); \
97
/* XXX: we probably shouldn't croak here */
98
#define mpxs_write_loop(func, obj) \
98
#define mpxs_write_loop(func, obj, name) \
99
99
while (MARK <= SP) { \
100
100
apr_size_t wlen; \
102
101
char *buf = SvPV(*MARK, wlen); \
103
102
MP_TRACE_o(MP_FUNC, "%d bytes [%s]", wlen, buf); \
104
rv = func(aTHX_ obj, buf, &wlen); \
105
if (rv != APR_SUCCESS) { \
106
Perl_croak(aTHX_ modperl_error_strerror(aTHX_ rv)); \
103
MP_RUN_CROAK(func(aTHX_ obj, buf, &wlen), name); \
108
/* custom pool objects created by modperl users (not internal like
109
* r->pool) are marked by magic in SvRV(obj)
111
#define mpxs_pool_is_custom(pool) (mg_find(pool, PERL_MAGIC_ext) != NULL)
113
/* several methods need to ensure that the pool that they take as an
114
* object doesn't go out of scope before the object that they return,
115
* since if this happens, the data contained in the later object
116
* becomes corrupted. this macro is used in various xs files where
118
#if ((PERL_REVISION == 5) && (PERL_VERSION >= 8))
119
/* sometimes the added magic is the second one (e.g. in case when
120
* the object is generated by modperl_hash_tie, so under 5.8+
121
* need to use sv_magicext, since sv_magicext does only one magic
122
* of the same type at 5.8+ */
123
#define mpxs_add_pool_magic_doit(obj, pool_obj) \
124
sv_magicext(SvRV(obj), pool_obj, PERL_MAGIC_ext, NULL, Nullch, -1)
126
#define mpxs_add_pool_magic_doit(obj, pool_obj) \
127
sv_magic(SvRV(obj), pool_obj, PERL_MAGIC_ext, Nullch, -1)
130
/* add dependency magic only for custom pools. there are all kind of
131
* complications when more than one magic of the same type(in this
132
* case PERL_MAGIC_ext is added), luckily most of the PERL_MAGIC_ext
133
* magic used by modperl-core, uses Nullsv as mg->mg_obj, therefore
134
* the following code tries to workaround the multiple magic issue, by
135
* simply hanging the pool object into the unused slot, incrementing
136
* its refcnt just like sv_magic does internally. In case we ever hit
137
* magic which already has mg->mg_obj taken we will deal with that,
138
* for now we just croak in such a case.
140
#define mpxs_add_pool_magic(obj, pool_obj) \
141
if (mpxs_pool_is_custom(SvRV(pool_obj))) { \
142
MAGIC *mg = mg_find(SvRV(obj), PERL_MAGIC_ext); \
144
if (mg->mg_obj == Nullsv) { \
145
mg->mg_obj = SvREFCNT_inc(SvRV(pool_obj)); \
146
mg->mg_flags |= MGf_REFCOUNTED; \
149
Perl_croak(aTHX_ "Fixme: don't know how to " \
150
"handle magic w/ occupied mg->mg_obj"); \
154
mpxs_add_pool_magic_doit(obj, SvRV(pool_obj)); \
112
159
#endif /* MODPERL_XS_H */