~ubuntu-branches/ubuntu/karmic/python3.0/karmic

« back to all changes in this revision

Viewing changes to Modules/_testcapimodule.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2009-02-16 17:18:23 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20090216171823-1d5cm5qnnjvmnzzm
Tags: 3.0.1-0ubuntu1
New upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
175
175
}
176
176
 
177
177
 
 
178
/* Issue #4701: Check that PyObject_Hash implicitly calls
 
179
 *   PyType_Ready if it hasn't already been called
 
180
 */
 
181
static PyTypeObject _HashInheritanceTester_Type = {
 
182
        PyVarObject_HEAD_INIT(NULL, 0)
 
183
        "hashinheritancetester",        /* Name of this type */
 
184
        sizeof(PyObject),       /* Basic object size */
 
185
        0,                      /* Item size for varobject */
 
186
        (destructor)PyObject_Del, /* tp_dealloc */
 
187
        0,                      /* tp_print */
 
188
        0,                      /* tp_getattr */
 
189
        0,                      /* tp_setattr */
 
190
        0,                      /* tp_reserved */
 
191
        0,                      /* tp_repr */
 
192
        0,                      /* tp_as_number */
 
193
        0,                      /* tp_as_sequence */
 
194
        0,                      /* tp_as_mapping */
 
195
        0,                      /* tp_hash */
 
196
        0,                      /* tp_call */
 
197
        0,                      /* tp_str */
 
198
        PyObject_GenericGetAttr,  /* tp_getattro */
 
199
        0,                      /* tp_setattro */
 
200
        0,                      /* tp_as_buffer */
 
201
        Py_TPFLAGS_DEFAULT,     /* tp_flags */
 
202
        0,                      /* tp_doc */
 
203
        0,                      /* tp_traverse */
 
204
        0,                      /* tp_clear */
 
205
        0,                      /* tp_richcompare */
 
206
        0,                      /* tp_weaklistoffset */
 
207
        0,                      /* tp_iter */
 
208
        0,                      /* tp_iternext */
 
209
        0,                      /* tp_methods */
 
210
        0,                      /* tp_members */
 
211
        0,                      /* tp_getset */
 
212
        0,                      /* tp_base */
 
213
        0,                      /* tp_dict */
 
214
        0,                      /* tp_descr_get */
 
215
        0,                      /* tp_descr_set */
 
216
        0,                      /* tp_dictoffset */
 
217
        0,                      /* tp_init */
 
218
        0,                      /* tp_alloc */
 
219
        PyType_GenericNew,              /* tp_new */
 
220
};
 
221
 
 
222
static PyObject*
 
223
test_lazy_hash_inheritance(PyObject* self)
 
224
{
 
225
        PyTypeObject *type;
 
226
        PyObject *obj;
 
227
        long hash;
 
228
 
 
229
        type = &_HashInheritanceTester_Type;
 
230
        obj = PyObject_New(PyObject, type);
 
231
        if (obj == NULL) {
 
232
                PyErr_Clear();
 
233
                PyErr_SetString(
 
234
                        TestError,
 
235
                        "test_lazy_hash_inheritance: failed to create object");
 
236
                return NULL;
 
237
        }
 
238
 
 
239
        if (type->tp_dict != NULL) {
 
240
                PyErr_SetString(
 
241
                        TestError,
 
242
                        "test_lazy_hash_inheritance: type initialised too soon");
 
243
                Py_DECREF(obj);
 
244
                return NULL;
 
245
        }
 
246
 
 
247
        hash = PyObject_Hash(obj);
 
248
        if ((hash == -1) && PyErr_Occurred()) {
 
249
                PyErr_Clear();
 
250
                PyErr_SetString(
 
251
                        TestError,
 
252
                        "test_lazy_hash_inheritance: could not hash object");
 
253
                Py_DECREF(obj);
 
254
                return NULL;
 
255
        }
 
256
 
 
257
        if (type->tp_dict == NULL) {
 
258
                PyErr_SetString(
 
259
                        TestError,
 
260
                        "test_lazy_hash_inheritance: type not initialised by hash()");
 
261
                Py_DECREF(obj);
 
262
                return NULL;
 
263
        }
 
264
 
 
265
        if (type->tp_hash != PyType_Type.tp_hash) {
 
266
                PyErr_SetString(
 
267
                        TestError,
 
268
                        "test_lazy_hash_inheritance: unexpected hash function");
 
269
                Py_DECREF(obj);
 
270
                return NULL;
 
271
        }
 
272
 
 
273
        Py_RETURN_NONE;
 
274
}
 
