aboutsummaryrefslogtreecommitdiff
path: root/Capture.xs
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2017-07-22 09:26:47 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2017-07-22 09:32:47 +0300
commit4da9775f1d88787517e54f5c1fe1c43f1e023480 (patch)
treea214263c46aea4199cdf32ee0763f53e1e80a05a /Capture.xs
parent5ea83707e0b082687b59469fa422611e18e812bc (diff)
downloadposixruncapture-4da9775f1d88787517e54f5c1fe1c43f1e023480.tar.gz
posixruncapture-4da9775f1d88787517e54f5c1fe1c43f1e023480.tar.bz2
Add new methods for manipulating argv and program pathname
* Capture.xs (capture_new): Use new ARGV typedef. Handle the new "program" keyword. (capture_set_argv_ref, capture_set_program) (capture_argv, capture_program): New methods. * capture.c: Handle out of memory errors. (XS_pack_ARGV, XS_unpack_ARGV): New functions. (capture_new): Change signature. Set the rc_program field. (capture_DESTROY): Destroy cp->program (capture_set_argv_ref): New function. * capture.h (capture) <program>: New member. (ARGV): New typedef. (capture_new): Change signature. (XS_unpack_ARGV, XS_pack_ARGV) (capture_set_argv_ref): New protos. * lib/POSIX/Run/Capture.pm (set_argv): New method. * typemap: Hande ARGV conversions. * runcap: Update.
Diffstat (limited to 'Capture.xs')
-rw-r--r--Capture.xs57
1 files changed, 49 insertions, 8 deletions
diff --git a/Capture.xs b/Capture.xs
index df47544..d85b74c 100644
--- a/Capture.xs
+++ b/Capture.xs
@@ -19,14 +19,15 @@ POSIX::Run::Capture
capture_new(package, ...)
char *package;
PREINIT:
- AV *argv = NULL;
+ ARGV argv = NULL;
unsigned timeout = 0;
SV *cb[2] = { &PL_sv_undef, &PL_sv_undef };
+ SV *prog = &PL_sv_undef;
CODE:
if (items == 2) {
SV *sv = ST(1);
if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVAV) {
- argv = (AV*) SvRV(sv);
+ argv = XS_unpack_ARGV(sv);
} else
croak("single argument must be an array ref");
} else if (items % 2 == 0)
@@ -44,7 +45,7 @@ capture_new(package, ...)
if (strcmp(kw, "argv") == 0) {
if (SvROK(val)
&& SvTYPE(SvRV(val)) == SVt_PVAV) {
- argv = (AV*) SvRV(val);
+ argv = XS_unpack_ARGV(val);
} else
croak("argv must be an array ref");
} else if (strcmp(kw, "stdout") == 0
@@ -59,15 +60,16 @@ capture_new(package, ...)
timeout = SvUV(val);
} else
croak("timeout must be a number of seconds");
+ } else if (strcmp(kw, "program") == 0) {
+ if (SvROK(val))
+ croak("program argument is not a scalar");
+ else
+ prog = val;
} else
croak("unknown keyword argument %s", kw);
}
}
- if (!argv)
- croak("argv not defined");
- RETVAL = capture_new(argv, timeout, cb);
- if (!RETVAL)
- croak("Out of memory!");
+ RETVAL = capture_new(prog, argv, timeout, cb);
OUTPUT:
RETVAL
@@ -75,6 +77,45 @@ void
capture_DESTROY(cp)
POSIX::Run::Capture cp;
+void
+capture_set_argv_ref(cp, argv)
+ POSIX::Run::Capture cp;
+ ARGV argv;
+
+void
+capture_set_program(cp, prog)
+ POSIX::Run::Capture cp;
+ char *prog;
+ CODE:
+ if (cp->program != &PL_sv_undef)
+ SvREFCNT_dec(cp->program);
+ cp->program = ST(1);
+ if (cp->program != &PL_sv_undef) {
+ SvREFCNT_inc(cp->program);
+ cp->rc.rc_program = prog;
+ cp->flags |= RCF_PROGRAM;
+ } else
+ cp->flags &= ~RCF_PROGRAM;
+
+ARGV
+capture_argv(cp)
+ POSIX::Run::Capture cp;
+ CODE:
+ RETVAL = cp->rc.rc_argv;
+ OUTPUT:
+ RETVAL
+
+void
+capture_program(cp)
+ POSIX::Run::Capture cp;
+ PPCODE:
+ if (cp->program == &PL_sv_undef && cp->rc.rc_argv) {
+ ST(0) = newSVpv(cp->rc.rc_argv[0], 0);
+ sv_2mortal(ST(0));
+ } else
+ ST(0) = cp->program;
+ XSRETURN(1);
+
int
capture_run(cp)
POSIX::Run::Capture cp;

Return to:

Send suggestions and report system problems to the System administrator.