Mercurial > cpython-lru_cache-weakref
comparison Python/errors.c @ 15591:36286632ff3a legacy-trunk
Add PyErr_Warn().
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Fri, 15 Dec 2000 21:58:52 +0000 |
| parents | 8aa947e1eee8 |
| children | 09f6c1372056 |
comparison
equal
deleted
inserted
replaced
| 15590:1e756f93bf5d | 15591:36286632ff3a |
|---|---|
| 586 } | 586 } |
| 587 Py_XDECREF(t); | 587 Py_XDECREF(t); |
| 588 Py_XDECREF(v); | 588 Py_XDECREF(v); |
| 589 Py_XDECREF(tb); | 589 Py_XDECREF(tb); |
| 590 } | 590 } |
| 591 | |
| 592 | |
| 593 /* Function to issue a warning message; may raise an exception. */ | |
| 594 int | |
| 595 PyErr_Warn(PyObject *category, char *message) | |
| 596 { | |
| 597 PyObject *mod, *dict, *func = NULL; | |
| 598 | |
| 599 mod = PyImport_ImportModule("warnings"); | |
| 600 if (mod != NULL) { | |
| 601 dict = PyModule_GetDict(mod); | |
| 602 func = PyDict_GetItemString(dict, "warn"); | |
| 603 Py_DECREF(mod); | |
| 604 } | |
| 605 if (func == NULL) { | |
| 606 PySys_WriteStderr("warning: %s\n", message); | |
| 607 return 0; | |
| 608 } | |
| 609 else { | |
| 610 PyObject *args, *res; | |
| 611 | |
| 612 if (category == NULL) | |
| 613 category = PyExc_RuntimeWarning; | |
| 614 args = Py_BuildValue("(sO)", message, category); | |
| 615 if (args == NULL) | |
| 616 return -1; | |
| 617 res = PyEval_CallObject(func, args); | |
| 618 Py_DECREF(args); | |
| 619 if (res == NULL) | |
| 620 return -1; | |
| 621 Py_DECREF(res); | |
| 622 return 0; | |
| 623 } | |
| 624 } |
