Nginx-ru mailing list archive (nginx-ru@sysoev.ru)
[Date Prev ][Date Next ][Thread Prev ][Thread Next ][Date Index ][Thread Index ]
Re: использование perl_set
On Fri, 24 Nov 2006, Veryazov Sergey wrote:
Беру код из примера:
http://www.sysoev.ru/nginx/docs/http/ngx_http_perl_module.html
Выдает ошибку:
2006/11/24 12:01:40 [error] 30314#0: *3 call_sv("
sub {
my $r = shift;
my $ua = $r->header_in("User-Agent");
return "" if $ua =~ /Opera/;
return "1" if $ua =~ / MSIE [6-9]\.\d+/;
return "";
}
") failed: "Can't call method "header_in" on an undefined value at (eval
2) line 3."
Оказывается, что параметр запроса не передается в функцию:
perl_set $test 'sub { my $r = shift; return "($r)" }';
в итоге $test = '()';
В чем проблема?
nginx version: nginx/0.4.13
built by gcc 4.1.1 20060525 (Red Hat 4.1.1-1)
$perl -v
This is perl, v5.8.8 built for x86_64-linux-thread-multi
По-видимому, начиная с 0.3.38, nginx не работал с трэдовым перлом.
Патч прилагается.
Игорь Сысоев
http://sysoev.ru Index: src/http/modules/perl/ngx_http_perl_module.c
===================================================================
--- src/http/modules/perl/ngx_http_perl_module.c (revision 187)
+++ src/http/modules/perl/ngx_http_perl_module.c (working copy)
@@ -74,7 +74,7 @@
static char *ngx_http_perl_set(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
static char *ngx_http_perl_interp_max_unsupported(ngx_conf_t *cf, void *post,
void *data);
-#if (NGX_HAVE_PERL_CLONE || NGX_HAVE_PERL_MULTIPLICITY)
+#if (NGX_HAVE_PERL_MULTIPLICITY)
static void ngx_http_perl_cleanup_perl(void *data);
#endif
static void ngx_http_perl_cleanup_sv(void *data);
@@ -478,7 +478,7 @@
static char *
ngx_http_perl_init_interpreter(ngx_conf_t *cf, ngx_http_perl_main_conf_t *pmcf)
{
-#if (NGX_HAVE_PERL_CLONE || NGX_HAVE_PERL_MULTIPLICITY)
+#if (NGX_HAVE_PERL_MULTIPLICITY)
ngx_pool_cleanup_t *cln;
cln = ngx_pool_cleanup_add(cf->pool, 0);
@@ -502,7 +502,7 @@
}
}
-#if !(NGX_HAVE_PERL_CLONE || NGX_HAVE_PERL_MULTIPLICITY)
+#if !(NGX_HAVE_PERL_MULTIPLICITY)
if (perl) {
if (ngx_http_perl_run_requires(aTHX_ &pmcf->requires, cf->log)
@@ -527,7 +527,7 @@
return NGX_CONF_ERROR;
}
-#if (NGX_HAVE_PERL_CLONE || NGX_HAVE_PERL_MULTIPLICITY)
+#if (NGX_HAVE_PERL_MULTIPLICITY)
cln->handler = ngx_http_perl_cleanup_perl;
cln->data = pmcf->perl;
@@ -554,32 +554,6 @@
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, log, 0, "create perl interpreter");
-#if (NGX_HAVE_PERL_CLONE)
-
- if (pmcf->perl) {
-
- perl = perl_clone(pmcf->perl, CLONEf_KEEP_PTR_TABLE);
- if (perl == NULL) {
- ngx_log_error(NGX_LOG_ALERT, log, 0, "perl_clone() failed");
- return NULL;
- }
-
- {
-
- dTHXa(perl);
-
- ptr_table_free(PL_ptr_table);
- PL_ptr_table = NULL;
-
- }
-
- pmcf->nalloc++;
-
- return perl;
- }
-
-#endif
-
perl = perl_alloc();
if (perl == NULL) {
ngx_log_error(NGX_LOG_ALERT, log, 0, "perl_alloc() failed");
@@ -826,7 +800,7 @@
{
ngx_http_perl_main_conf_t *pmcf = conf;
-#if (NGX_HAVE_PERL_CLONE || NGX_HAVE_PERL_MULTIPLICITY)
+#if (NGX_HAVE_PERL_MULTIPLICITY)
ngx_conf_init_uint_value(pmcf->interp_max, 10);
#else
ngx_conf_init_uint_value(pmcf->interp_max, 1);
@@ -844,15 +818,13 @@
}
}
-#if !(NGX_HAVE_PERL_CLONE)
ngx_http_perl_free_interpreter(pmcf, pmcf->perl);
-#endif
return NGX_CONF_OK;
}
-#if (NGX_HAVE_PERL_CLONE || NGX_HAVE_PERL_MULTIPLICITY)
+#if (NGX_HAVE_PERL_MULTIPLICITY)
static void
ngx_http_perl_cleanup_perl(void *data)
@@ -1113,7 +1085,7 @@
static char *
ngx_http_perl_interp_max_unsupported(ngx_conf_t *cf, void *post, void *data)
{
-#if (NGX_HAVE_PERL_CLONE || NGX_HAVE_PERL_MULTIPLICITY)
+#if (NGX_HAVE_PERL_MULTIPLICITY)
return NGX_CONF_OK;
Index: auto/lib/perl/conf
===================================================================
--- auto/lib/perl/conf (revision 187)
+++ auto/lib/perl/conf (working copy)
@@ -36,11 +36,7 @@
echo " + perl interpreter multiplicity found"
fi
- if $NGX_PERL -V:useithreads | grep define > /dev/null; then
- have=NGX_HAVE_PERL_CLONE . auto/have
- echo " + perl_clone() found"
-
- else
+ if $NGX_PERL -V:useithreads | grep undef > /dev/null; then
# FreeBSD port wants to link with -pthread non-threaded perl
ngx_perl_ldopts=`echo $ngx_perl_ldopts | sed 's/ -pthread//'`
fi