#include "Python.h" #include "pycore_initconfig.h" #include "pycore_interp.h" // PyInterpreterState.warnings #include "pycore_long.h" // _PyLong_GetZero() #include "pycore_pyerrors.h" #include "pycore_pystate.h" // _PyThreadState_GET() #include "pycore_frame.h" #include "clinic/_warnings.c.h" #define MODULE_NAME "_warnings" PyDoc_STRVAR(warnings__doc__, MODULE_NAME " provides basic warning filtering support.\n" "It is a helper module to speed up interpreter start-up."); /*************************************************************************/ typedef struct _warnings_runtime_state WarningsState; static inline int check_interp(PyInterpreterState *interp) { if (interp == NULL) { PyErr_SetString(PyExc_RuntimeError, "warnings_get_state: could not identify " "current interpreter"); return 0; } return 1; } static inline PyInterpreterState * get_current_interp(void) { PyInterpreterState *interp = _PyInterpreterState_GET(); return check_interp(interp) ? interp : NULL; } static inline PyThreadState * get_current_tstate(void) { PyThreadState *tstate = _PyThreadState_GET(); if (tstate == NULL) { (void)check_interp(NULL); return NULL; } return check_interp(tstate->interp) ? tstate : NULL; } /* Given a module object, get its per-module state. */ static WarningsState * warnings_get_state(PyInterpreterState *interp) { return &interp->warnings; } /* Clear the given warnings module state. */ static void warnings_clear_state(WarningsState *st) { Py_CLEAR(st->filters); Py_CLEAR(st->once_registry); Py_CLEAR(st->default_action); } #ifndef Py_DEBUG static PyObject * create_filter(PyObject *category, PyObject *action_str, const char *modname) { PyObject *modname_obj = NULL; /* Default to "no module name" for initial filter set */ if (modname != NULL) { modname_obj = PyUnicode_InternFromString(modname); if (modname_obj == NULL) { return NULL; } } else { modname_obj = Py_NewRef(Py_None); } /* This assumes the line number is zero for now. */ PyObject *filter = PyTuple_Pack(5, action_str, Py_None, category, modname_obj, _PyLong_GetZero()); Py_DECREF(modname_obj); return filter; } #endif static PyObject * init_filters(PyInterpreterState *interp) { #ifdef Py_DEBUG /* Py_DEBUG builds show all warnings by default */ return PyList_New(0); #else /* Other builds ignore a number of warning categories by default */ PyObject *filters = PyList_New(5); if (filters == NULL) { return NULL; } size_t pos = 0; /* Post-incremented in each use. */ #define ADD(TYPE, ACTION, MODNAME) \ PyList_SET_ITEM(filters, pos++, \ create_filter(TYPE, &_Py_ID(ACTION), MODNAME)); ADD(PyExc_DeprecationWarning, default, "__main__"); ADD(PyExc_DeprecationWarning, ignore, NULL); ADD(PyExc_PendingDeprecationWarning, ignore, NULL); ADD(PyExc_ImportWarning, ignore, NULL); ADD(PyExc_ResourceWarning, ignore, NULL); #undef ADD for (size_t x = 0; x < pos; x++) { if (PyList_GET_ITEM(filters, x) == NULL) { Py_DECREF(filters); return NULL; } } return filters; #endif } /* Initialize the given warnings module state. */ int _PyWarnings_InitState(PyInterpreterState *interp) { WarningsState *st = &interp->warnings; if (st->filters == NULL) { st->filters = init_filters(interp); if (st->filters == NULL) { return -1; } } if (st->once_registry == NULL) { st->once_registry = PyDict_New(); if (st->once_registry == NULL) { return -1; } } if (st->default_action == NULL) { st->default_action = PyUnicode_FromString("default"); if (st->default_action == NULL) { return -1; } } st->filters_version = 0; return 0; } /*************************************************************************/ static int check_matched(PyInterpreterState *interp, PyObject *obj, PyObject *arg) { PyObject *result; int rc; /* A 'None' filter always matches */ if (obj == Py_None) return 1; /* An internal plain text default filter must match exactly */ if (PyUnicode_CheckExact(obj)) { int cmp_result = PyUnicode_Compare(obj, arg); if (cmp_result == -1 && PyErr_Occurred()) { return -1; } return !cmp_result; } /* Otherwise assume a regex filter and call its match() method */ result = PyObject_CallMethodOneArg(obj, &_Py_ID(match), arg); if (result == NULL) return -1; rc = PyObject_IsTrue(result); Py_DECREF(result); return rc; } #define GET_WARNINGS_ATTR(interp, ATTR, try_import) \ get_warnings_attr(interp, &_Py_ID(ATTR), try_import) /* Returns a new reference. A NULL return value can mean false or an error. */ static PyObject * get_warnings_attr(PyInterpreterState *interp, PyObject *attr, int try_import) { PyObject *warnings_module, *obj; /* don't try to import after the start of the Python finallization */ if (try_import && !_Py_IsFinalizing()) { warnings_module = PyImport_Import(&_Py_ID(warnings)); if (warnings_module == NULL) { /* Fallback to the C implementation if we cannot get the Python implementation */ if (PyErr_ExceptionMatches(PyExc_ImportError)) { PyErr_Clear(); } return NULL; } } else { /* if we're so late into Python finalization that the module dict is gone, then we can't even use PyImport_GetModule without triggering an interpreter abort. */ if (!_PyImport_GetModules(interp)) { return NULL; } warnings_module = PyImport_GetModule(&_Py_ID(warnings)); if (warnings_module == NULL) return NULL; } (void)_PyObject_LookupAttr(warnings_module, attr, &obj); Py_DECREF(warnings_module); return obj; } sta/**************************************************************************** ** ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtSCriptTools module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage ** This file contains pre-release code and may not be distributed. ** You may use this file in accordance with the terms and conditions ** contained in the Technology Preview License Agreement accompanying ** this package. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser ** General Public License version 2.1 as published by the Free Software ** Foundation and appearing in the file LICENSE.LGPL included in the ** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 2.1 requirements ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** ** In addition, as a special exception, Nokia gives you certain additional ** rights. These rights are described in the Nokia Qt LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** If you have questions regarding the use of this file, please contact ** Nokia at qt-info@nokia.com. ** ** ** ** ** ** ** ** ** $QT_END_LICENSE$ ** ****************************************************************************/ #include "qscriptdebuggerscriptswidgetinterface_p.h" #include "qscriptdebuggerscriptswidgetinterface_p_p.h" QT_BEGIN_NAMESPACE QScriptDebuggerScriptsWidgetInterfacePrivate::QScriptDebuggerScriptsWidgetInterfacePrivate() { } QScriptDebuggerScriptsWidgetInterfacePrivate::~QScriptDebuggerScriptsWidgetInterfacePrivate() { } QScriptDebuggerScriptsWidgetInterface::~QScriptDebuggerScriptsWidgetInterface() { } QScriptDebuggerScriptsWidgetInterface::QScriptDebuggerScriptsWidgetInterface( QScriptDebuggerScriptsWidgetInterfacePrivate &dd, QWidget *parent, Qt::WindowFlags flags) : QWidget(dd, parent, flags) { } QT_END_NAMESPACE