Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Objects/boolobject.c

    r2 r391  
    88bool_print(PyBoolObject *self, FILE *fp, int flags)
    99{
    10         Py_BEGIN_ALLOW_THREADS
    11         fputs(self->ob_ival == 0 ? "False" : "True", fp);
    12         Py_END_ALLOW_THREADS
    13         return 0;
     10    Py_BEGIN_ALLOW_THREADS
     11    fputs(self->ob_ival == 0 ? "False" : "True", fp);
     12    Py_END_ALLOW_THREADS
     13    return 0;
    1414}
    1515
     
    2222bool_repr(PyBoolObject *self)
    2323{
    24         PyObject *s;
    25 
    26         if (self->ob_ival)
    27                 s = true_str ? true_str :
    28                         (true_str = PyString_InternFromString("True"));
    29         else
    30                 s = false_str ? false_str :
    31                         (false_str = PyString_InternFromString("False"));
    32         Py_XINCREF(s);
    33         return s;
     24    PyObject *s;
     25
     26    if (self->ob_ival)
     27        s = true_str ? true_str :
     28            (true_str = PyString_InternFromString("True"));
     29    else
     30        s = false_str ? false_str :
     31            (false_str = PyString_InternFromString("False"));
     32    Py_XINCREF(s);
     33    return s;
    3434}
    3535
     
    3838PyObject *PyBool_FromLong(long ok)
    3939{
    40         PyObject *result;
    41 
    42         if (ok)
    43                 result = Py_True;
    44         else
    45                 result = Py_False;
    46         Py_INCREF(result);
    47         return result;
     40    PyObject *result;
     41
     42    if (ok)
     43        result = Py_True;
     44    else
     45        result = Py_False;
     46    Py_INCREF(result);
     47    return result;
    4848}
    4949
     
    5353bool_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
    5454{
    55         static char *kwlist[] = {"x", 0};
    56         PyObject *x = Py_False;
    57         long ok;
    58 
    59         if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O:bool", kwlist, &x))
    60                 return NULL;
    61         ok = PyObject_IsTrue(x);
    62         if (ok < 0)
    63                 return NULL;
    64         return PyBool_FromLong(ok);
     55    static char *kwlist[] = {"x", 0};
     56    PyObject *x = Py_False;
     57    long ok;
     58
     59    if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O:bool", kwlist, &x))
     60        return NULL;
     61    ok = PyObject_IsTrue(x);
     62    if (ok < 0)
     63        return NULL;
     64    return PyBool_FromLong(ok);
    6565}
    6666
     
    7070bool_and(PyObject *a, PyObject *b)
    7171{
    72         if (!PyBool_Check(a) || !PyBool_Check(b))
    73                 return PyInt_Type.tp_as_number->nb_and(a, b);
    74         return PyBool_FromLong(
    75                 ((PyBoolObject *)a)->ob_ival & ((PyBoolObject *)b)->ob_ival);
     72    if (!PyBool_Check(a) || !PyBool_Check(b))
     73        return PyInt_Type.tp_as_number->nb_and(a, b);
     74    return PyBool_FromLong(
     75        ((PyBoolObject *)a)->ob_ival & ((PyBoolObject *)b)->ob_ival);
    7676}
    7777
     
    7979bool_or(PyObject *a, PyObject *b)
    8080{
    81         if (!PyBool_Check(a) || !PyBool_Check(b))
    82                 return PyInt_Type.tp_as_number->nb_or(a, b);
    83         return PyBool_FromLong(
    84                 ((PyBoolObject *)a)->ob_ival | ((PyBoolObject *)b)->ob_ival);
     81    if (!PyBool_Check(a) || !PyBool_Check(b))
     82        return PyInt_Type.tp_as_number->nb_or(a, b);
     83    return PyBool_FromLong(
     84        ((PyBoolObject *)a)->ob_ival | ((PyBoolObject *)b)->ob_ival);
    8585}
    8686
     
    8888bool_xor(PyObject *a, PyObject *b)
    8989{
    90         if (!PyBool_Check(a) || !PyBool_Check(b))
    91                 return PyInt_Type.tp_as_number->nb_xor(a, b);
    92         return PyBool_FromLong(
    93                 ((PyBoolObject *)a)->ob_ival ^ ((PyBoolObject *)b)->ob_ival);
     90    if (!PyBool_Check(a) || !PyBool_Check(b))
     91        return PyInt_Type.tp_as_number->nb_xor(a, b);
     92    return PyBool_FromLong(
     93        ((PyBoolObject *)a)->ob_ival ^ ((PyBoolObject *)b)->ob_ival);
    9494}
    9595
     
    106106
    107107static PyNumberMethods bool_as_number = {
    108         0,                      /* nb_add */
    109         0,                      /* nb_subtract */
    110         0,                      /* nb_multiply */
    111         0,                      /* nb_divide */
    112         0,                      /* nb_remainder */
    113         0,                      /* nb_divmod */
    114         0,                      /* nb_power */
    115         0,                      /* nb_negative */
    116         0,                      /* nb_positive */
    117         0,                      /* nb_absolute */
    118         0,                      /* nb_nonzero */
    119         0,                      /* nb_invert */
    120         0,                      /* nb_lshift */
    121         0,                      /* nb_rshift */
    122         bool_and,               /* nb_and */
    123         bool_xor,               /* nb_xor */
    124         bool_or,                /* nb_or */
    125         0,                      /* nb_coerce */
    126         0,                      /* nb_int */
    127         0,                      /* nb_long */
    128         0,                      /* nb_float */
    129         0,                      /* nb_oct */
    130         0,                      /* nb_hex */
    131         0,                      /* nb_inplace_add */
    132         0,                      /* nb_inplace_subtract */
    133         0,                      /* nb_inplace_multiply */
    134         0,                      /* nb_inplace_divide */
    135         0,                      /* nb_inplace_remainder */
    136         0,                      /* nb_inplace_power */
    137         0,                      /* nb_inplace_lshift */
    138         0,                      /* nb_inplace_rshift */
    139         0,                      /* nb_inplace_and */
    140         0,                      /* nb_inplace_xor */
    141         0,                      /* nb_inplace_or */
    142         0,                      /* nb_floor_divide */
    143         0,                      /* nb_true_divide */
    144         0,                      /* nb_inplace_floor_divide */
    145         0,                      /* nb_inplace_true_divide */
     108    0,                          /* nb_add */
     109    0,                          /* nb_subtract */
     110    0,                          /* nb_multiply */
     111    0,                          /* nb_divide */
     112    0,                          /* nb_remainder */
     113    0,                          /* nb_divmod */
     114    0,                          /* nb_power */
     115    0,                          /* nb_negative */
     116    0,                          /* nb_positive */
     117    0,                          /* nb_absolute */
     118    0,                          /* nb_nonzero */
     119    0,                          /* nb_invert */
     120    0,                          /* nb_lshift */
     121    0,                          /* nb_rshift */
     122    bool_and,                   /* nb_and */
     123    bool_xor,                   /* nb_xor */
     124    bool_or,                    /* nb_or */
     125    0,                          /* nb_coerce */
     126    0,                          /* nb_int */
     127    0,                          /* nb_long */
     128    0,                          /* nb_float */
     129    0,                          /* nb_oct */
     130    0,                          /* nb_hex */
     131    0,                          /* nb_inplace_add */
     132    0,                          /* nb_inplace_subtract */
     133    0,                          /* nb_inplace_multiply */
     134    0,                          /* nb_inplace_divide */
     135    0,                          /* nb_inplace_remainder */
     136    0,                          /* nb_inplace_power */
     137    0,                          /* nb_inplace_lshift */
     138    0,                          /* nb_inplace_rshift */
     139    0,                          /* nb_inplace_and */
     140    0,                          /* nb_inplace_xor */
     141    0,                          /* nb_inplace_or */
     142    0,                          /* nb_floor_divide */
     143    0,                          /* nb_true_divide */
     144    0,                          /* nb_inplace_floor_divide */
     145    0,                          /* nb_inplace_true_divide */
    146146};
    147147
     
    149149
    150150PyTypeObject PyBool_Type = {
    151         PyVarObject_HEAD_INIT(&PyType_Type, 0)
    152         "bool",
    153         sizeof(PyIntObject),
    154         0,
    155         0,                                      /* tp_dealloc */
    156         (printfunc)bool_print,                  /* tp_print */
    157         0,                                      /* tp_getattr */
    158         0,                                      /* tp_setattr */
    159         0,                                      /* tp_compare */
    160         (reprfunc)bool_repr,                    /* tp_repr */
    161         &bool_as_number,                        /* tp_as_number */
    162         0,                                      /* tp_as_sequence */
    163         0,                                      /* tp_as_mapping */
    164         0,                                      /* tp_hash */
    165         0,                                      /* tp_call */
    166         (reprfunc)bool_repr,                    /* tp_str */
    167         0,                                      /* tp_getattro */
    168         0,                                      /* tp_setattro */
    169         0,                                      /* tp_as_buffer */
    170         Py_TPFLAGS_DEFAULT | Py_TPFLAGS_CHECKTYPES, /* tp_flags */
    171         bool_doc,                               /* tp_doc */
    172         0,                                      /* tp_traverse */
    173         0,                                      /* tp_clear */
    174         0,                                      /* tp_richcompare */
    175         0,                                      /* tp_weaklistoffset */
    176         0,                                      /* tp_iter */
    177         0,                                      /* tp_iternext */
    178         0,                                      /* tp_methods */
    179         0,                                      /* tp_members */
    180         0,                                      /* tp_getset */
    181         &PyInt_Type,                            /* tp_base */
    182         0,                                      /* tp_dict */
    183         0,                                      /* tp_descr_get */
    184         0,                                      /* tp_descr_set */
    185         0,                                      /* tp_dictoffset */
    186         0,                                      /* tp_init */
    187         0,                                      /* tp_alloc */
    188         bool_new,                               /* tp_new */
     151    PyVarObject_HEAD_INIT(&PyType_Type, 0)
     152    "bool",
     153    sizeof(PyIntObject),
     154    0,
     155    0,                                          /* tp_dealloc */
     156    (printfunc)bool_print,                      /* tp_print */
     157    0,                                          /* tp_getattr */
     158    0,                                          /* tp_setattr */
     159    0,                                          /* tp_compare */
     160    (reprfunc)bool_repr,                        /* tp_repr */
     161    &bool_as_number,                            /* tp_as_number */
     162    0,                                          /* tp_as_sequence */
     163    0,                                          /* tp_as_mapping */
     164    0,                                          /* tp_hash */
     165    0,                                          /* tp_call */
     166    (reprfunc)bool_repr,                        /* tp_str */
     167    0,                                          /* tp_getattro */
     168    0,                                          /* tp_setattro */
     169    0,                                          /* tp_as_buffer */
     170    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_CHECKTYPES, /* tp_flags */
     171    bool_doc,                                   /* tp_doc */
     172    0,                                          /* tp_traverse */
     173    0,                                          /* tp_clear */
     174    0,                                          /* tp_richcompare */
     175    0,                                          /* tp_weaklistoffset */
     176    0,                                          /* tp_iter */
     177    0,                                          /* tp_iternext */
     178    0,                                          /* tp_methods */
     179    0,                                          /* tp_members */
     180    0,                                          /* tp_getset */
     181    &PyInt_Type,                                /* tp_base */
     182    0,                                          /* tp_dict */
     183    0,                                          /* tp_descr_get */
     184    0,                                          /* tp_descr_set */
     185    0,                                          /* tp_dictoffset */
     186    0,                                          /* tp_init */
     187    0,                                          /* tp_alloc */
     188    bool_new,                                   /* tp_new */
    189189};
    190190
     
    193193/* Named Zero for link-level compatibility */
    194194PyIntObject _Py_ZeroStruct = {
    195         PyObject_HEAD_INIT(&PyBool_Type)
    196         0
     195    PyObject_HEAD_INIT(&PyBool_Type)
     196    0
    197197};
    198198
    199199PyIntObject _Py_TrueStruct = {
    200         PyObject_HEAD_INIT(&PyBool_Type)
    201         1
    202 };
     200    PyObject_HEAD_INIT(&PyBool_Type)
     201    1
     202};
Note: See TracChangeset for help on using the changeset viewer.