~pythonregexp2.7/python/issue2636-09-01+10

« back to all changes in this revision

Viewing changes to Python/_warnings.c

  • Committer: Jeffrey C. "The TimeHorse" Jacobs
  • Date: 2008-09-22 21:39:45 UTC
  • mfrom: (39055.1.33 Regexp-2.7)
  • Revision ID: darklord@timehorse.com-20080922213945-23717m5eiqpamcyn
Merged in changes from the Single-Loop Engine branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#include "Python.h"
 
2
#include "code.h"  /* For DeprecationWarning about adding 'line'. */
2
3
#include "frameobject.h"
3
4
 
4
5
#define MODULE_NAME "_warnings"
256
257
    Py_XDECREF(name);
257
258
 
258
259
    /* Print "  source_line\n" */
259
 
    PyFile_WriteString("  ", f_stderr);
260
260
    if (sourceline) {
261
261
        char *source_line_str = PyString_AS_STRING(sourceline);
262
262
        while (*source_line_str == ' ' || *source_line_str == '\t' ||
267
267
        PyFile_WriteString("\n", f_stderr);
268
268
    }
269
269
    else
270
 
        Py_DisplaySourceLine(f_stderr, PyString_AS_STRING(filename), lineno);
 
270
        _Py_DisplaySourceLine(f_stderr, PyString_AS_STRING(filename), 
 
271
                              lineno, 2);
271
272
    PyErr_Clear();
272
273
}
273
274
 
280
281
    PyObject *item = Py_None;
281
282
    const char *action;
282
283
    int rc;
 
284
    
 
285
    if (registry && !PyDict_Check(registry) && (registry != Py_None)) {
 
286
        PyErr_SetString(PyExc_TypeError, "'registry' must be a dict");
 
287
        return NULL;
 
288
    }
283
289
 
284
290
    /* Normalize module. */
285
291
    if (module == NULL) {
303
309
    else {
304
310
        text = message;
305
311
        message = PyObject_CallFunction(category, "O", message);
 
312
        if (message == NULL)
 
313
            goto cleanup;
306
314
    }
307
315
 
308
316
    lineno_obj = PyInt_FromLong(lineno);
314
322
    if (key == NULL)
315
323
        goto cleanup;
316
324
 
317
 
    if (registry != NULL) {
 
325
    if ((registry != NULL) && (registry != Py_None)) {
318
326
        rc = already_warned(registry, key, 0);
319
327
        if (rc == -1)
320
328
            goto cleanup;
336
344
       is "always". */
337
345
    rc = 0;
338
346
    if (strcmp(action, "always") != 0) {
339
 
        if (registry != NULL && PyDict_SetItem(registry, key, Py_True) < 0)
 
347
        if (registry != NULL && registry != Py_None &&
 
348
                PyDict_SetItem(registry, key, Py_True) < 0)
340
349
            goto cleanup;
341
350
        else if (strcmp(action, "ignore") == 0)
342
351
            goto return_none;
343
352
        else if (strcmp(action, "once") == 0) {
344
 
            if (registry == NULL) {
 
353
            if (registry == NULL || registry == Py_None) {
345
354
                registry = get_once_registry();
346
355
                if (registry == NULL)
347
356
                    goto cleanup;
351
360
        }
352
361
        else if (strcmp(action, "module") == 0) {
353
362
            /* registry[(text, category, 0)] = 1 */
354
 
            if (registry != NULL)
 
363
            if (registry != NULL && registry != Py_None)
355
364
                rc = update_registry(registry, text, category, 0);
356
365
        }
357
366
        else if (strcmp(action, "default") != 0) {
408
417
                /* A proper implementation of warnings.showwarning() should
409
418
                    have at least two default arguments. */
410
419
                if ((defaults == NULL) || (PyTuple_Size(defaults) < 2)) {
411
 
                    if (PyErr_WarnEx(PyExc_DeprecationWarning, msg, 1) < 0) {
412
 
                        Py_DECREF(show_fxn);
413
 
                        goto cleanup;
 
420
                    PyCodeObject *code = (PyCodeObject *)
 
421
                                                PyFunction_GetCode(check_fxn);
 
422
                    if (!(code->co_flags & CO_VARARGS)) {
 
423
                        if (PyErr_WarnEx(PyExc_DeprecationWarning, msg, 1) <
 
424
                                0) {
 
425
                            Py_DECREF(show_fxn);
 
426
                            goto cleanup;
 
427
                        }
414
428
                    }
415
 
                }
 
429
                }
416
430
                res = PyObject_CallFunctionObjArgs(show_fxn, message, category,
417
431
                                                    filename, lineno_obj,
418
432
                                                    NULL);
435
449
    Py_XDECREF(text);
436
450
    Py_XDECREF(lineno_obj);
437
451
    Py_DECREF(module);
438
 
    Py_DECREF(message);
 
452
    Py_XDECREF(message);
439
453
    return result;  /* Py_None or NULL. */
440
454
}
441
455