Changeset 12095


Ignore:
Timestamp:
May 20, 2009, 12:15:14 AM (10 years ago)
Author:
gb
Message:

On Windows, try to obtain the UTF-16 version of argv; change some
of the functions that deal with determining the image name and
opening the image to accept UTF-16-encoded strings. When the
kernel's done with the image name and argv, convert the strings
involved to UTF-8 (since this doesn't lose information and makes
it a little easier to bootstrap changes to the lisp side of this.)

On the lisp side of this (when obtaining the heap image name and
command-line arguments), assume that the strings are UTF-8-encoded
and possibly do platform-dependent postprocessing. (I honestly
don't know how to reliably tell what encoding was used for things
that come from the command line on other platforms; if they may
not be UTF-8, we might want to make similar changes in the kernel
to support other encodings.

This is supposed to help address ticket:475; I don't know yet if
it does, or if the kernel changes will compie on non-Windows platforms.
One way to find out ...

Location:
trunk/source
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/level-1/l1-pathnames.lisp

    r11859 r12095  
    2525
    2626(defun heap-image-name ()
    27   (let* ((p (%null-ptr)))
     27  (let* ((p (%null-ptr))
     28         (string (%get-utf-8-cstring (%get-kernel-global-ptr 'image-name p))))
    2829    (declare (dynamic-extent p))
    29     #-windows-target
    30     (%get-cstring (%get-kernel-global-ptr 'image-name p))
    31     #+windows-target
    32      (nbackslash-to-forward-slash
    33       (%get-cstring (%get-kernel-global-ptr 'image-name p)))))
     30    #+windows-target (nbackslash-to-forward-slash string)
     31    #+darwin-target (precompose-simple-string string)
     32    #-(or windows-target darwin-target) string))
    3433
    3534(defloadvar *heap-image-name* (heap-image-name))
     
    4443         ((%null-ptr-p arg) (nreverse res))
    4544      (declare (fixnum i))
    46       (push (%get-cstring arg) res))))
     45      (push (%get-utf-8-cstring arg) res))))
    4746
    4847;These are used by make-pathname
  • trunk/source/lisp-kernel/lisp.h

    r11623 r12095  
    119119#define PLATFORM (PLATFORM_OS|PLATFORM_CPU|PLATFORM_WORD_SIZE)
    120120
     121#ifdef WINDOWS
     122Boolean check_for_embedded_image (wchar_t *);
     123#else
    121124Boolean check_for_embedded_image (char *);
     125#endif
    122126natural xStackSpace();
    123127void init_threads(void *, TCR *);
  • trunk/source/lisp-kernel/pmcl-kernel.c

    r12007 r12095  
    841841#ifdef WINDOWS
    842842/* Chop the trailing ".exe" from the kernel image name */
    843 char *
    844 chop_exe_suffix(char *path)
    845 {
    846   int len = strlen(path);
    847   char *copy = malloc(len+1), *tail;
    848 
    849   strcpy(copy,path);
    850   tail = strrchr(copy, '.');
     843wchar_t *
     844chop_exe_suffix(wchar_t *path)
     845{
     846  int len = wcslen(path);
     847  wchar_t *copy = malloc((len+1)*sizeof(wchar_t)), *tail;
     848
     849  wcscpy(copy,path);
     850  tail = wcsrchr(copy, '.');
    851851  if (tail) {
    852852    *tail = 0;
     
    856856#endif
    857857
     858#ifdef WINDOWS
     859wchar_t *
     860path_by_appending_image(wchar_t *path)
     861{
     862  int len = wcslen(path) + wcslen(L".image") + 1;
     863  wchar_t *copy = (wchar_t *) malloc(len*sizeof(wchar_t));
     864
     865  if (copy) {
     866    wcscpy(copy, path);
     867    wcscat(copy, L".image");
     868  }
     869  return copy;
     870}
     871#else
    858872char *
    859873path_by_appending_image(char *path)
     
    868882  return copy;
    869883}
     884#endif
    870885
    871886char *
     
    896911   Tack ".image" onto the end of the kernel's name.  Much better ...
    897912*/
     913#ifdef WINDOWS
     914wchar_t *
     915default_image_name(wchar_t *orig)
     916{
     917  wchar_t *path = chop_exe_suffix(orig);
     918  wchar_t *image_name = path_by_appending_image(path);
     919  return image_name;
     920}
     921#else
    898922char *
    899923default_image_name(char *orig)
     
    915939  return image_name;
    916940}
     941#endif
    917942
    918943
    919944
    920945char *program_name = NULL;
     946#ifdef WINDOWS
     947wchar_t *real_executable_name = NULL;
     948#else
    921949char *real_executable_name = NULL;
    922 
     950#endif
     951
     952#ifndef WINDOWS
    923953char *
    924954determine_executable_name(char *argv0)
     
    965995  return argv0;
    966996#endif
    967 #ifdef WINDOWS
    968   char path[PATH_MAX], *p;
    969   int len = GetModuleFileName(NULL, path, PATH_MAX);
    970   if (len > 0) {
    971     p = malloc(len + 1);
    972     memmove(p, path, len);
    973     p[len] = 0;
    974     return p;
    975   }
    976997  return argv0;
    977 #endif
    978 }
     998}
     999#endif
    9791000
    9801001void
     
    9981019  fprintf(dbgout, "\t--no-sigtrap : obscure option for running under GDB\n");
    9991020  fprintf(dbgout, "\t-I, --image-name <image-name>\n");
     1021#ifndef WINDOWS
    10001022  fprintf(dbgout, "\t and <image-name> defaults to %s\n",
    10011023          default_image_name(program_name));
     1024#endif
    10021025  fprintf(dbgout, "\n");
    10031026  _exit(exit_status);
     
    10051028
    10061029int no_sigtrap = 0;
     1030#ifdef WINDOWS
     1031wchar_t *image_name = NULL;
     1032#else
    10071033char *image_name = NULL;
     1034#endif
    10081035int batch_flag = 0;
    10091036
     
    10531080
    10541081void
    1055 process_options(int argc, char *argv[])
     1082process_options(int argc, char *argv[], wchar_t *shadow[])
    10561083{
    10571084  int i, j, k, num_elide, flag, arg_error;
    10581085  char *arg, *val;
     1086  wchar_t *warg, *wval;
    10591087#ifdef DARWIN
    10601088  extern int NXArgc;
     
    10631091  for (i = 1; i < argc;) {
    10641092    arg = argv[i];
     1093    if (shadow) {
     1094      warg = shadow[i];
     1095    }
    10651096    arg_error = 0;
    10661097    if (*arg != '-') {
     
    10721103          (strcmp (arg, "--image-name") == 0)) {
    10731104        if (flag && arg[2]) {
    1074           val = arg+2;
     1105          val = arg+2;         
     1106          if (shadow) {
     1107            wval = warg+2;
     1108          }
    10751109          num_elide = 1;
    10761110        } else {
    10771111          if ((i+1) < argc) {
    10781112            val = argv[i+1];
     1113            if (shadow) {
     1114              wval = shadow[i+1];
     1115            }
    10791116            num_elide = 2;
    10801117          } else {
     
    10831120        }
    10841121        if (val) {
     1122#ifdef WINDOWS
     1123          image_name = wval;
     1124#else
    10851125          image_name = val;
     1126#endif
    10861127        }
    10871128      } else if ((flag = (strncmp(arg, "-R", 2) == 0)) ||
     
    11871228        for (j = i+num_elide, k=i; j < argc; j++, k++) {
    11881229          argv[k] = argv[j];
     1230          if (shadow) {
     1231            shadow[k] = shadow[j];
     1232          }
    11891233        }
    11901234        argc -= num_elide;
     
    14991543}
    15001544
     1545#ifdef WINDOWS
     1546char *
     1547utf_16_to_utf_8(wchar_t *utf_16)
     1548{
     1549  int utf8len = WideCharToMultiByte(CP_UTF8,
     1550                                    0,
     1551                                    utf_16,
     1552                                    -1,
     1553                                    NULL,
     1554                                    0,
     1555                                    NULL,
     1556                                    NULL);
     1557
     1558  char *utf_8 = malloc(utf8len);
     1559
     1560  WideCharToMultiByte(CP_UTF8,
     1561                      0,
     1562                      utf_16,
     1563                      -1,
     1564                      utf_8,
     1565                      utf8len,
     1566                      NULL,
     1567                      NULL);
     1568
     1569  return utf_8;
     1570}
     1571
     1572char **
     1573wide_argv_to_utf_8(wchar_t *wide_argv[], int argc)
     1574{
     1575  char** argv = calloc(argc+1,sizeof(char *));
     1576  int i;
     1577
     1578  for (i = 0; i < argc; i++) {
     1579    argv[i] = utf_16_to_utf_8(wide_argv[i]);
     1580  }
     1581  return argv;
     1582}
     1583#endif
     1584
     1585
     1586 
     1587
    15011588
    15021589int
     
    15201607    ;
    15211608  Boolean lisp_heap_threshold_set_from_command_line = false;
     1609  wchar_t **utf_16_argv = NULL;
    15221610
    15231611#ifdef PPC
    15241612  extern int altivec_present;
    15251613#endif
     1614#ifdef WINDOWS
     1615  extern LispObj load_image(wchar_t *);
     1616#else
    15261617  extern LispObj load_image(char *);
     1618#endif
    15271619  area *a;
    15281620  BytePtr stack_base, current_sp = (BytePtr) current_stack_pointer();
     
    15331625#ifdef WINDOWS
    15341626  {
     1627    int wide_argc;
    15351628    extern void init_winsock(void);
    15361629    extern void init_windows_io(void);
     
    15421635    init_winsock();
    15431636    init_windows_io();
     1637    utf_16_argv = CommandLineToArgvW(GetCommandLineW(),&wide_argc);
    15441638  }
    15451639#endif
    15461640
    15471641  check_os_version(argv[0]);
     1642#ifdef WINDOWS
     1643  real_executable_name = utf_16_argv[0];
     1644#else
    15481645  real_executable_name = determine_executable_name(argv[0]);
     1646#endif
    15491647  page_size = getpagesize(); /* Implement with GetSystemInfo on Windows w/o MinGW */
    15501648
     
    16341732  program_name = argv[0];
    16351733  if ((argc == 2) && (*argv[1] != '-')) {
     1734#ifdef WINDOWS
     1735    image_name = utf_16_argv[1];
     1736#else
    16361737    image_name = argv[1];
     1738#endif
    16371739    argv[1] = NULL;
     1740#ifdef WINDOWS
     1741    utf_16_argv[1] = NULL;
     1742#endif
    16381743  } else {
    1639     process_options(argc,argv);
     1744    process_options(argc,argv,utf_16_argv);
    16401745  }
    16411746  if (lisp_heap_gc_threshold != DEFAULT_LISP_HEAP_GC_THRESHOLD) {
     
    16991804 
    17001805
     1806#ifdef WINDOWS
     1807  lisp_global(IMAGE_NAME) = ptr_to_lispobj(utf_16_to_utf_8(image_name));
     1808  lisp_global(ARGV) = ptr_to_lispobj(wide_argv_to_utf_8(utf_16_argv, argc));
     1809#else
    17011810  lisp_global(IMAGE_NAME) = ptr_to_lispobj(image_name);
    17021811  lisp_global(ARGV) = ptr_to_lispobj(argv);
     1812#endif
    17031813  lisp_global(KERNEL_IMPORTS) = (LispObj)import_ptrs_base;
    17041814
     
    19792089
    19802090Boolean
    1981 check_for_embedded_image (char *path)
    1982 {
     2091check_for_embedded_image (
     2092#ifdef WINDOWS
     2093                          wchar_t *path
     2094#else
     2095                          char *path
     2096#endif
     2097                          )
     2098{
     2099#ifdef WINDOWS
     2100  int fd = wopen(path, O_RDONLY);
     2101#else 
    19832102  int fd = open(path, O_RDONLY);
     2103#endif
     2104
    19842105  Boolean image_is_embedded = false;
    19852106
     
    19962117
    19972118LispObj
    1998 load_image(char *path)
    1999 {
     2119load_image(
     2120#ifdef WINDOWS
     2121           wchar_t * path
     2122#else
     2123           char *path
     2124#endif
     2125)
     2126{
     2127#ifdef WINDOWS
     2128  int fd = wopen(path, O_RDONLY, 0666), err;
     2129#else
    20002130  int fd = open(path, O_RDONLY, 0666), err;
     2131#endif
    20012132  LispObj image_nil = 0;
    20022133
  • trunk/source/lisp-kernel/windows-calls.c

    r11957 r12095  
    256256  }
    257257  return hfile;
     258}
     259
     260int
     261wopen(wchar_t *path, int flag, int mode)
     262{
     263  HANDLE h = lisp_open(path, flag, mode);
     264
     265  if (h == (HANDLE)-1) {
     266    return -1;                  /* errno already set */
     267  }
     268  return _open_osfhandle((DWORD)h,0);
    258269}
    259270
Note: See TracChangeset for help on using the changeset viewer.