guile-launcher.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* GNU Guix --- Functional package management for GNU
  2. Copyright 1996-1997,2000-2001,2006,2008,2011,2013,2018,2020,2021
  3. Free Software Foundation, Inc.
  4. Copyright (C) 2020 Ludovic Courtès <ludo@gnu.org>
  5. This file is part of GNU Guix.
  6. GNU Guix is free software; you can redistribute it and/or modify it
  7. under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 3 of the License, or (at
  9. your option) any later version.
  10. GNU Guix is distributed in the hope that it will be useful, but
  11. WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. */
  16. /* This file implements a variant of the 'guile' executable that does not
  17. complain about locale issues and arranges to reduce startup time by
  18. ignoring GUILE_LOAD_PATH and GUILE_LOAD_COMPILED_PATH until it has
  19. booted. */
  20. #include <stdlib.h>
  21. #include <string.h>
  22. #include <locale.h>
  23. #include <libguile.h>
  24. /* Saved values of GUILE_LOAD_PATH and GUILE_LOAD_COMPILED_PATH. */
  25. static const char *load_path, *load_compiled_path;
  26. static void
  27. inner_main (void *unused, int argc, char **argv)
  28. {
  29. if (load_path != NULL)
  30. {
  31. setenv ("GUILE_LOAD_PATH", load_path, 1);
  32. SCM load_path_var =
  33. scm_c_public_lookup ("guile", "%load-path");
  34. SCM addition =
  35. scm_parse_path (scm_from_locale_string (load_path), SCM_EOL);
  36. scm_variable_set_x (load_path_var,
  37. scm_append
  38. (scm_list_2 (scm_variable_ref (load_path_var),
  39. addition)));
  40. }
  41. if (load_compiled_path != NULL)
  42. {
  43. setenv ("GUILE_LOAD_COMPILED_PATH", load_compiled_path, 1);
  44. SCM load_compiled_path_var =
  45. scm_c_public_lookup ("guile", "%load-compiled-path");
  46. SCM addition =
  47. scm_parse_path (scm_from_locale_string (load_compiled_path), SCM_EOL);
  48. scm_variable_set_x (load_compiled_path_var,
  49. scm_append
  50. (scm_list_2 (scm_variable_ref (load_compiled_path_var),
  51. addition)));
  52. }
  53. scm_shell (argc, argv);
  54. }
  55. int
  56. main (int argc, char **argv)
  57. {
  58. /* Try to install the current locale; remain silent if it fails. */
  59. if (setlocale (LC_ALL, "") == NULL)
  60. /* The 'guix pull'-provided 'guix' includes at least en_US.utf8 so use
  61. that. That gives us UTF-8 support for 'scm_to_locale_string', etc.,
  62. which is always preferable over the C locale. */
  63. setlocale (LC_ALL, "en_US.utf8");
  64. const char *str;
  65. str = getenv ("GUILE_LOAD_PATH");
  66. load_path = str != NULL ? strdup (str) : NULL;
  67. str = getenv ("GUILE_LOAD_COMPILED_PATH");
  68. load_compiled_path = str ? strdup (str) : NULL;
  69. unsetenv ("GUILE_LOAD_PATH");
  70. unsetenv ("GUILE_LOAD_COMPILED_PATH");
  71. #if !SCM_ENABLE_MINI_GMP
  72. /* XXX: On Guile < 3.0.6 and Guile built without its bundled mini-GMP, do
  73. not let GMP allocate via libgc as this can lead to memory corruption in
  74. GnuTLS/Nettle since Nettle also uses GMP:
  75. <https://issues.guix.gnu.org/46330>. */
  76. scm_install_gmp_memory_functions = 0;
  77. #endif
  78. scm_boot_guile (argc, argv, inner_main, 0);
  79. return 0; /* never reached */
  80. }