#include <stdio.h>
#include "libguile/_scm.h"
-#include "libguile/private-gc.h" /* scm_getenv_int */
#include "libguile/libpath.h"
#include "libguile/fports.h"
#include "libguile/read.h"
/* Utility functions for assembling C strings in a buffer.
*/
-struct stringbuf {
+struct stringbuf
+{
char *buf, *ptr;
size_t buf_len;
};
-static void
-stringbuf_free (void *data)
-{
- struct stringbuf *buf = (struct stringbuf *)data;
- free (buf->buf);
-}
-
static void
stringbuf_grow (struct stringbuf *buf)
{
- size_t ptroff = buf->ptr - buf->buf;
- buf->buf_len *= 2;
- buf->buf = scm_realloc (buf->buf, buf->buf_len);
+ size_t ptroff, prev_len;
+ void *prev_buf = buf->buf;
+
+ prev_len = buf->buf_len;
+ ptroff = buf->ptr - buf->buf;
+
+ buf->buf_len *= 2;
+ buf->buf = scm_gc_malloc_pointerless (buf->buf_len, "search-path");
+ memcpy (buf->buf, prev_buf, prev_len);
buf->ptr = buf->buf + ptroff;
}
}
}
-
+/* Return non-zero if STR is suffixed by a dot followed by one of
+ EXTENSIONS. */
static int
-scm_c_string_has_an_ext (char *str, size_t len, SCM extensions)
+string_has_an_ext (SCM str, SCM extensions)
{
for (; !scm_is_null (extensions); extensions = SCM_CDR (extensions))
{
- char *ext;
- size_t extlen;
- int match;
- ext = scm_to_locale_string (SCM_CAR (extensions));
- extlen = strlen (ext);
- match = (len > extlen && str[len - extlen - 1] == '.'
- && strncmp (str + (len - extlen), ext, extlen) == 0);
- free (ext);
- if (match)
- return 1;
+ SCM extension;
+
+ extension = SCM_CAR (extensions);
+ if (scm_is_true (scm_string_suffix_p (extension, str,
+ SCM_UNDEFINED, SCM_UNDEFINED,
+ SCM_UNDEFINED, SCM_UNDEFINED)))
+ return 1;
}
+
return 0;
}
char *filename_chars;
size_t filename_len;
SCM result = SCM_BOOL_F;
+ char initial_buffer[256];
if (scm_ilength (path) < 0)
scm_misc_error ("%search-path", "path is not a proper list: ~a",
if (is_absolute_file_name (filename))
{
if ((scm_is_false (require_exts) ||
- scm_c_string_has_an_ext (filename_chars, filename_len,
- extensions))
+ string_has_an_ext (filename, extensions))
&& stat (filename_chars, stat_buf) == 0
&& !(stat_buf->st_mode & S_IFDIR))
result = filename;
if (*endp == '.')
{
if (scm_is_true (require_exts) &&
- !scm_c_string_has_an_ext (filename_chars, filename_len,
- extensions))
+ !string_has_an_ext (filename, extensions))
{
/* This filename has an extension, but not one of the right
ones... */
if (scm_is_null (extensions))
extensions = scm_listofnullstr;
- buf.buf_len = 512;
- buf.buf = scm_malloc (buf.buf_len);
- scm_dynwind_unwind_handler (stringbuf_free, &buf, SCM_F_WIND_EXPLICITLY);
+ buf.buf_len = sizeof initial_buffer;
+ buf.buf = initial_buffer;
/* Try every path element.
*/
if (stat (buf.buf, stat_buf) == 0
&& ! (stat_buf->st_mode & S_IFDIR))
{
- result = scm_from_locale_string (buf.buf);
+ result =
+ scm_from_locale_string (scm_i_mirror_backslashes (buf.buf));
goto end;
}
}
else
{
compiled_is_newer = 0;
- scm_puts (";;; note: source file ", scm_current_error_port ());
+ scm_puts_unlocked (";;; note: source file ", scm_current_error_port ());
scm_display (full_filename, scm_current_error_port ());
- scm_puts ("\n;;; newer than compiled ", scm_current_error_port ());
+ scm_puts_unlocked ("\n;;; newer than compiled ", scm_current_error_port ());
scm_display (compiled_filename, scm_current_error_port ());
- scm_puts ("\n", scm_current_error_port ());
+ scm_puts_unlocked ("\n", scm_current_error_port ());
}
return compiled_is_newer;
static SCM
do_try_auto_compile (void *data)
{
- SCM source = PTR2SCM (data);
+ SCM source = SCM_PACK_POINTER (data);
SCM comp_mod, compile_file;
- scm_puts (";;; compiling ", scm_current_error_port ());
+ scm_puts_unlocked (";;; compiling ", scm_current_error_port ());
scm_display (source, scm_current_error_port ());
scm_newline (scm_current_error_port ());
/* Assume `*current-warning-prefix*' has an appropriate value. */
res = scm_call_n (scm_variable_ref (compile_file), args, 5);
- scm_puts (";;; compiled ", scm_current_error_port ());
+ scm_puts_unlocked (";;; compiled ", scm_current_error_port ());
scm_display (res, scm_current_error_port ());
scm_newline (scm_current_error_port ());
return res;
}
else
{
- scm_puts (";;; it seems ", scm_current_error_port ());
+ scm_puts_unlocked (";;; it seems ", scm_current_error_port ());
scm_display (source, scm_current_error_port ());
- scm_puts ("\n;;; is part of the compiler; skipping auto-compilation\n",
+ scm_puts_unlocked ("\n;;; is part of the compiler; skipping auto-compilation\n",
scm_current_error_port ());
return SCM_BOOL_F;
}
static SCM
auto_compile_catch_handler (void *data, SCM tag, SCM throw_args)
{
- SCM source = PTR2SCM (data);
+ SCM source = SCM_PACK_POINTER (data);
SCM oport, lines;
oport = scm_open_output_string ();
scm_print_exception (oport, SCM_BOOL_F, tag, throw_args);
- scm_puts (";;; WARNING: compilation of ", scm_current_warning_port ());
+ scm_puts_unlocked (";;; WARNING: compilation of ", scm_current_warning_port ());
scm_display (source, scm_current_warning_port ());
- scm_puts (" failed:\n", scm_current_warning_port ());
+ scm_puts_unlocked (" failed:\n", scm_current_warning_port ());
lines = scm_string_split (scm_get_output_string (oport),
SCM_MAKE_CHAR ('\n'));
for (; scm_is_pair (lines); lines = scm_cdr (lines))
if (scm_c_string_length (scm_car (lines)))
{
- scm_puts (";;; ", scm_current_warning_port ());
+ scm_puts_unlocked (";;; ", scm_current_warning_port ());
scm_display (scm_car (lines), scm_current_warning_port ());
scm_newline (scm_current_warning_port ());
}
if (!message_shown)
{
- scm_puts (";;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0\n"
+ scm_puts_unlocked (";;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0\n"
";;; or pass the --no-auto-compile argument to disable.\n",
scm_current_warning_port ());
message_shown = 1;
scm_sys_warn_auto_compilation_enabled ();
return scm_c_catch (SCM_BOOL_T,
do_try_auto_compile,
- SCM2PTR (source),
+ SCM_UNPACK_POINTER (source),
auto_compile_catch_handler,
- SCM2PTR (source),
+ SCM_UNPACK_POINTER (source),
NULL, NULL);
}
if (stat_ret == 0 && compiled_is_fresh (full_filename, fallback,
&stat_source, &stat_compiled))
{
- scm_puts (";;; found fresh local cache at ", scm_current_warning_port ());
+ scm_puts_unlocked (";;; found fresh local cache at ", scm_current_warning_port ());
scm_display (fallback, scm_current_warning_port ());
scm_newline (scm_current_warning_port ());
return scm_load_compiled_with_vm (fallback);
for (i = 0; i < (sizeof (info) / sizeof (info[0])); i++)
{
- SCM key = scm_from_locale_symbol (info[i].name);
+ SCM key = scm_from_utf8_symbol (info[i].name);
SCM val = scm_from_locale_string (info[i].value);
*loc = scm_acons (key, val, *loc);
}