| Store | Cart

[perl #122005] deprecate POSIX::tmpnam

From: Tony Cook via RT <perl...@perl.org>
Mon, 21 Jul 2014 19:02:26 -0700
On Sun Jun 01 06:27:39 2014, jhi wrote:
> The tmpnam() interface is known to be dangerous enough that compilers> and even linkers warn against its use.  And POSIX.pod advises> likewise.> > Therefore, POSIX extension probably should stop giving access to the> raw> tmpnam().> > Some options:> > (1) remove it, let users (*) die>  (2) implement it using mkstemp() if available.  (What about platforms>  that have tmpnam() but do not have mkstemp()?)  This reimplementing,> of>  course, is already done (and much more) in File::Temp, but we> probably> don't want the POSIX being dependent on File::Temp.> > Both options above can include "add a loud obnoxious warning".> > (*) http://grep.cpan.me/?q=POSIX.*tmpnam

(3) produce a deprecation warning, patch attached.

Tony

---
via perlbug:  queue: perl5 status: new
https://rt.perl.org/Ticket/Display.html?id=122005

From a35462eee8412e905fcbeaad3ee92d794ea50ba0 Mon Sep 17 00:00:00 2001
From: Tony Cook <t...@develop-help.com>
Date: Tue, 22 Jul 2014 11:44:54 +1000
Subject: [PATCH] deprecate POSIX::tmpnam()

---
 ext/POSIX/POSIX.xs     |    2 ++
 ext/POSIX/lib/POSIX.pm |    2 +-
 ext/POSIX/t/posix.t    |   14 +++++++++++++-
 3 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/ext/POSIX/POSIX.xs b/ext/POSIX/POSIX.xs
index 2a77df0..e3a6f83 100644
--- a/ext/POSIX/POSIX.xs
+++ b/ext/POSIX/POSIX.xs
@@ -1505,6 +1505,8 @@ tmpnam()
 	STRLEN i;
 	int len;
     CODE:
+        if (ckWARN_d(WARN_DEPRECATED))
+	    Perl_warner(aTHX_ packWARN(WARN_DEPRECATED), "Calling POSIX::tmpnam() is deprecated");
 	RETVAL = newSVpvs("");
 	SvGROW(RETVAL, L_tmpnam);
 	/* Yes, we know tmpnam() is bad.  So bad that some compilers
diff --git a/ext/POSIX/lib/POSIX.pm b/ext/POSIX/lib/POSIX.pm
index 57845a7..3daa2f3 100644
--- a/ext/POSIX/lib/POSIX.pm
+++ b/ext/POSIX/lib/POSIX.pm
@@ -4,7 +4,7 @@ use warnings;
 
 our ($AUTOLOAD, %SIGRT);
 
-our $VERSION = '1.41';
+our $VERSION = '1.42';
 
 require XSLoader;
 
diff --git a/ext/POSIX/t/posix.t b/ext/POSIX/t/posix.t
index c2e4abe..3d68d76 100644
--- a/ext/POSIX/t/posix.t
+++ b/ext/POSIX/t/posix.t
@@ -8,7 +8,7 @@ BEGIN {
     }
 }
 
-use Test::More tests => 109;
+use Test::More tests => 111;
 
 use POSIX qw(fcntl_h signal_h limits_h _exit getcwd open read strftime write
 	     errno localeconv dup dup2 lseek access);
@@ -401,6 +401,18 @@ SKIP: {
     cmp_ok($!, '==', POSIX::ENOTDIR);
 }
 
+{   # tmpnam() is deprecated
+    my $warn;
+    local $SIG{__WARN__} = sub { $warn .= "@_" };
+    my $foo = POSIX::tmpnam();
+    like($warn, qr!^Calling POSIX::tmpnam\(\) is deprecated at t/posix.t line \d+\.$!,
+       "check POSIX::tmpnam warns by default");
+    no warnings "deprecated";
+    undef $warn;
+    my $foo = POSIX::tmpnam();
+    is($warn, undef, "... but the warning can be disabled");
+}
+
 # Check that output is not flushed by _exit. This test should be last
 # in the file, and is not counted in the total number of tests.
 if ($^O eq 'vos') {
-- 
1.7.10.4


Recent Messages in this Thread
Tony Cook via RT Jul 22, 2014 02:02 am
Karl Williamson Jul 23, 2014 03:39 am
Tony Cook via RT Aug 05, 2014 01:47 am
Messages in this thread