Skip to content

Commit 7a63115

Browse files
author
Jan Kaluža
committed
Add MP_*_CROAK_*_PUTBACK macros to call modperl_croak and also putback
the interpreter if possible. Use them in modperl_filter related code. git-svn-id: https://svn.apache.org/repos/asf/perl/modperl/trunk@1682366 13f79535-47bb-0310-9956-ffa450edef68
1 parent 3b4d4aa commit 7a63115

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

src/modules/perl/modperl_error.h

+40
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,20 @@ char *modperl_error_strerror(pTHX_ apr_status_t rc);
3737

3838
void modperl_croak(pTHX_ apr_status_t rc, const char* func);
3939

40+
#define MP_PUTBACK_IF_USED() STMT_START \
41+
{ \
42+
modperl_interp_t *interp = modperl_thx_interp_get(aTHX); \
43+
if (interp && interp->refcnt > 1) { \
44+
modperl_interp_unselect(interp); \
45+
} \
46+
} STMT_END
47+
48+
#define MP_CROAK_PUTBACK(rc, func) STMT_START \
49+
{ \
50+
MP_PUTBACK_IF_USED(); \
51+
modperl_croak(aTHX_ rc, func); \
52+
} STMT_END
53+
4054
#define MP_RUN_CROAK(rc_run, func) STMT_START \
4155
{ \
4256
apr_status_t rc = rc_run; \
@@ -45,6 +59,15 @@ void modperl_croak(pTHX_ apr_status_t rc, const char* func);
4559
} \
4660
} STMT_END
4761

62+
#define MP_RUN_CROAK_PUTBACK(rc_run, func) STMT_START \
63+
{ \
64+
apr_status_t rc = rc_run; \
65+
if (rc != APR_SUCCESS) { \
66+
MP_PUTBACK_IF_USED(); \
67+
modperl_croak(aTHX_ rc, func); \
68+
} \
69+
} STMT_END
70+
4871
#define MP_RUN_CROAK_RESET_OK(s, rc_run, func) STMT_START \
4972
{ \
5073
apr_status_t rc = rc_run; \
@@ -61,6 +84,23 @@ void modperl_croak(pTHX_ apr_status_t rc, const char* func);
6184
} \
6285
} STMT_END
6386

87+
#define MP_RUN_CROAK_RESET_OK_PUTBACK(s, rc_run, func) STMT_START \
88+
{ \
89+
apr_status_t rc = rc_run; \
90+
if (rc != APR_SUCCESS) { \
91+
if (APR_STATUS_IS_ECONNRESET(rc) || \
92+
APR_STATUS_IS_ECONNABORTED(rc)) { \
93+
ap_log_error(APLOG_MARK, APLOG_INFO, 0, s, \
94+
"%s got: %s", func, \
95+
modperl_error_strerror(aTHX_ rc)); \
96+
} \
97+
else { \
98+
MP_PUTBACK_IF_USED(); \
99+
modperl_croak(aTHX_ rc, func); \
100+
} \
101+
} \
102+
} STMT_END
103+
64104
#endif /* MODPERL_ERROR_H */
65105

66106
/*

src/modules/perl/modperl_filter.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ static apr_status_t modperl_filter_f_cleanup(void *data)
283283
if (ctx->data){
284284
#ifdef USE_ITHREADS
285285
dTHXa(ctx->interp->perl);
286-
MP_ASSERT_CONTEXT(aTHX);
286+
// MP_ASSERT_CONTEXT(aTHX);
287287
#endif
288288
if (SvOK(ctx->data) && SvREFCNT(ctx->data)) {
289289
SvREFCNT_dec(ctx->data);
@@ -535,7 +535,7 @@ int modperl_run_filter(modperl_filter_t *filter)
535535
* pass the bucket brigade through after it called
536536
* $f->read(), since it causes a pre-fetch of the
537537
* bb */
538-
modperl_croak(aTHX_ MODPERL_FILTER_ERROR,
538+
MP_CROAK_PUTBACK(MODPERL_FILTER_ERROR,
539539
"a filter calling $f->read "
540540
"must return OK and not DECLINED");
541541
}
@@ -546,11 +546,11 @@ int modperl_run_filter(modperl_filter_t *filter)
546546
apr_brigade_destroy(filter->bb_in);
547547
filter->bb_in = NULL;
548548
}
549-
MP_RUN_CROAK_RESET_OK(s, modperl_input_filter_flush(filter),
549+
MP_RUN_CROAK_RESET_OK_PUTBACK(s, modperl_input_filter_flush(filter),
550550
"Apache2::Filter internal flush");
551551
}
552552
else {
553-
MP_RUN_CROAK_RESET_OK(s, modperl_output_filter_flush(filter),
553+
MP_RUN_CROAK_RESET_OK_PUTBACK(s, modperl_output_filter_flush(filter),
554554
"Apache2::Filter internal flush");
555555
}
556556

0 commit comments

Comments
 (0)