275
 
 
276
 
178
277
/* Tests of PyLong_{As, From}{Unsigned,}Long(), and (#ifdef HAVE_LONG_LONG)
179
278
   PyLong_{As, From}{Unsigned,}LongLong().
180
279
 
508
607
    Py_RETURN_NONE;
509
608
}
510
609
 
 
610
static volatile int x;
 
611
 
511
612
/* Test the u and u# codes for PyArg_ParseTuple. May leak memory in case
512
613
   of an error.
513
614
*/
522
623
        /* issue4122: Undefined reference to _Py_ascii_whitespace on Windows */
523
624
        /* Just use the macro and check that it compiles */
524
625
        x = Py_UNICODE_ISSPACE(25);
525
 
        x = x;
526
626
 
527
627
        tuple = PyTuple_New(1);
528
628
        if (tuple == NULL)
608
708
}
609
709
 
610
710
static PyObject *
 
711
test_empty_argparse(PyObject *self)
 
712
{
 
713
        /* Test that formats can begin with '|'. See issue #4720. */
 
714
        PyObject *tuple, *dict = NULL;
 
715
        static char *kwlist[] = {NULL};
 
716
        int result;
 
717
        tuple = PyTuple_New(0);
 
718
        if (!tuple)
 
719
                return NULL;
 
720
        if ((result = PyArg_ParseTuple(tuple, "|:test_empty_argparse")) < 0)
 
721
                goto done;
 
722
        dict = PyDict_New();
 
723
        if (!dict)
 
724
                goto done;
 
725
        result = PyArg_ParseTupleAndKeywords(tuple, dict, "|:test_empty_argparse", kwlist);
 
726
  done:
 
727
        Py_DECREF(tuple);
 
728
        Py_XDECREF(dict);
 
729
        if (result < 0)
 
730
                return NULL;
 
731
        else {
 
732
                Py_RETURN_NONE;
 
733
        }
 
734
}
 
735
 
 
736
static PyObject *
611
737
codec_incrementalencoder(PyObject *self, PyObject *args)
612
738
{
613
739
        const char *encoding, *errors = NULL;
1009
1135
        {"test_config",         (PyCFunction)test_config,        METH_NOARGS},
1010
1136
        {"test_list_api",       (PyCFunction)test_list_api,      METH_NOARGS},
1011
1137
        {"test_dict_iteration", (PyCFunction)test_dict_iteration,METH_NOARGS},
 
1138
        {"test_lazy_hash_inheritance",  (PyCFunction)test_lazy_hash_inheritance,METH_NOARGS},
1012
1139
        {"test_long_api",       (PyCFunction)test_long_api,      METH_NOARGS},
1013
1140
        {"test_long_numbits",   (PyCFunction)test_long_numbits,  METH_NOARGS},
1014
1141
        {"test_k_code",         (PyCFunction)test_k_code,        METH_NOARGS},
 
1142
        {"test_empty_argparse", (PyCFunction)test_empty_argparse,METH_NOARGS},
1015
1143
        {"test_null_strings",   (PyCFunction)test_null_strings,  METH_NOARGS},
1016
1144
        {"test_string_from_format", (PyCFunction)test_string_from_format, METH_NOARGS},
1017
1145
        {"test_with_docstring", (PyCFunction)test_with_docstring, METH_NOARGS,
1156
1284
        0,                              /* tp_print */
1157
1285
        0,                              /* tp_getattr */
1158
1286
        0,                              /* tp_setattr */
1159
 
        0,                              /* tp_compare */
 
1287
        0,                              /* tp_reserved */
1160
1288
        0,                              /* tp_repr */
1161
1289
        0,                              /* tp_as_number */
1162
1290
        0,                              /* tp_as_sequence */
1211
1339
        if (m == NULL)
1212
1340
                return NULL;
1213
1341
 
 
1342
        Py_TYPE(&_HashInheritanceTester_Type)=&PyType_Type;
 
1343
 
1214
1344
        Py_TYPE(&test_structmembersType)=&PyType_Type;
1215
1345
        Py_INCREF(&test_structmembersType);
1216
1346
        PyModule_AddObject(m, "test_structmembersType", (PyObject *)&test_structmembersType);