@@ -1,3 +1,10 @@
+2014-09-25 David Malcolm <dmalcolm@redhat.com>
+
+ * internal-api.c (make_tempdir_path_template): New.
+ (gcc::jit::playback::context::compile): Call
+ make_tempdir_path_template to make m_path_template, rather than
+ hardcoding "/tmp/" within "/tmp/libgccjit-XXXXXX".
+
2014-09-24 David Malcolm <dmalcolm@redhat.com>
* docs/internals/index.rst ("Overview of code structure"): Add
@@ -4826,6 +4826,44 @@ block (function *func,
m_label_expr = NULL;
}
+/* Construct a tempdir path template suitable for use by mkdtemp
+ e.g. "/tmp/libgccjit-XXXXXX", but respecting the rules in
+ libiberty's choose_tempdir rather than hardcoding "/tmp/".
+
+ The memory is allocated using malloc and must be freed.
+ Aborts the process if allocation fails. */
+
+static char *
+make_tempdir_path_template ()
+{
+ const char *tmpdir_buf;
+ size_t tmpdir_len;
+ const char *file_template_buf;
+ size_t file_template_len;
+ char *result;
+
+ /* The result of choose_tmpdir is a cached buffer within libiberty, so
+ we must *not* free it. */
+ tmpdir_buf = choose_tmpdir ();
+
+ /* choose_tmpdir aborts on malloc failure. */
+ gcc_assert (tmpdir_buf);
+
+ tmpdir_len = strlen (tmpdir_buf);
+ /* tmpdir_buf should now have a dir separator as the final byte. */
+ gcc_assert (tmpdir_len > 0);
+ gcc_assert (tmpdir_buf[tmpdir_len - 1] == DIR_SEPARATOR);
+
+ file_template_buf = "libgccjit-XXXXXX";
+ file_template_len = strlen (file_template_buf);
+
+ result = XNEWVEC (char, tmpdir_len + file_template_len + 1);
+ strcpy (result, tmpdir_buf);
+ strcpy (result + tmpdir_len, file_template_buf);
+
+ return result;
+}
+
/* Compile a playback::context:
- Use the context's options to cconstruct command-line options, and
@@ -4845,7 +4883,7 @@ compile ()
const char *fake_args[20];
unsigned int num_args;
- m_path_template = xstrdup ("/tmp/libgccjit-XXXXXX");
+ m_path_template = make_tempdir_path_template ();
if (!m_path_template)
return NULL;
new file mode 100644
@@ -0,0 +1,11 @@
+2014-09-25 David Malcolm <dmalcolm@redhat.com>
+
+ * libiberty.h (choose_tmpdir): New prototype.
+ * ChangeLog.jit: New.
+
+
+Copyright (C) 2014 Free Software Foundation, Inc.
+
+Copying and distribution of this file, with or without modification,
+are permitted in any medium without royalty provided the copyright
+notice and this notice are preserved.
@@ -227,6 +227,11 @@ extern char *make_relative_prefix (const char *, const char *,
extern char *make_relative_prefix_ignore_links (const char *, const char *,
const char *) ATTRIBUTE_MALLOC;
+/* Returns a pointer to a directory path suitable for creating temporary
+ files in. */
+
+extern const char *choose_tmpdir (void) ATTRIBUTE_RETURNS_NONNULL;
+
/* Choose a temporary directory to use for scratch files. */
extern char *choose_temp_base (void) ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL;
@@ -1,3 +1,12 @@
+2014-09-25 David Malcolm <dmalcolm@redhat.com>
+
+ * choose-temp.c (choose_tmpdir): Remove now-redundant local
+ copy of prototype.
+ * functions.texi: Regenerate.
+ * make-temp-file.c (choose_tmpdir): Convert return type from
+ char * to const char * - given that this returns a pointer to
+ a memoized allocation, the caller must not touch it.
+
2014-09-24 David Malcolm <dmalcolm@redhat.com>
* ChangeLog.jit: Add copyright footer.
@@ -34,7 +34,6 @@ Boston, MA 02110-1301, USA. */
#endif
#include "libiberty.h"
-extern char *choose_tmpdir (void);
/* Name of temporary file.
mktemp requires 6 trailing X's. */
@@ -125,7 +125,7 @@ Uses @code{malloc} to allocate storage for @var{nelem} objects of
@end deftypefn
-@c choose-temp.c:46
+@c choose-temp.c:45
@deftypefn Extension char* choose_temp_base (void)
Return a prefix for temporary file names or @code{NULL} if unable to
@@ -139,7 +139,7 @@ not recommended.
@end deftypefn
@c make-temp-file.c:96
-@deftypefn Replacement char* choose_tmpdir ()
+@deftypefn Replacement const char* choose_tmpdir ()
Returns a pointer to a directory path suitable for creating temporary
files in.
@@ -160,9 +160,8 @@ number of seconds used.
@dots{}, @code{NULL})
Concatenate zero or more of strings and return the result in freshly
-@code{xmalloc}ed memory. Returns @code{NULL} if insufficient memory is
-available. The argument list is terminated by the first @code{NULL}
-pointer encountered. Pointers to empty strings are ignored.
+@code{xmalloc}ed memory. The argument list is terminated by the first
+@code{NULL} pointer encountered. Pointers to empty strings are ignored.
@end deftypefn
@@ -528,7 +527,7 @@ nineteen EBCDIC varying characters is tested; exercise caution.)
@end ftable
@end defvr
-@c hashtab.c:336
+@c hashtab.c:328
@deftypefn Supplemental htab_t htab_create_typed_alloc (size_t @var{size}, @
htab_hash @var{hash_f}, htab_eq @var{eq_f}, htab_del @var{del_f}, @
htab_alloc @var{alloc_tab_f}, htab_alloc @var{alloc_f}, @
@@ -1163,7 +1162,7 @@ control over the state of the random number generator.
@end deftypefn
-@c concat.c:174
+@c concat.c:160
@deftypefn Extension char* reconcat (char *@var{optr}, const char *@var{s1}, @
@dots{}, @code{NULL})
@@ -93,7 +93,7 @@ static char *memoized_tmpdir;
/*
-@deftypefn Replacement char* choose_tmpdir ()
+@deftypefn Replacement const char* choose_tmpdir ()
Returns a pointer to a directory path suitable for creating temporary
files in.
@@ -102,7 +102,7 @@ files in.
*/
-char *
+const char *
choose_tmpdir (void)
{
if (!memoized_tmpdir)