summaryrefslogtreecommitdiff
path: root/ext/POSIX
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2011-09-07 16:57:03 +0200
committerNicholas Clark <nick@ccl4.org>2011-09-13 11:28:07 +0200
commita2261f90b6d492d28f8279172b3cd8ed09808927 (patch)
tree7f256daaf2c1fd61afb51a3828b8db9e3c1c68ba /ext/POSIX
parentaa4afdf1b41f5995bc787c295b1262315964e415 (diff)
downloadperl-a2261f90b6d492d28f8279172b3cd8ed09808927.tar.gz
In POSIX.xs, extract allocate_struct() from POSIX::Termios::new().
The same code will be needed for POSIX::SigSet::new(), so share it as a small static function.
Diffstat (limited to 'ext/POSIX')
-rw-r--r--ext/POSIX/POSIX.xs20
1 files changed, 13 insertions, 7 deletions
diff --git a/ext/POSIX/POSIX.xs b/ext/POSIX/POSIX.xs
index f293553e4a..dbe4c240d5 100644
--- a/ext/POSIX/POSIX.xs
+++ b/ext/POSIX/POSIX.xs
@@ -555,6 +555,16 @@ restore_sigmask(pTHX_ SV *osset_sv)
(void)sigprocmask(SIG_SETMASK, ossetp, (sigset_t *)0);
}
+static void *
+allocate_struct(pTHX_ SV *rv, const STRLEN size, const char *packname) {
+ SV *const t = newSVrv(rv, packname);
+ void *const p = sv_grow(t, size + 1);
+
+ SvCUR_set(t, size);
+ SvPOK_on(t);
+ return p;
+}
+
#ifdef WIN32
/*
@@ -718,17 +728,13 @@ new(packname = "POSIX::Termios", ...)
CODE:
{
#ifdef I_TERMIOS
- SV *t;
- ST(0) = sv_newmortal();
- t = newSVrv(ST(0), packname);
- sv_grow(t, sizeof(struct termios) + 1);
- SvCUR_set(t, sizeof(struct termios));
- SvPOK_on(t);
+ void *const p = allocate_struct(aTHX_ (ST(0) = sv_newmortal()),
+ sizeof(struct termios), packname);
/* The previous implementation stored a pointer to an uninitialised
struct termios. Seems safer to initialise it, particularly as
this implementation exposes the struct to prying from perl-space.
*/
- memset(SvPVX(t), 0, 1 + sizeof(struct termios));
+ memset(p, 0, 1 + sizeof(struct termios));
XSRETURN(1);
#else
not_here("termios");