1
/* Copyright 2001-2004 The Apache Software Foundation
3
* Licensed under the Apache License, Version 2.0 (the "License");
4
* you may not use this file except in compliance with the License.
5
* You may obtain a copy of the License at
7
* http://www.apache.org/licenses/LICENSE-2.0
9
* Unless required by applicable law or agreed to in writing, software
10
* distributed under the License is distributed on an "AS IS" BASIS,
11
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
* See the License for the specific language governing permissions and
13
* limitations under the License.
1
16
#ifndef MODPERL_XS_H
2
17
#define MODPERL_XS_H
41
56
#define mpxs_sv_cur_set(sv, len) MP_SvCUR_set(sv, len)
43
#define mpxs_set_targ(func, arg) \
47
func(aTHX_ TARG, arg); \
58
#define mpxs_set_targ(func, arg) \
62
func(aTHX_ TARG, arg); \
52
#define mpxs_cv_name() \
53
HvNAME(GvSTASH(CvGV(cv))), GvNAME(CvGV(cv))
55
#define mpxs_sv_is_object(sv) \
56
(SvROK(sv) && (SvTYPE(SvRV(sv)) == SVt_PVMG))
58
#define mpxs_sv_object_deref(sv, type) \
59
(mpxs_sv_is_object(sv) ? (type *)SvIVX((SV*)SvRV(sv)) : NULL)
61
#define mpxs_sv2_obj(obj, sv) \
62
(obj = mp_xs_sv2_##obj(sv))
64
#define mpxs_usage_items_1(arg) \
66
Perl_croak(aTHX_ "usage: %s::%s(%s)", \
67
mpxs_cv_name(), arg); \
70
#define mpxs_usage_va(i, obj, msg) \
71
if ((items < i) || !(mpxs_sv2_obj(obj, *MARK))) { \
72
Perl_croak(aTHX_ "usage: %s", msg); \
67
#define mpxs_cv_name() \
68
HvNAME(GvSTASH(CvGV(cv))), GvNAME(CvGV(cv))
70
#define mpxs_sv_is_object(sv) \
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)
76
#define mpxs_sv2_obj(obj, sv) \
77
(obj = mp_xs_sv2_##obj(sv))
79
#define mpxs_usage_items_1(arg) \
81
Perl_croak(aTHX_ "usage: %s::%s(%s)", \
82
mpxs_cv_name(), arg); \
85
#define mpxs_usage_va(i, obj, msg) \
86
if ((items < i) || !(mpxs_sv2_obj(obj, *MARK))) { \
87
Perl_croak(aTHX_ "usage: %s", msg); \
76
91
#define mpxs_usage_va_1(obj, msg) mpxs_usage_va(1, obj, msg)
78
#define mpxs_usage_va_2(obj, arg, msg) \
79
mpxs_usage_va(2, obj, msg); \
93
#define mpxs_usage_va_2(obj, arg, msg) \
94
mpxs_usage_va(2, obj, msg); \
82
97
/* XXX: we probably shouldn't croak here */
83
#define mpxs_write_loop(func, obj) \
84
while (MARK <= SP) { \
87
char *buf = SvPV(*MARK, wlen); \
88
MP_TRACE_o(MP_FUNC, "%d bytes [%s]", wlen, buf); \
89
rv = func(aTHX_ obj, buf, &wlen); \
90
if (rv != APR_SUCCESS) { \
91
Perl_croak(aTHX_ modperl_apr_strerror(rv)); \
98
#define mpxs_write_loop(func, obj) \
99
while (MARK <= SP) { \
102
char *buf = SvPV(*MARK, wlen); \
103
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)); \
97
112
#endif /* MODPERL_XS_H */