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/node.c

    r2 r388  
    88PyNode_New(int type)
    99{
    10         node *n = (node *) PyObject_MALLOC(1 * sizeof(node));
    11         if (n == NULL)
    12                 return NULL;
    13         n->n_type = type;
    14         n->n_str = NULL;
    15         n->n_lineno = 0;
    16         n->n_nchildren = 0;
    17         n->n_child = NULL;
    18         return n;
     10    node *n = (node *) PyObject_MALLOC(1 * sizeof(node));
     11    if (n == NULL)
     12        return NULL;
     13    n->n_type = type;
     14    n->n_str = NULL;
     15    n->n_lineno = 0;
     16    n->n_nchildren = 0;
     17    n->n_child = NULL;
     18    return n;
    1919}
    2020
     
    2323fancy_roundup(int n)
    2424{
    25         /* Round up to the closest power of 2 >= n. */
    26         int result = 256;
    27         assert(n > 128);
    28         while (result < n) {
    29                 result <<= 1;
    30                 if (result <= 0)
    31                         return -1;
    32         }
    33         return result;
     25    /* Round up to the closest power of 2 >= n. */
     26    int result = 256;
     27    assert(n > 128);
     28    while (result < n) {
     29        result <<= 1;
     30        if (result <= 0)
     31            return -1;
     32    }
     33    return result;
    3434}
    3535
     
    7171 * capacity.  The code is tricky to avoid that.
    7272 */
    73 #define XXXROUNDUP(n) ((n) <= 1 ? (n) :                 \
    74                        (n) <= 128 ? (((n) + 3) & ~3) :  \
    75                        fancy_roundup(n))
     73#define XXXROUNDUP(n) ((n) <= 1 ? (n) :                 \
     74               (n) <= 128 ? (((n) + 3) & ~3) :          \
     75               fancy_roundup(n))
    7676
    7777
     
    7979PyNode_AddChild(register node *n1, int type, char *str, int lineno, int col_offset)
    8080{
    81         const int nch = n1->n_nchildren;
    82         int current_capacity;
    83         int required_capacity;
    84         node *n;
     81    const int nch = n1->n_nchildren;
     82    int current_capacity;
     83    int required_capacity;
     84    node *n;
    8585
    86         if (nch == INT_MAX || nch < 0)
    87                 return E_OVERFLOW;
     86    if (nch == INT_MAX || nch < 0)
     87        return E_OVERFLOW;
    8888
    89         current_capacity = XXXROUNDUP(nch);
    90         required_capacity = XXXROUNDUP(nch + 1);
    91         if (current_capacity < 0 || required_capacity < 0)
    92                 return E_OVERFLOW;
    93         if (current_capacity < required_capacity) {
    94                 if (required_capacity > PY_SIZE_MAX / sizeof(node)) {
    95                         return E_NOMEM;
    96                 }
    97                 n = n1->n_child;
    98                 n = (node *) PyObject_REALLOC(n,
    99                                               required_capacity * sizeof(node));
    100                 if (n == NULL)
    101                         return E_NOMEM;
    102                 n1->n_child = n;
    103         }
     89    current_capacity = XXXROUNDUP(nch);
     90    required_capacity = XXXROUNDUP(nch + 1);
     91    if (current_capacity < 0 || required_capacity < 0)
     92        return E_OVERFLOW;
     93    if (current_capacity < required_capacity) {
     94        if (required_capacity > PY_SIZE_MAX / sizeof(node)) {
     95            return E_NOMEM;
     96        }
     97        n = n1->n_child;
     98        n = (node *) PyObject_REALLOC(n,
     99                                      required_capacity * sizeof(node));
     100        if (n == NULL)
     101            return E_NOMEM;
     102        n1->n_child = n;
     103    }
    104104
    105         n = &n1->n_child[n1->n_nchildren++];
    106         n->n_type = type;
    107         n->n_str = str;
    108         n->n_lineno = lineno;
    109         n->n_col_offset = col_offset;
    110         n->n_nchildren = 0;
    111         n->n_child = NULL;
    112         return 0;
     105    n = &n1->n_child[n1->n_nchildren++];
     106    n->n_type = type;
     107    n->n_str = str;
     108    n->n_lineno = lineno;
     109    n->n_col_offset = col_offset;
     110    n->n_nchildren = 0;
     111    n->n_child = NULL;
     112    return 0;
    113113}
    114114
    115115/* Forward */
    116116static void freechildren(node *);
     117static Py_ssize_t sizeofchildren(node *n);
    117118
    118119
     
    120121PyNode_Free(node *n)
    121122{
    122         if (n != NULL) {
    123                 freechildren(n);
    124                 PyObject_FREE(n);
    125         }
     123    if (n != NULL) {
     124        freechildren(n);
     125        PyObject_FREE(n);
     126    }
     127}
     128
     129Py_ssize_t
     130_PyNode_SizeOf(node *n)
     131{
     132    Py_ssize_t res = 0;
     133
     134    if (n != NULL)
     135        res = sizeof(node) + sizeofchildren(n);
     136    return res;
    126137}
    127138
     
    129140freechildren(node *n)
    130141{
    131         int i;
    132         for (i = NCH(n); --i >= 0; )
    133                 freechildren(CHILD(n, i));
    134         if (n->n_child != NULL)
    135                 PyObject_FREE(n->n_child);
    136         if (STR(n) != NULL)
    137                 PyObject_FREE(STR(n));
     142    int i;
     143    for (i = NCH(n); --i >= 0; )
     144        freechildren(CHILD(n, i));
     145    if (n->n_child != NULL)
     146        PyObject_FREE(n->n_child);
     147    if (STR(n) != NULL)
     148        PyObject_FREE(STR(n));
    138149}
     150
     151static Py_ssize_t
     152sizeofchildren(node *n)
     153{
     154    Py_ssize_t res = 0;
     155    int i;
     156    for (i = NCH(n); --i >= 0; )
     157        res += sizeofchildren(CHILD(n, i));
     158    if (n->n_child != NULL)
     159        /* allocated size of n->n_child array */
     160        res += XXXROUNDUP(NCH(n)) * sizeof(node);
     161    if (STR(n) != NULL)
     162        res += strlen(STR(n)) + 1;
     163    return res;
     164}
Note: See TracChangeset for help on using the changeset viewer.