OpenVMS, use 'r' mode to open source file by default, environment variable
authorJean-Francois Pieronne <jf.pieronne@laposte.net>
Mon, 03 Oct 2011 14:52:41 +0200
changeset 12914afb5c8c66a
parent 128 228b759a8bdb
child 130 9c200df7e736
OpenVMS, use 'r' mode to open source file by default, environment variable
(logical or symbol) PYTHON_SOURCE_UNIVNL allow to open in universal newline
mode.
series
vms223.patch
     1.1 --- a/series
     1.2 +++ b/series
     1.3 @@ -63,3 +63,4 @@
     1.4  vms101.patch
     1.5  vms102.patch
     1.6  vms039.patch
     1.7 +vms223.patch
     2.1 new file mode 100755
     2.2 --- /dev/null
     2.3 +++ b/vms223.patch
     2.4 @@ -0,0 +1,74 @@
     2.5 +# HG changeset patch
     2.6 +# Parent 7254c7b81f1b0ac00c2ea0e1c379c15dcc50b472
     2.7 +OpenVMS, use 'r' mode to open source file by default, environment variable
     2.8 +(logical or symbol) PYTHON_SOURCE_UNIVNL allow to open in universal newline
     2.9 +mode.
    2.10 +
    2.11 +diff --git a/Python/import.c b/Python/import.c
    2.12 +--- a/Python/import.c
    2.13 ++++ b/Python/import.c
    2.14 +@@ -97,12 +97,19 @@
    2.15 + /* these tables define the module suffixes that Python recognizes */
    2.16 + struct filedescr * _PyImport_Filetab = NULL;
    2.17 + 
    2.18 +-#ifdef RISCOS
    2.19 ++#if defined(RISCOS)
    2.20 + static const struct filedescr _PyImport_StandardFiletab[] = {
    2.21 +     {"/py", "U", PY_SOURCE},
    2.22 +     {"/pyc", "rb", PY_COMPILED},
    2.23 +     {0, 0}
    2.24 + };
    2.25 ++#elif defined(__VMS)
    2.26 ++extern unsigned int pyvms_gl_source_univnl;
    2.27 ++static const struct filedescr _PyImport_StandardFiletab[] = {
    2.28 ++    {".py", "r", PY_SOURCE},
    2.29 ++    {".pyc", "rb", PY_COMPILED},
    2.30 ++    {0, 0}
    2.31 ++};
    2.32 + #else
    2.33 + static const struct filedescr _PyImport_StandardFiletab[] = {
    2.34 +     {".py", "U", PY_SOURCE},
    2.35 +@@ -160,6 +167,15 @@
    2.36 +         }
    2.37 +     }
    2.38 + 
    2.39 ++#ifdef __VMS
    2.40 ++    if (pyvms_gl_source_univnl) {
    2.41 ++        /* Replace "r" mode with "U" */
    2.42 ++        for (; filetab->suffix != NULL; filetab++)
    2.43 ++            if (strcmp(filetab->suffix, ".py") == 0)
    2.44 ++                filetab->mode = "U";
    2.45 ++    }
    2.46 ++#endif
    2.47 ++
    2.48 +     if (Py_UnicodeFlag) {
    2.49 +         /* Fix the pyc_magic so that byte compiled code created
    2.50 +            using the all-Unicode method doesn't interfere with
    2.51 +diff --git a/vms/pyvms_init.c b/vms/pyvms_init.c
    2.52 +--- a/vms/pyvms_init.c
    2.53 ++++ b/vms/pyvms_init.c
    2.54 +@@ -40,7 +40,7 @@
    2.55 + unsigned int		  pyvms_gl_keyboard_id;
    2.56 + unsigned int		  pyvms_gl_key_table_id;
    2.57 + unsigned int              pyvms_gl_posix_exit;
    2.58 +-
    2.59 ++unsigned int              pyvms_gl_source_univnl;
    2.60 + /*
    2.61 + ** Force a reference to LIB$INITIALIZE to ensure it
    2.62 + ** exists in the image.
    2.63 +@@ -351,6 +351,15 @@
    2.64 +     {
    2.65 +         pyvms_gl_posix_exit = 1;
    2.66 +     }
    2.67 ++    str = getenv("PYTHON_SOURCE_UNIVNL");
    2.68 ++    if (str == NULL)
    2.69 ++    {
    2.70 ++        pyvms_gl_source_univnl = 0;
    2.71 ++    }
    2.72 ++    else
    2.73 ++    {
    2.74 ++        pyvms_gl_source_univnl = 1;
    2.75 ++    }
    2.76 +     return SS$_NORMAL;
    2.77 + } 
    2.78 +