~ubuntu-branches/ubuntu/edgy/libapache2-mod-perl2/edgy

« back to all changes in this revision

Viewing changes to xs/modperl_xs_util.h

  • Committer: Bazaar Package Importer
  • Author(s): Andres Salomon
  • Date: 2005-08-12 01:40:38 UTC
  • mfrom: (1.1.2 upstream) (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20050812014038-gjigefs55pqx4qc8
Tags: 2.0.1-3
Grr.  Really include perl.conf file; it got lost due to diff not
wanting to add an empty file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright 2001-2004 The Apache Software Foundation
 
1
/* Copyright 2001-2005 The Apache Software Foundation
2
2
 *
3
3
 * Licensed under the Apache License, Version 2.0 (the "License");
4
4
 * you may not use this file except in compliance with the License.
24
24
#define mp_xs_sv2_APR__Table(sv)                                        \
25
25
    (apr_table_t *)modperl_hash_tied_object(aTHX_ "APR::Table", sv)
26
26
 
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
31
31
 
32
32
#ifndef dAX
70
70
#define mpxs_sv_is_object(sv)                           \
71
71
    (SvROK(sv) && (SvTYPE(SvRV(sv)) == SVt_PVMG))
72
72
 
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) 
75
76
 
76
77
#define mpxs_sv2_obj(obj, sv)                   \
77
78
    (obj = mp_xs_sv2_##obj(sv))
94
95
    mpxs_usage_va(2, obj, msg);                 \
95
96
    arg = *MARK++
96
97
 
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;                                        \
101
 
        apr_status_t rv;                                        \
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)); \
107
 
        }                                                       \
 
103
        MP_RUN_CROAK(func(aTHX_ obj, buf, &wlen), name);        \
108
104
        bytes += wlen;                                          \
109
105
        MARK++;                                                 \
110
106
    }
111
107
 
 
108
/* custom pool objects created by modperl users (not internal like
 
109
 * r->pool) are marked by magic in SvRV(obj)
 
110
 */
 
111
#define mpxs_pool_is_custom(pool) (mg_find(pool, PERL_MAGIC_ext) != NULL)
 
112
 
 
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
 
117
 * it's needed */
 
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)
 
125
#else
 
126
#define mpxs_add_pool_magic_doit(obj, pool_obj)                         \
 
127
    sv_magic(SvRV(obj), pool_obj, PERL_MAGIC_ext, Nullch, -1)
 
128
#endif
 
129
 
 
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.
 
139
 */
 
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);            \
 
143
        if (mg) {                                                  \
 
144
            if (mg->mg_obj == Nullsv) {                            \
 
145
                mg->mg_obj = SvREFCNT_inc(SvRV(pool_obj));         \
 
146
                mg->mg_flags |= MGf_REFCOUNTED;                    \
 
147
            }                                                      \
 
148
            else {                                                 \
 
149
                Perl_croak(aTHX_ "Fixme: don't know how to "       \
 
150
                           "handle magic w/ occupied mg->mg_obj"); \
 
151
            }                                                      \
 
152
        }                                                          \
 
153
        else {                                                     \
 
154
            mpxs_add_pool_magic_doit(obj, SvRV(pool_obj));         \
 
155
        }                                                          \
 
156
    }
 
157
 
 
158
 
112
159
#endif /* MODPERL_XS_H */