From: Thien-Thi Nguyen <ttn@gnuvola.org>
To: guile-devel@gnu.org
Subject: Re: request tmpfile(3) wrapping in Guile 1.9 libguile
Date: Fri, 12 Feb 2010 16:21:00 +0100 [thread overview]
Message-ID: <87r5oqbhur.fsf@ambire.localdomain> (raw)
In-Reply-To: <m3zl3i9eyd.fsf@pobox.com> (Andy Wingo's message of "Wed, 10 Feb 2010 00:17:30 +0100")
[-- Attachment #1: Type: text/plain, Size: 2222 bytes --]
() Andy Wingo <wingo@pobox.com>
() Wed, 10 Feb 2010 00:17:30 +0100
Yes, I think that's probably the right answer.
On the (faint) suspicion that `scm_fdes_to_port' does not DTRT, given
the file descriptor extracted via `fileno' from the `FILE *', i ran a
small test:
(write (getpid)) (newline)
(define tmp (tmpfile))
(sleep 10)
(set! tmp #f) ; lose ref
(let loop () (gc) (sleep 1) (loop))
and monitored using "watch lsof -p PID". I observed that the descriptor
is listed as "/tmp/FILENAME (deleted)" from the beginning and that after
some time, this entry goes away. So my trust in `scm_fdes_to_port' is
not broken (cool). Still, i wonder what others see.
Yes, this sounds better than mkstemp!. Since you seem to have to code
already, can you submit two patches with mkstemp and tempfile,
respectively?
I think you mean `tmpfile'. Please see attached patch.
While we're here... Ludovic, Neil and I talked over mail about your
request to (re)join the Guile project, and we're very happy to have
your skills and energy. The one concern that we have is that you
tend to be a bit cavalier; so until we feel like we're on the same
page, we would like for you to refrain from committing to master or
the 1.8 branch.
Thanks for the frank assessment. I will try to be less cavalier (or
perhaps more "anti-cavalier", once i figure out what that means in this
context). I appreciate any tips on this aspect.
Instead, please feel free to (commit to | create) other branches in
the repository, preferably prefixing those branches with "wip-" if
you intend them to be rebased at some point. Please mail the list
when you would like for us to review and merge your patches into
master or 1.8.
OK. How do you feel about a branches named ttn/wip-TOPIC ?
I recognize that it's a somewhat awkward situation, but we're so
unfamiliar with each other at this point that a slow rapprochement
would probably be best to avoid unexpected conflicts.
Agreed.
That said, welcome back to Guile!
Thanks for giving me another chance. Perhaps i can avoid squandering
the privelege as i did the previous time.
thi
____________________________________________________
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-tmpfile-3-to-libguile.patch --]
[-- Type: text/x-diff, Size: 3154 bytes --]
From 6f5612459b1e414c33b5a1814a5bec57eb81052e Mon Sep 17 00:00:00 2001
From: Thien-Thi Nguyen <ttn@gnuvola.org>
Date: Fri, 12 Feb 2010 16:01:16 +0100
Subject: [PATCH] Add tmpfile(3) to libguile.
* libguile/posix.c (sym_tmpfile): New symbol.
(scm_tmpfile): New primitive.
* libguile/posix.h (scm_tmpfile): New func decl.
* doc/ref/posix.texi (File System): Document `tmpfile'.
Signed-off-by: Thien-Thi Nguyen <ttn@gnuvola.org>
---
doc/ref/posix.texi | 14 ++++++++++++++
libguile/posix.c | 24 ++++++++++++++++++++++++
libguile/posix.h | 1 +
3 files changed, 39 insertions(+), 0 deletions(-)
diff --git a/doc/ref/posix.texi b/doc/ref/posix.texi
index 6ff7109..349dcbe 100644
--- a/doc/ref/posix.texi
+++ b/doc/ref/posix.texi
@@ -948,6 +948,20 @@ which is usual for ordinary file creation,
@end example
@end deffn
+@deffn {Scheme Procedure} tmpfile
+@deffnx {C Function} scm_tmpfile
+Return an input/output port to a unique temporary file
+named using the path prefix @code{P_tmpdir} defined in
+@file{stdio.h}.
+The file is automatically deleted when the port is closed
+or the program terminates.
+
+The name of the temporary file associated with the returned
+port is not available to Scheme programs;
+@code{(port-filename (tmpfile))} always returns the
+symbol @code{tmpfile}.
+@end deffn
+
@deffn {Scheme Procedure} dirname filename
@deffnx {C Function} scm_dirname (filename)
Return the directory name component of the file name
diff --git a/libguile/posix.c b/libguile/posix.c
index 73921a2..363de8c 100644
--- a/libguile/posix.c
+++ b/libguile/posix.c
@@ -1373,6 +1373,30 @@ SCM_DEFINE (scm_mkstemp, "mkstemp!", 1, 0, 0,
}
#undef FUNC_NAME
+SCM_SYMBOL (sym_tmpfile, "tmpfile");
+
+SCM_DEFINE (scm_tmpfile, "tmpfile", 0, 0, 0,
+ (void),
+ "Return an input/output port to a unique temporary file\n"
+ "named using the path prefix @code{P_tmpdir} defined in\n"
+ "@file{stdio.h}.\n"
+ "The file is automatically deleted when the port is closed\n"
+ "or the program terminates.\n"
+ "\n"
+ "The name of the temporary file associated with the returned\n"
+ "port is not available to Scheme programs;\n"
+ "@code{(port-filename (tmpfile))} always returns the\n"
+ "symbol @code{tmpfile}.")
+#define FUNC_NAME s_scm_tmpfile
+{
+ FILE *rv;
+
+ if (! (rv = tmpfile ()))
+ SCM_SYSERROR;
+ return scm_fdes_to_port (fileno (rv), "w+", sym_tmpfile);
+}
+#undef FUNC_NAME
+
SCM_DEFINE (scm_utime, "utime", 1, 5, 0,
(SCM pathname, SCM actime, SCM modtime, SCM actimens, SCM modtimens,
SCM flags),
diff --git a/libguile/posix.h b/libguile/posix.h
index 420311e..71c46f2 100644
--- a/libguile/posix.h
+++ b/libguile/posix.h
@@ -68,6 +68,7 @@ SCM_API SCM scm_uname (void);
SCM_API SCM scm_environ (SCM env);
SCM_API SCM scm_tmpnam (void);
SCM_API SCM scm_mkstemp (SCM tmpl);
+SCM_API SCM scm_tmpfile (void);
SCM_API SCM scm_open_pipe (SCM pipestr, SCM modes);
SCM_API SCM scm_close_pipe (SCM port);
SCM_API SCM scm_utime (SCM pathname, SCM actime, SCM modtime,
--
1.6.3.2
next prev parent reply other threads:[~2010-02-12 15:21 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <877hqoubkv.fsf@ambire.localdomain>
[not found] ` <m36368dlt6.fsf@pobox.com>
[not found] ` <87wrymojzx.fsf@ambire.localdomain>
2010-02-09 23:17 ` request tmpfile(3) wrapping in Guile 1.9 libguile Andy Wingo
2010-02-10 0:47 ` Greg Troxel
2010-02-12 15:21 ` Thien-Thi Nguyen [this message]
2010-02-12 20:48 ` Andy Wingo
2010-02-13 11:15 ` Thien-Thi Nguyen
2010-02-14 10:51 ` Andy Wingo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87r5oqbhur.fsf@ambire.localdomain \
--to=ttn@gnuvola.org \
--cc=guile-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).