예제 #1
0
파일: errors.c 프로젝트: Belxjander/Kirito
/* Function to issue a warning message; may raise an exception. */
int
PyErr_Warn(PyObject *category, char *message)
{
	PyObject *dict, *func = NULL;
	PyObject *warnings_module = PyModule_GetWarningsModule();

	if (warnings_module != NULL) {
		dict = PyModule_GetDict(warnings_module);
		func = PyDict_GetItemString(dict, "warn");
	}
	if (func == NULL) {
		PySys_WriteStderr("warning: %s\n", message);
		return 0;
	}
	else {
		PyObject *args, *res;

		if (category == NULL)
			category = PyExc_RuntimeWarning;
		args = Py_BuildValue("(sO)", message, category);
		if (args == NULL)
			return -1;
		res = PyEval_CallObject(func, args);
		Py_DECREF(args);
		if (res == NULL)
			return -1;
		Py_DECREF(res);
		return 0;
	}
}
예제 #2
0
/* Function to issue a warning message; may raise an exception. */
int
PyErr_WarnEx(PyObject *category, const char *message, Py_ssize_t stack_level)
{
    PyObject *dict, *func = NULL;
    PyObject *warnings_module = PyModule_GetWarningsModule();

    if (warnings_module != NULL) {
        dict = PyModule_GetDict(warnings_module);
        func = PyDict_GetItemString(dict, "warn");
    }
    if (func == NULL) {
        PySys_WriteStderr("warning: %s\n", message);
        return 0;
    }
    else {
        PyObject *res;

        if (category == NULL)
            category = PyExc_RuntimeWarning;
        res = PyObject_CallFunction(func, "sOn",
                                    message, category, stack_level);
        if (res == NULL)
            return -1;
        Py_DECREF(res);
        return 0;
    }
}