Ignore:
Timestamp:
Mar 19, 2014, 11:11:30 AM (11 years ago)
Author:
dmik
Message:

python: Update vendor to 2.7.6.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/vendor/current/Parser/myreadline.c

    r2 r388  
    4040my_fgets(char *buf, int len, FILE *fp)
    4141{
    42         char *p;
    43         for (;;) {
    44                 if (PyOS_InputHook != NULL)
    45                         (void)(PyOS_InputHook)();
    46                 errno = 0;
    47                 p = fgets(buf, len, fp);
    48                 if (p != NULL)
    49                         return 0; /* No error */
     42    char *p;
    5043#ifdef MS_WINDOWS
    51                 /* In the case of a Ctrl+C or some other external event
    52                    interrupting the operation:
    53                    Win2k/NT: ERROR_OPERATION_ABORTED is the most recent Win32
    54                    error code (and feof() returns TRUE).
    55                    Win9x: Ctrl+C seems to have no effect on fgets() returning
    56                    early - the signal handler is called, but the fgets()
    57                    only returns "normally" (ie, when Enter hit or feof())
    58                 */
    59                 if (GetLastError()==ERROR_OPERATION_ABORTED) {
    60                         /* Signals come asynchronously, so we sleep a brief
    61                            moment before checking if the handler has been
    62                            triggered (we cant just return 1 before the
    63                            signal handler has been called, as the later
    64                            signal may be treated as a separate interrupt).
    65                         */
    66                         Sleep(1);
    67                         if (PyOS_InterruptOccurred()) {
    68                                 return 1; /* Interrupt */
    69                         }
    70                         /* Either the sleep wasn't long enough (need a
    71                            short loop retrying?) or not interrupted at all
    72                            (in which case we should revisit the whole thing!)
    73                            Logging some warning would be nice.  assert is not
    74                            viable as under the debugger, the various dialogs
    75                            mean the condition is not true.
    76                         */
    77                 }
     44    int i;
     45#endif
     46
     47    while (1) {
     48        if (PyOS_InputHook != NULL)
     49            (void)(PyOS_InputHook)();
     50        errno = 0;
     51        clearerr(fp);
     52        p = fgets(buf, len, fp);
     53        if (p != NULL)
     54            return 0; /* No error */
     55#ifdef MS_WINDOWS
     56        /* Ctrl-C anywhere on the line or Ctrl-Z if the only character
     57           on a line will set ERROR_OPERATION_ABORTED. Under normal
     58           circumstances Ctrl-C will also have caused the SIGINT handler
     59           to fire. This signal fires in another thread and is not
     60           guaranteed to have occurred before this point in the code.
     61
     62           Therefore: check in a small loop to see if the trigger has
     63           fired, in which case assume this is a Ctrl-C event. If it
     64           hasn't fired within 10ms assume that this is a Ctrl-Z on its
     65           own or that the signal isn't going to fire for some other
     66           reason and drop through to check for EOF.
     67        */
     68        if (GetLastError()==ERROR_OPERATION_ABORTED) {
     69            for (i = 0; i < 10; i++) {
     70                if (PyOS_InterruptOccurred())
     71                    return 1;
     72                Sleep(1);
     73            }
     74        }
    7875#endif /* MS_WINDOWS */
    79                 if (feof(fp)) {
    80                         return -1; /* EOF */
    81                 }
     76        if (feof(fp)) {
     77            clearerr(fp);
     78            return -1; /* EOF */
     79        }
    8280#ifdef EINTR
    83                 if (errno == EINTR) {
    84                         int s;
    85 #ifdef WITH_THREAD
    86                         PyEval_RestoreThread(_PyOS_ReadlineTState);
    87 #endif
    88                         s = PyErr_CheckSignals();
    89 #ifdef WITH_THREAD
    90                         PyEval_SaveThread();
    91 #endif
    92                         if (s < 0) {
    93                                 return 1;
    94                         }
    95                 }
    96 #endif
    97                 if (PyOS_InterruptOccurred()) {
    98                         return 1; /* Interrupt */
    99                 }
    100                 return -2; /* Error */
    101         }
    102         /* NOTREACHED */
     81        if (errno == EINTR) {
     82            int s;
     83#ifdef WITH_THREAD
     84            PyEval_RestoreThread(_PyOS_ReadlineTState);
     85#endif
     86            s = PyErr_CheckSignals();
     87#ifdef WITH_THREAD
     88            PyEval_SaveThread();
     89#endif
     90            if (s < 0)
     91                    return 1;
     92            /* try again */
     93            continue;
     94        }
     95#endif
     96        if (PyOS_InterruptOccurred()) {
     97            return 1; /* Interrupt */
     98        }
     99        return -2; /* Error */
     100    }
     101    /* NOTREACHED */
    103102}
    104103
     
    109108PyOS_StdioReadline(FILE *sys_stdin, FILE *sys_stdout, char *prompt)
    110109{
    111         size_t n;
    112         char *p;
    113         n = 100;
    114         if ((p = (char *)PyMem_MALLOC(n)) == NULL)
    115                 return NULL;
    116         fflush(sys_stdout);
     110    size_t n;
     111    char *p;
     112    n = 100;
     113    if ((p = (char *)PyMem_MALLOC(n)) == NULL)
     114        return NULL;
     115    fflush(sys_stdout);
    117116#ifndef RISCOS
    118         if (prompt)
    119                 fprintf(stderr, "%s", prompt);
     117    if (prompt)
     118        fprintf(stderr, "%s", prompt);
    120119#else
    121         if (prompt) {
    122                 if(Py_RISCOSWimpFlag)
    123                         fprintf(stderr, "\x0cr%s\x0c", prompt);
    124                 else
    125                         fprintf(stderr, "%s", prompt);
    126         }
    127 #endif
    128         fflush(stderr);
    129         switch (my_fgets(p, (int)n, sys_stdin)) {
    130         case 0: /* Normal case */
    131                 break;
    132         case 1: /* Interrupt */
    133                 PyMem_FREE(p);
    134                 return NULL;
    135         case -1: /* EOF */
    136         case -2: /* Error */
    137         default: /* Shouldn't happen */
    138                 *p = '\0';
    139                 break;
    140         }
    141         n = strlen(p);
    142         while (n > 0 && p[n-1] != '\n') {
    143                 size_t incr = n+2;
    144                 p = (char *)PyMem_REALLOC(p, n + incr);
    145                 if (p == NULL)
    146                         return NULL;
    147                 if (incr > INT_MAX) {
    148                         PyErr_SetString(PyExc_OverflowError, "input line too long");
    149                 }
    150                 if (my_fgets(p+n, (int)incr, sys_stdin) != 0)
    151                         break;
    152                 n += strlen(p+n);
    153         }
    154         return (char *)PyMem_REALLOC(p, n+1);
     120    if (prompt) {
     121        if(Py_RISCOSWimpFlag)
     122            fprintf(stderr, "\x0cr%s\x0c", prompt);
     123        else
     124            fprintf(stderr, "%s", prompt);
     125    }
     126#endif
     127    fflush(stderr);
     128    switch (my_fgets(p, (int)n, sys_stdin)) {
     129    case 0: /* Normal case */
     130        break;
     131    case 1: /* Interrupt */
     132        PyMem_FREE(p);
     133        return NULL;
     134    case -1: /* EOF */
     135    case -2: /* Error */
     136    default: /* Shouldn't happen */
     137        *p = '\0';
     138        break;
     139    }
     140    n = strlen(p);
     141    while (n > 0 && p[n-1] != '\n') {
     142        size_t incr = n+2;
     143        p = (char *)PyMem_REALLOC(p, n + incr);
     144        if (p == NULL)
     145            return NULL;
     146        if (incr > INT_MAX) {
     147            PyErr_SetString(PyExc_OverflowError, "input line too long");
     148        }
     149        if (my_fgets(p+n, (int)incr, sys_stdin) != 0)
     150            break;
     151        n += strlen(p+n);
     152    }
     153    return (char *)PyMem_REALLOC(p, n+1);
    155154}
    156155
     
    169168PyOS_Readline(FILE *sys_stdin, FILE *sys_stdout, char *prompt)
    170169{
    171         char *rv;
    172 
    173         if (_PyOS_ReadlineTState == PyThreadState_GET()) {
    174                 PyErr_SetString(PyExc_RuntimeError,
    175                                 "can't re-enter readline");
    176                 return NULL;
    177         }
    178        
    179 
    180         if (PyOS_ReadlineFunctionPointer == NULL) {
     170    char *rv;
     171
     172    if (_PyOS_ReadlineTState == PyThreadState_GET()) {
     173        PyErr_SetString(PyExc_RuntimeError,
     174                        "can't re-enter readline");
     175        return NULL;
     176    }
     177
     178
     179    if (PyOS_ReadlineFunctionPointer == NULL) {
    181180#ifdef __VMS
    182                 PyOS_ReadlineFunctionPointer = vms__StdioReadline;
     181        PyOS_ReadlineFunctionPointer = vms__StdioReadline;
    183182#else
    184                 PyOS_ReadlineFunctionPointer = PyOS_StdioReadline;
    185 #endif
    186         }
    187        
    188 #ifdef WITH_THREAD
    189         if (_PyOS_ReadlineLock == NULL) {
    190                 _PyOS_ReadlineLock = PyThread_allocate_lock();         
    191         }
    192 #endif
    193 
    194         _PyOS_ReadlineTState = PyThreadState_GET();
    195         Py_BEGIN_ALLOW_THREADS
    196 #ifdef WITH_THREAD
    197         PyThread_acquire_lock(_PyOS_ReadlineLock, 1);
    198 #endif
    199 
    200         /* This is needed to handle the unlikely case that the
    201          * interpreter is in interactive mode *and* stdin/out are not
    202          * a tty.  This can happen, for example if python is run like
    203          * this: python -i < test1.py
    204          */
    205         if (!isatty (fileno (sys_stdin)) || !isatty (fileno (sys_stdout)))
    206                 rv = PyOS_StdioReadline (sys_stdin, sys_stdout, prompt);
    207         else
    208                 rv = (*PyOS_ReadlineFunctionPointer)(sys_stdin, sys_stdout,
    209                                                      prompt);
    210         Py_END_ALLOW_THREADS
    211 
    212 #ifdef WITH_THREAD
    213         PyThread_release_lock(_PyOS_ReadlineLock);
    214 #endif
    215 
    216         _PyOS_ReadlineTState = NULL;
    217 
    218         return rv;
     183        PyOS_ReadlineFunctionPointer = PyOS_StdioReadline;
     184#endif
     185    }
     186
     187#ifdef WITH_THREAD
     188    if (_PyOS_ReadlineLock == NULL) {
     189        _PyOS_ReadlineLock = PyThread_allocate_lock();
     190    }
     191#endif
     192
     193    _PyOS_ReadlineTState = PyThreadState_GET();
     194    Py_BEGIN_ALLOW_THREADS
     195#ifdef WITH_THREAD
     196    PyThread_acquire_lock(_PyOS_ReadlineLock, 1);
     197#endif
     198
     199    /* This is needed to handle the unlikely case that the
     200     * interpreter is in interactive mode *and* stdin/out are not
     201     * a tty.  This can happen, for example if python is run like
     202     * this: python -i < test1.py
     203     */
     204    if (!isatty (fileno (sys_stdin)) || !isatty (fileno (sys_stdout)))
     205        rv = PyOS_StdioReadline (sys_stdin, sys_stdout, prompt);
     206    else
     207        rv = (*PyOS_ReadlineFunctionPointer)(sys_stdin, sys_stdout,
     208                                             prompt);
     209    Py_END_ALLOW_THREADS
     210
     211#ifdef WITH_THREAD
     212    PyThread_release_lock(_PyOS_ReadlineLock);
     213#endif
     214
     215    _PyOS_ReadlineTState = NULL;
     216
     217    return rv;
    219218}
Note: See TracChangeset for help on using the changeset viewer.