~ubuntu-branches/ubuntu/lucid/python2.6/lucid

« back to all changes in this revision

Viewing changes to Python/ceval.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2010-03-11 13:30:19 UTC
  • mto: (10.1.13 sid)
  • mto: This revision was merged to the branch mainline in revision 44.
  • Revision ID: james.westby@ubuntu.com-20100311133019-sblbooa3uqrkoe70
Tags: upstream-2.6.5~rc2
ImportĀ upstreamĀ versionĀ 2.6.5~rc2

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
        ((long*)(v))[1] = tb;
52
52
}
53
53
 
54
 
#else /* this is for linux/x86 (and probably any other GCC/x86 combo) */
 
54
#elif defined(__i386__)
 
55
 
 
56
/* this is for linux/x86 (and probably any other GCC/x86 combo) */
55
57
 
56
58
#define READ_TIMESTAMP(val) \
57
59
     __asm__ __volatile__("rdtsc" : "=A" (val))
58
60
 
 
61
#elif defined(__x86_64__)
 
62
 
 
63
/* for gcc/x86_64, the "A" constraint in DI mode means *either* rax *or* rdx;
 
64
   not edx:eax as it does for i386.  Since rdtsc puts its result in edx:eax
 
65
   even in 64-bit mode, we need to use "a" and "d" for the lower and upper
 
66
   32-bit pieces of the result. */
 
67
 
 
68
#define READ_TIMESTAMP(val) \
 
69
    __asm__ __volatile__("rdtsc" : \
 
70
                         "=a" (((int*)&(val))[0]), "=d" (((int*)&(val))[1]));
 
71
 
 
72
 
 
73
#else
 
74
 
 
75
#error "Don't know how to implement timestamp counter for this architecture"
 
76
 
59
77
#endif
60
78
 
61
79
void dump_tsc(int opcode, int ticked, uint64 inst0, uint64 inst1,
127
145
static void format_exc_check_arg(PyObject *, char *, PyObject *);
128
146
static PyObject * string_concatenate(PyObject *, PyObject *,
129
147
                                    PyFrameObject *, unsigned char *);
 
148
static PyObject * kwd_as_string(PyObject *);
130
149
 
131
150
#define NAME_ERROR_MSG \
132
151
        "name '%.200s' is not defined"
1173
1192
                                register long a, b, i;
1174
1193
                                a = PyInt_AS_LONG(v);
1175
1194
                                b = PyInt_AS_LONG(w);
1176
 
                                i = a + b;
 
1195
                                /* cast to avoid undefined behaviour
 
1196
                                   on overflow */
 
1197
                                i = (long)((unsigned long)a + b);
1177
1198
                                if ((i^a) < 0 && (i^b) < 0)
1178
1199
                                        goto slow_add;
1179
1200
                                x = PyInt_FromLong(i);
1203
1224
                                register long a, b, i;
1204
1225
                                a = PyInt_AS_LONG(v);
1205
1226
                                b = PyInt_AS_LONG(w);
1206
 
                                i = a - b;
 
1227
                                /* cast to avoid undefined behaviour
 
1228
                                   on overflow */
 
1229
                                i = (long)((unsigned long)a - b);
1207
1230
                                if ((i^a) < 0 && (i^~b) < 0)
1208
1231
                                        goto slow_sub;
1209
1232
                                x = PyInt_FromLong(i);
2809
2832
                        PyObject *keyword = kws[2*i];
2810
2833
                        PyObject *value = kws[2*i + 1];
2811
2834
                        int j;
2812
 
                        if (keyword == NULL || !PyString_Check(keyword)) {
 
2835
                        if (keyword == NULL || !(PyString_Check(keyword) ||
 
2836
                                                 PyUnicode_Check(keyword))) {
2813
2837
                                PyErr_Format(PyExc_TypeError,
2814
2838
                                    "%.200s() keywords must be strings",
2815
2839
                                    PyString_AsString(co->co_name));
2838
2862
                                goto fail;
2839
2863
                        if (j >= co->co_argcount) {
2840
2864
                                if (kwdict == NULL) {
2841
 
                                        PyErr_Format(PyExc_TypeError,
2842
 
                                            "%.200s() got an unexpected "
2843
 
                                            "keyword argument '%.400s'",
2844
 
                                            PyString_AsString(co->co_name),
2845
 
                                            PyString_AsString(keyword));
 
2865
                                        PyObject *kwd_str = kwd_as_string(keyword);
 
2866
                                        if (kwd_str) {
 
2867
                                                PyErr_Format(PyExc_TypeError,
 
2868
                                                             "%.200s() got an unexpected "
 
2869
                                                             "keyword argument '%.400s'",
 
2870
                                                             PyString_AsString(co->co_name),
 
2871
                                                             PyString_AsString(kwd_str));
 
2872
                                                Py_DECREF(kwd_str);
 
2873
                                        }
2846
2874
                                        goto fail;
2847
2875
                                }
2848
2876
                                PyDict_SetItem(kwdict, keyword, value);
2850
2878
                        }
2851
2879
kw_found:
2852
2880
                        if (GETLOCAL(j) != NULL) {
2853
 
                                PyErr_Format(PyExc_TypeError,
2854
 
                                                "%.200s() got multiple "
2855
 
                                                "values for keyword "
2856
 
                                                "argument '%.400s'",
2857
 
                                                PyString_AsString(co->co_name),
2858
 
                                                PyString_AsString(keyword));
 
2881
                                PyObject *kwd_str = kwd_as_string(keyword);
 
2882
                                if (kwd_str) {
 
2883
                                        PyErr_Format(PyExc_TypeError,
 
2884
                                                     "%.200s() got multiple "
 
2885
                                                     "values for keyword "
 
2886
                                                     "argument '%.400s'",
 
2887
                                                     PyString_AsString(co->co_name),
 
2888
                                                     PyString_AsString(kwd_str));
 
2889
                                        Py_DECREF(kwd_str);
 
2890
                                }
2859
2891
                                goto fail;
2860
2892
                        }
2861
2893
                        Py_INCREF(value);
2982
3014
}
2983
3015
 
2984
3016
 
 
3017
static PyObject *
 
3018
kwd_as_string(PyObject *kwd) {
 
3019
        if (PyString_Check(kwd)) {
 
3020
                Py_INCREF(kwd);
 
3021
                return kwd;
 
3022
        }
 
3023
        else
 
3024
                return _PyUnicode_AsDefaultEncodedString(kwd, "replace");
 
3025
}
 
3026
 
 
3027
 
2985
3028
/* Implementation notes for set_exc_info() and reset_exc_info():
2986
3029
 
2987
3030
- Below, 'exc_ZZZ' stands for 'exc_type', 'exc_value' and
3217
3260
                /* Not something you can raise.  You get an exception
3218
3261
                   anyway, just not what you specified :-) */
3219
3262
                PyErr_Format(PyExc_TypeError,
3220
 
                        "exceptions must be classes or instances, not %s",
3221
 
                        type->ob_type->tp_name);
 
3263
                             "exceptions must be old-style classes or "
 
3264
                             "derived from BaseException, not %s",
 
3265
                             type->ob_type->tp_name);
3222
3266
                goto raise_error;
3223
3267
        }
3224
3268