summaryrefslogtreecommitdiffstats
path: root/Lib/asyncore.py
diff options
context:
space:
mode:
authorCharles-François Natali <neologix@free.fr>2011-07-14 18:00:49 (GMT)
committerCharles-François Natali <neologix@free.fr>2011-07-14 18:00:49 (GMT)
commitf64f9e9ec1f8f39dd8c889368ecaad0e198efcb6 (patch)
tree7b843e92fc022ee1c0009a3ecefe69f6f746aba0 /Lib/asyncore.py
parentb6ffa7980f2f0fe27efa6cd0e80e511f6bfb00e0 (diff)
downloadcpython-f64f9e9ec1f8f39dd8c889368ecaad0e198efcb6.zip
cpython-f64f9e9ec1f8f39dd8c889368ecaad0e198efcb6.tar.gz
cpython-f64f9e9ec1f8f39dd8c889368ecaad0e198efcb6.tar.bz2
Merge - Issue #12502: asyncore: fix polling loop with AF_UNIX sockets.
Diffstat (limited to 'Lib/asyncore.py')
-rw-r--r--Lib/asyncore.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/Lib/asyncore.py b/Lib/asyncore.py
index d647606..e699815 100644
--- a/Lib/asyncore.py
+++ b/Lib/asyncore.py
@@ -132,7 +132,8 @@ def poll(timeout=0.0, map=None):
is_w = obj.writable()
if is_r:
r.append(fd)
- if is_w:
+ # accepting sockets should not be writable
+ if is_w and not obj.accepting:
w.append(fd)
if is_r or is_w:
e.append(fd)
@@ -179,7 +180,8 @@ def poll2(timeout=0.0, map=None):
flags = 0
if obj.readable():
flags |= select.POLLIN | select.POLLPRI
- if obj.writable():
+ # accepting sockets should not be writable
+ if obj.writable() and not obj.accepting:
flags |= select.POLLOUT
if flags:
# Only check for exceptions if object was either readable
odel.h | 2 +- src/gui/itemviews/qcolumnview.h | 2 +- src/gui/itemviews/qcolumnviewgrip_p.h | 2 +- src/gui/itemviews/qdatawidgetmapper.h | 2 +- src/gui/itemviews/qdirmodel.h | 2 +- src/gui/itemviews/qfileiconprovider.h | 2 +- src/gui/itemviews/qheaderview.h | 2 +- src/gui/itemviews/qitemdelegate.h | 2 +- src/gui/itemviews/qitemselectionmodel.h | 2 +- src/gui/itemviews/qlistview.h | 2 +- src/gui/itemviews/qlistwidget.h | 2 +- src/gui/itemviews/qproxymodel.h | 2 +- src/gui/itemviews/qsortfilterproxymodel.h | 2 +- src/gui/itemviews/qstandarditemmodel.h | 4 +- src/gui/itemviews/qstyleditemdelegate.h | 2 +- src/gui/itemviews/qtableview.h | 2 +- src/gui/itemviews/qtablewidget.h | 2 +- src/gui/itemviews/qtreeview.h | 2 +- src/gui/itemviews/qtreewidget.h | 2 +- src/gui/itemviews/qtreewidget_p.h | 2 +- src/gui/itemviews/qtreewidgetitemiterator.h | 2 +- src/gui/kernel/qaction.h | 2 +- src/gui/kernel/qactiongroup.h | 2 +- src/gui/kernel/qapplication.cpp | 33 +-- src/gui/kernel/qapplication.h | 2 +- src/gui/kernel/qapplication_qws.cpp | 12 +- src/gui/kernel/qapplication_s60.cpp | 12 +- src/gui/kernel/qapplication_win.cpp | 2 +- src/gui/kernel/qboxlayout.cpp | 29 ++- src/gui/kernel/qboxlayout.h | 2 +- src/gui/kernel/qclipboard.h | 2 +- src/gui/kernel/qclipboard_s60.cpp | 15 +- src/gui/kernel/qdesktopwidget.h | 2 +- src/gui/kernel/qdesktopwidget_x11.cpp | 2 +- src/gui/kernel/qdnd_s60.cpp | 2 +- src/gui/kernel/qdnd_x11.cpp | 2 +- src/gui/kernel/qdrag.h | 2 +- src/gui/kernel/qeventdispatcher_glib_qws_p.h | 2 +- src/gui/kernel/qeventdispatcher_mac_p.h | 2 +- src/gui/kernel/qeventdispatcher_qws_p.h | 2 +- src/gui/kernel/qeventdispatcher_s60.cpp | 2 +- src/gui/kernel/qeventdispatcher_x11_p.h | 2 +- src/gui/kernel/qformlayout.h | 2 +- src/gui/kernel/qgesture.h | 4 +- src/gui/kernel/qgesturerecognizer.h | 2 +- src/gui/kernel/qgridlayout.h | 2 +- src/gui/kernel/qguieventdispatcher_glib_p.h | 2 +- src/gui/kernel/qkeymapper_mac.cpp | 10 +- src/gui/kernel/qkeymapper_p.h | 4 +- src/gui/kernel/qkeymapper_win.cpp | 9 +- src/gui/kernel/qkeysequence.cpp | 4 +- src/gui/kernel/qlayout.h | 2 +- src/gui/kernel/qsessionmanager.h | 2 +- src/gui/kernel/qshortcut.h | 2 +- src/gui/kernel/qshortcutmap_p.h | 2 +- src/gui/kernel/qsound.h | 2 +- src/gui/kernel/qstackedlayout.h | 2 +- src/gui/kernel/qt_s60_p.h | 10 +- src/gui/kernel/qwidget.cpp | 74 ++++-- src/gui/kernel/qwidget.h | 2 +- src/gui/kernel/qwidget_mac.mm | 6 +- src/gui/kernel/qwidget_p.h | 7 +- src/gui/kernel/qwidget_qws.cpp | 9 +- src/gui/kernel/qwidget_s60.cpp | 34 +-- src/gui/kernel/qwidget_win.cpp | 6 +- src/gui/kernel/qwidget_x11.cpp | 6 +- src/gui/kernel/qwidgetaction.h | 2 +- src/gui/kernel/qx11embed_x11.cpp | 2 +- src/gui/kernel/qx11embed_x11.h | 4 +- src/gui/painting/qbrush.cpp | 10 +- src/gui/painting/qbrush.h | 4 +- src/gui/painting/qgrayraster.c | 4 + src/gui/painting/qpaintengine.h | 2 +- src/gui/painting/qpaintengine_alpha_p.h | 2 +- src/gui/painting/qpaintengine_mac_p.h | 2 +- src/gui/painting/qpaintengine_preview_p.h | 2 +- src/gui/painting/qpaintengine_raster.cpp | 98 ++++---- src/gui/painting/qpaintengine_raster_p.h | 16 +- src/gui/painting/qpaintengine_x11.cpp | 2 +- src/gui/painting/qpaintengine_x11_p.h | 2 +- src/gui/painting/qpaintengineex_p.h | 2 +- src/gui/painting/qpainter.cpp | 19 +- src/gui/painting/qpainter.h | 6 +- src/gui/painting/qpainterpath.cpp | 9 +- src/gui/painting/qpainterpath.h | 8 +- src/gui/painting/qpdf_p.h | 2 +- src/gui/painting/qprintengine_mac_p.h | 2 +- src/gui/painting/qprintengine_pdf_p.h | 2 +- src/gui/painting/qprintengine_ps_p.h | 2 +- src/gui/painting/qprintengine_qws_p.h | 2 +- src/gui/painting/qprintengine_win_p.h | 2 +- src/gui/painting/qprinter.h | 2 +- src/gui/painting/qprinterinfo.h | 6 +- src/gui/painting/qprinterinfo_mac.cpp | 8 +- src/gui/painting/qprinterinfo_unix.cpp | 8 +- src/gui/painting/qprinterinfo_win.cpp | 8 +- src/gui/painting/qrasterizer.cpp | 4 +- src/gui/painting/qtessellator.cpp | 12 +- src/gui/painting/qwindowsurface_raster_p.h | 2 +- src/gui/painting/qwindowsurface_s60.cpp | 9 +- src/gui/statemachine/qbasickeyeventtransition_p.h | 2 +- .../statemachine/qbasicmouseeventtransition_p.h | 2 +- src/gui/statemachine/qkeyeventtransition.h | 2 +- src/gui/statemachine/qmouseeventtransition.h | 2 +- src/gui/styles/qcleanlooksstyle.h | 2 +- src/gui/styles/qcommonstyle.cpp | 4 +- src/gui/styles/qcommonstyle.h | 2 +- src/gui/styles/qgtkstyle.h | 2 +- src/gui/styles/qmotifstyle.h | 2 +- src/gui/styles/qplastiquestyle.h | 2 +- src/gui/styles/qproxystyle.h | 2 +- src/gui/styles/qs60style.cpp | 22 +- src/gui/styles/qs60style.h | 2 +- src/gui/styles/qs60style_p.h | 2 +- src/gui/styles/qs60style_s60.cpp | 53 +++-- src/gui/styles/qstyle.h | 2 +- src/gui/styles/qstylesheetstyle_p.h | 2 +- src/gui/styles/qwindowsmobilestyle.h | 2 +- src/gui/styles/qwindowsstyle.h | 2 +- src/gui/styles/qwindowsvistastyle.h | 2 +- src/gui/styles/qwindowsxpstyle.h | 2 +- src/gui/text/qabstractfontengine_qws.h | 4 +- src/gui/text/qabstracttextdocumentlayout.h | 2 +- src/gui/text/qfontdatabase.cpp | 4 +- src/gui/text/qfontdatabase_qws.cpp | 86 +++---- src/gui/text/qfontdatabase_s60.cpp | 17 +- src/gui/text/qfontengine.cpp | 4 +- src/gui/text/qfontengine_ft.cpp | 19 +- src/gui/text/qfontengine_ft_p.h | 2 +- src/gui/text/qfontengine_s60.cpp | 8 +- src/gui/text/qfontengine_win.cpp | 11 +- src/gui/text/qfragmentmap_p.h | 13 +- src/gui/text/qsyntaxhighlighter.h | 2 +- src/gui/text/qtextcontrol_p.h | 2 +- src/gui/text/qtextdocument.h | 2 +- src/gui/text/qtextdocument_p.cpp | 76 +++--- src/gui/text/qtextdocumentlayout_p.h | 2 +- src/gui/text/qtextformat.cpp | 16 +- src/gui/text/qtextlist.h | 2 +- src/gui/text/qtextobject.h | 6 +- src/gui/text/qtexttable.cpp | 8 +- src/gui/text/qtexttable.h | 2 +- src/gui/util/qcompleter.cpp | 7 +- src/gui/util/qcompleter.h | 2 +- src/gui/util/qcompleter_p.h | 5 +- src/gui/util/qdesktopservices_s60.cpp | 57 +++-- src/gui/util/qsystemtrayicon.h | 2 +- src/gui/util/qundogroup.h | 2 +- src/gui/util/qundostack.h | 2 +- src/gui/util/qundoview.h | 2 +- src/gui/widgets/qabstractbutton.h | 2 +- src/gui/widgets/qabstractscrollarea.h | 2 +- src/gui/widgets/qabstractslider.h | 2 +- src/gui/widgets/qabstractspinbox.h | 2 +- src/gui/widgets/qbuttongroup.h | 2 +- src/gui/widgets/qcalendarwidget.h | 2 +- src/gui/widgets/qcheckbox.h | 2 +- src/gui/widgets/qcombobox.cpp | 8 +- src/gui/widgets/qcombobox.h | 2 +- src/gui/widgets/qcommandlinkbutton.h | 2 +- src/gui/widgets/qdatetimeedit.h | 2 +- src/gui/widgets/qdial.h | 2 +- src/gui/widgets/qdialogbuttonbox.h | 2 +- src/gui/widgets/qdockwidget.h | 2 +- src/gui/widgets/qfocusframe.h | 2 +- src/gui/widgets/qfontcombobox.h | 2 +- src/gui/widgets/qframe.h | 2 +- src/gui/widgets/qgroupbox.h | 2 +- src/gui/widgets/qlabel.h | 2 +- src/gui/widgets/qlcdnumber.h | 2 +- src/gui/widgets/qlineedit.h | 2 +- src/gui/widgets/qmaccocoaviewcontainer_mac.h | 2 +- src/gui/widgets/qmacnativewidget_mac.h | 2 +- src/gui/widgets/qmainwindow.h | 2 +- src/gui/widgets/qmdiarea.h | 2 +- src/gui/widgets/qmdisubwindow.h | 2 +- src/gui/widgets/qmenu.cpp | 2 +- src/gui/widgets/qmenu.h | 2 +- src/gui/widgets/qmenu_symbian.cpp | 4 +- src/gui/widgets/qmenubar.h | 2 +- src/gui/widgets/qplaintextedit.h | 4 +- src/gui/widgets/qprintpreviewwidget.h | 2 +- src/gui/widgets/qprogressbar.h | 2 +- src/gui/widgets/qpushbutton.h | 2 +- src/gui/widgets/qradiobutton.h | 2 +- src/gui/widgets/qrubberband.h | 2 +- src/gui/widgets/qscrollarea.h | 2 +- src/gui/widgets/qscrollbar.h | 2 +- src/gui/widgets/qsizegrip.h | 2 +- src/gui/widgets/qslider.h | 2 +- src/gui/widgets/qspinbox.h | 4 +- src/gui/widgets/qsplashscreen.h | 2 +- src/gui/widgets/qsplitter.h | 4 +- src/gui/widgets/qstackedwidget.h | 2 +- src/gui/widgets/qstatusbar.h | 2 +- src/gui/widgets/qtabbar.h | 2 +- src/gui/widgets/qtabwidget.h | 2 +- src/gui/widgets/qtextbrowser.h | 2 +- src/gui/widgets/qtextedit.h | 2 +- src/gui/widgets/qtoolbar.h | 2 +- src/gui/widgets/qtoolbox.h | 2 +- src/gui/widgets/qtoolbutton.h | 2 +- src/gui/widgets/qvalidator.h | 4 +- src/gui/widgets/qworkspace.cpp | 2 +- src/gui/widgets/qworkspace.h | 2 +- src/network/access/qabstractnetworkcache.h | 2 +- src/network/access/qftp.h | 2 +- src/network/access/qhttp.h | 8 +- src/network/access/qhttpnetworkconnection_p.h | 2 +- src/network/access/qhttpnetworkreply_p.h | 2 +- src/network/access/qnetworkaccessmanager.h | 2 +- src/network/access/qnetworkcookie.h | 2 +- src/network/access/qnetworkdiskcache.h | 2 +- src/network/access/qnetworkreply.h | 2 +- src/network/access/qnetworkreplyimpl_p.h | 2 +- src/network/socket/qabstractsocket.h | 2 +- src/network/socket/qabstractsocketengine_p.h | 2 +- src/network/socket/qhttpsocketengine_p.h | 2 +- src/network/socket/qlocalserver.h | 2 +- src/network/socket/qlocalsocket.h | 2 +- src/network/socket/qnativesocketengine_p.h | 2 +- src/network/socket/qsocks5socketengine_p.h | 2 +- src/network/socket/qtcpserver.h | 2 +- src/network/socket/qtcpsocket.h | 2 +- src/network/socket/qudpsocket.h | 2 +- src/network/ssl/qsslsocket.h | 2 +- .../gl2paintengineex/qpaintengineex_opengl2_p.h | 2 +- src/opengl/qgl.h | 4 +- src/opengl/qglframebufferobject.h | 2 +- src/opengl/qglpaintdevice_qws_p.h | 2 +- src/opengl/qglpixelbuffer.h | 2 +- src/opengl/qglscreen_qws.h | 2 +- src/opengl/qglwindowsurface_qws_p.h | 2 +- src/opengl/qpaintengine_opengl_p.h | 2 +- .../gfxdrivers/directfb/qdirectfbpaintengine.h | 2 +- src/plugins/imageformats/mng/qmnghandler.h | 2 +- src/plugins/s60/src/qdesktopservices_3_2.cpp | 18 +- src/qt3support/other/q3dragobject.h | 8 +- src/qt3support/painting/q3paintengine_svg_p.h | 2 +- src/qt3support/widgets/q3mainwindow.h | 2 +- src/qt3support/widgets/q3titlebar_p.h | 2 +- src/s60main/qts60main_mcrt0.cpp | 9 +- src/s60main/qts60mainappui.cpp | 7 +- src/script/qscriptable.h | 2 +- src/script/qscriptclass.h | 2 +- src/script/qscriptclasspropertyiterator.h | 2 +- src/script/qscriptcontext.h | 2 +- src/script/qscriptcontextinfo.h | 2 +- src/script/qscriptengine.h | 4 +- src/script/qscriptengineagent.h | 2 +- src/script/qscriptstring.cpp | 8 +- src/script/qscriptstring.h | 6 +- src/script/qscriptvalue.cpp | 8 +- src/script/qscriptvalue.h | 6 +- src/script/qscriptvalueiterator.h | 2 +- .../debugging/qscriptbreakpointdata_p.h | 2 +- .../debugging/qscriptbreakpointsmodel_p.h | 2 +- .../debugging/qscriptbreakpointswidget_p.h | 2 +- .../qscriptbreakpointswidgetinterface_p.h | 2 +- .../debugging/qscriptcompletiontask_p.h | 2 +- .../debugging/qscriptcompletiontaskinterface_p.h | 2 +- src/scripttools/debugging/qscriptdebugger_p.h | 2 +- src/scripttools/debugging/qscriptdebuggeragent_p.h | 2 +- .../debugging/qscriptdebuggerbackend_p.h | 2 +- .../debugging/qscriptdebuggercodefinderwidget_p.h | 2 +- .../qscriptdebuggercodefinderwidgetinterface_p.h | 2 +- .../debugging/qscriptdebuggercodeview_p.h | 2 +- .../debugging/qscriptdebuggercodeviewinterface_p.h | 2 +- .../debugging/qscriptdebuggercodewidget_p.h | 2 +- .../qscriptdebuggercodewidgetinterface_p.h | 2 +- .../debugging/qscriptdebuggercommand_p.h | 2 +- .../debugging/qscriptdebuggercommandexecutor_p.h | 2 +- .../qscriptdebuggercommandschedulerjob_p.h | 2 +- .../debugging/qscriptdebuggerconsole_p.h | 2 +- .../debugging/qscriptdebuggerconsolecommand_p.h | 2 +- .../qscriptdebuggerconsolecommandgroupdata_p.h | 2 +- .../debugging/qscriptdebuggerconsolecommandjob_p.h | 2 +- .../qscriptdebuggerconsolecommandmanager_p.h | 2 +- .../qscriptdebuggerconsoleglobalobject_p.h | 2 +- .../debugging/qscriptdebuggerconsolewidget_p.h | 2 +- .../qscriptdebuggerconsolewidgetinterface_p.h | 2 +- src/scripttools/debugging/qscriptdebuggerevent_p.h | 2 +- .../debugging/qscriptdebuggerfrontend_p.h | 2 +- src/scripttools/debugging/qscriptdebuggerjob_p.h | 2 +- .../debugging/qscriptdebuggerlocalsmodel_p.h | 2 +- .../debugging/qscriptdebuggerlocalswidget_p.h | 2 +- .../qscriptdebuggerlocalswidgetinterface_p.h | 2 +- .../debugging/qscriptdebuggerresponse_p.h | 2 +- .../qscriptdebuggerscriptedconsolecommand.cpp | 2 +- .../qscriptdebuggerscriptedconsolecommand_p.h | 2 +- .../debugging/qscriptdebuggerscriptsmodel_p.h | 2 +- .../debugging/qscriptdebuggerscriptswidget_p.h | 2 +- .../qscriptdebuggerscriptswidgetinterface_p.h | 2 +- .../debugging/qscriptdebuggerstackmodel_p.h | 2 +- .../debugging/qscriptdebuggerstackwidget_p.h | 2 +- .../qscriptdebuggerstackwidgetinterface_p.h | 2 +- src/scripttools/debugging/qscriptdebuggervalue_p.h | 2 +- .../debugging/qscriptdebuggervalueproperty_p.h | 2 +- .../debugging/qscriptdebugoutputwidget_p.h | 2 +- .../qscriptdebugoutputwidgetinterface_p.h | 2 +- src/scripttools/debugging/qscriptenginedebugger.h | 2 +- .../debugging/qscriptenginedebuggerfrontend.cpp | 2 +- .../debugging/qscriptenginedebuggerfrontend_p.h | 2 +- .../debugging/qscripterrorlogwidget_p.h | 2 +- .../debugging/qscripterrorlogwidgetinterface_p.h | 2 +- src/scripttools/debugging/qscriptscriptdata_p.h | 2 +- .../debugging/qscriptstdmessagehandler_p.h | 2 +- src/scripttools/debugging/qscriptvalueproperty_p.h | 2 +- src/sql/kernel/qsqldriver.h | 2 +- src/sql/models/qsqlquerymodel.h | 2 +- src/sql/models/qsqlrelationaltablemodel.h | 2 +- src/sql/models/qsqltablemodel.h | 2 +- src/svg/qgraphicssvgitem.h | 2 +- src/svg/qsvggenerator.cpp | 2 +- src/svg/qsvggenerator.h | 2 +- src/svg/qsvgrenderer.h | 2 +- src/svg/qsvgwidget.h | 2 +- src/testlib/qplaintestlogger.cpp | 18 +- src/xml/sax/qxml.h | 2 +- src/xmlpatterns/api/qabstractmessagehandler.h | 2 +- src/xmlpatterns/api/qabstracturiresolver.h | 2 +- src/xmlpatterns/api/qsimplexmlnodemodel.h | 2 +- src/xmlpatterns/api/qxmlformatter.h | 2 +- src/xmlpatterns/api/qxmlresultitems.h | 2 +- src/xmlpatterns/api/qxmlserializer.h | 2 +- tests/auto/exceptionsafety_objects/oomsimulator.h | 158 ++++++++++--- .../tst_exceptionsafety_objects.cpp | 257 +++++++++++++++++---- tests/auto/qfiledialog/tst_qfiledialog.cpp | 2 +- .../auto/qfilesystemmodel/tst_qfilesystemmodel.cpp | 2 +- tests/auto/qglobal/tst_qglobal.cpp | 10 + .../qstandarditemmodel/tst_qstandarditemmodel.cpp | 2 +- .../qmainexceptions/tst_qmainexceptions.cpp | 156 ++++++++++++- .../src/components/formeditor/brushmanagerproxy.h | 2 +- .../src/components/formeditor/qtbrushmanager.h | 2 +- tools/designer/src/lib/shared/iconselector_p.h | 4 +- .../src/lib/shared/qtresourceeditordialog_p.h | 2 +- tools/designer/src/lib/shared/qtresourcemodel_p.h | 4 +- tools/designer/src/lib/shared/qtresourceview_p.h | 4 +- tools/designer/src/uitools/quiloader.h | 2 +- tools/shared/qtgradienteditor/qtcolorbutton.h | 2 +- tools/shared/qtgradienteditor/qtcolorline.h | 2 +- tools/shared/qtgradienteditor/qtgradientdialog.h | 2 +- tools/shared/qtgradienteditor/qtgradienteditor.h | 2 +- .../qtgradienteditor/qtgradientstopscontroller.h | 2 +- .../shared/qtgradienteditor/qtgradientstopsmodel.h | 2 +- .../qtgradienteditor/qtgradientstopswidget.h | 2 +- tools/shared/qtgradienteditor/qtgradientwidget.h | 2 +- .../qtpropertybrowser/qtbuttonpropertybrowser.h | 2 +- tools/shared/qtpropertybrowser/qteditorfactory.h | 30 +-- .../qtpropertybrowser/qtgroupboxpropertybrowser.h | 2 +- tools/shared/qtpropertybrowser/qtpropertybrowser.h | 4 +- tools/shared/qtpropertybrowser/qtpropertymanager.h | 44 ++-- .../qtpropertybrowser/qttreepropertybrowser.h | 2 +- tools/shared/qtpropertybrowser/qtvariantproperty.h | 4 +- tools/shared/qttoolbardialog/qttoolbardialog.cpp | 2 +- tools/shared/qttoolbardialog/qttoolbardialog.h | 4 +- 496 files changed, 2155 insertions(+), 1261 deletions(-) diff --git a/doc/src/snippets/code/src_corelib_tools_qscopedpointer.cpp b/doc/src/snippets/code/src_corelib_tools_qscopedpointer.cpp index 7de42b7..b625eb2 100644 --- a/doc/src/snippets/code/src_corelib_tools_qscopedpointer.cpp +++ b/doc/src/snippets/code/src_corelib_tools_qscopedpointer.cpp @@ -27,6 +27,7 @@ void myFunction(bool useSubClass) //! [1] void myFunction(bool useSubClass) { + // assuming that MyClass has a virtual destructor QScopedPointer p(useSubClass ? new MyClass() : new MySubClass); QScopedPointer device(handsOverOwnership()); @@ -80,3 +81,23 @@ private: // generate them. }; //! [4] + +//! [5] +// this QScopedPointer deletes its data using the delete[] operator: +QScopedPointer > arrayPointer(new int[42]); + +// this QScopedPointer frees its data using free(): +QScopedPointer > podPointer(reinterpret_cast(malloc(42))); + +// this struct calls "myCustomDeallocator" to delete the pointer +struct ScopedPointerCustomDeleter +{ + static inline void cleanup(MyCustomClass *pointer) + { + myCustomDeallocator(pointer); + } +}; + +// QScopedPointer using a custom deleter: +QScopedPointer customPointer(new MyCustomClass); +//! [5] diff --git a/doc/src/symbian-exceptionsafety.qdoc b/doc/src/symbian-exceptionsafety.qdoc index 56b28c9..df18031 100644 --- a/doc/src/symbian-exceptionsafety.qdoc +++ b/doc/src/symbian-exceptionsafety.qdoc @@ -80,11 +80,16 @@ Symbian leaves to standard C++ exceptions. The following help is provided: \list - \o \l qt_translateSymbianErrorToException() takes a Symbian + \o \l qt_throwIfError() takes a Symbian error code and throws an appropriate exception to represent it. This will do nothing if the error code is not in fact an error. The function is equivalent to Symbian's \c User::LeaveIfError. - \o \l QT_TRANSLATE_SYMBIAN_LEAVE_TO_EXCEPTION() takes a Symbian leaving + \o \l q_check_ptr() takes a pointer and throws a std::bad_alloc + exception if it is 0, otherwise the pointer is returned. This can be + used to check the success of a non-throwing allocation, eg from + \c malloc(). The function is equivalent to Symbian's \c + User::LeaveIfNull. + \o \l QT_TRAP_THROWING() takes a Symbian leaving code fragment f and runs it under a trap harness converting any resulting error into an exception. \o \c TRAP and \c TRAPD from the Symbian libraries can be used to convert @@ -94,16 +99,35 @@ \code HBufC* buf=0; // this will throw a std::bad_alloc because we've asked for too much memory - QT_TRANSLATE_SYMBIAN_LEAVE_TO_EXCEPTION(buf = HBufC::NewL(100000000)); + QT_TRAP_THROWING(buf = HBufC::NewL(100000000)); _LIT(KStr,"abc"); TInt pos = KStr().Locate('c'); // pos is a good value, >= 0, so no exception is thrown - qt_translateSymbianErrorToException(pos); + qt_throwIfError(pos); pos = KStr().Locate('d'); // pos == KErrNotFound, so this throws an exception - qt_translateSymbianErrorToException(pos); + qt_throwIfError(pos); + + // we are asking for a lot of memory, HBufC::New may return NULL, so check it + HBufC *buffer = q_check_ptr(HBufC::New(1000000)); + \endcode + + \section2 Be careful with new and CBase + + When writing Qt code, \c new will normally throw a \c std::bad_alloc if the + allocation fails. However this may not happen if the object being created + has its own \c {operator new}. For example, CBase and derived classes have + their own \c {operator new} which returns 0 and the \c {new(ELeave)} + overload for a leaving \c {operator new}, neither of which does what we want. + When using 2-phase construction of CBase derived objects, use \c new and + \l q_check_ptr(). + + \oldcode + CFbsBitmap* fbsBitmap = new(ELeave) CFbsBitmap; + \newcode + CFbsBitmap* fbsBitmap = q_check_ptr(new CFbsBitmap); \endcode \section1 Qt called from Symbian @@ -113,18 +137,18 @@ provided: \list - \o \l qt_translateExceptionToSymbianError() - + \o \l qt_exception2SymbianError() - this takes a standard exception and gives an appropriate Symbian error code. If no mapping is known for the exception type, \c KErrGeneral is returned. - \o \l qt_translateExceptionToSymbianErrorL() - + \o \l qt_exception2SymbianLeaveL() - this takes a standard exception and generates an appropriate Symbian leave. - \o \l QT_TRANSLATE_EXCEPTION_TO_SYMBIAN_ERROR() - this macro + \o \l QT_TRYCATCH_ERROR() - this macro takes the standard C++ code fragment \c f, catches any std::exceptions thrown from it, and sets err to the corresponding Symbian error code. err is set to \c KErrNone otherwise. - \o \l QT_TRANSLATE_EXCEPTION_TO_SYMBIAN_LEAVE() - this macro takes the + \o \l QT_TRYCATCH_LEAVING() - this macro takes the standard C++ code fragment \c f, catches any std::exceptions thrown from it, and throws a corresponding Symbian leave. \endlist @@ -133,7 +157,7 @@ TInt DoTickL() // called from an active object RunL, ie Symbian leaves expected { // without the translation to Symbian Leave, we get a USER:0 panic - QT_TRANSLATE_EXCEPTION_TO_SYMBIAN_LEAVE({ + QT_TRYCATCH_LEAVING({ int* x = new int[100000000]; // compiled as Qt code, will throw std::bad_alloc delete [] x; }); @@ -180,4 +204,38 @@ Now the exception generating functions are separated from the leaving functions. + + \section1 Advanced technique + When using Symbian APIs in Qt code, you may find that Symbian leaving + code and Qt exception throwing code are just too mixed up to have + them interoperate through barriers. In some circumstances you can allow + code to both leave and throw exceptions. But you must be aware of the + following issues: + + \list + \o Depending on whether a leave or exception is thrown, or a normal + exit happens, the cleanup order will vary. If the code leaves, + cleanup stack cleanup will happen first. On an exception however, + cleanup stack cleanup will happen last. + \o There must not be any destructor dependencies between different + code styles. That is, you must not have symbian objects using Qt + objects in their destructors, and vice versa. This is because the + cleanup order varies, and may result in objects being used after + they are deleted. + \o The cleanup stack must not refer to any stack based object. For + instance, in Symbian you may use \c CleanupClosePushL() to push + stack based R-classes onto the cleanup stack. However if the + stack has unwound due to an exception before the cleanup stack + cleanup happens, stack based objects will now be invalid. + Instead of using the cleanup stack, consider Symbian's new + \c LManagedHandle<> (or a custom cleanup object) to tie R-class + cleanup to the stack. + \o Mixed throwing code must be called within both a TRAP and a + try/catch harness. Standard exceptions must not propagate to + the TRAP and cleanup stack cleanup will only happen if a leave + is thrown, so the correct pattern is either \c {TRAPD(err, + QT_TRYCATCH_LEAVING( f ));} or \c {QT_TRAP_THROWING( + QT_TRYCATCH_LEAVING( f ));}, depending if you want an error + code or exception as a result. + \endlist */ diff --git a/examples/script/qsdbg/scriptdebugger.h b/examples/script/qsdbg/scriptdebugger.h index 2d4ba07..4752511 100644 --- a/examples/script/qsdbg/scriptdebugger.h +++ b/examples/script/qsdbg/scriptdebugger.h @@ -78,7 +78,7 @@ protected: ScriptDebuggerPrivate *d_ptr; private: - Q_DECLARE_PRIVATE(ScriptDebugger) + Q_DECLARE_SCOPED_PRIVATE(ScriptDebugger) Q_DISABLE_COPY(ScriptDebugger) }; diff --git a/mkspecs/common/symbian/qplatformdefs.h b/mkspecs/common/symbian/qplatformdefs.h index ebcd295..5f093b7 100644 --- a/mkspecs/common/symbian/qplatformdefs.h +++ b/mkspecs/common/symbian/qplatformdefs.h @@ -157,9 +157,9 @@ #endif -#if defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE >= 500) -#define QT_SNPRINTF ::snprintf -#define QT_VSNPRINTF ::vsnprintf +#if defined(__ISO_C_VISIBLE) && (__ISO_C_VISIBLE >= 1999) +#define QT_SNPRINTF ::snprintf +#define QT_VSNPRINTF ::vsnprintf #endif diff --git a/src/3rdparty/freetype/src/base/ftobjs.c b/src/3rdparty/freetype/src/base/ftobjs.c index 8208e2a..f90af67 100644 --- a/src/3rdparty/freetype/src/base/ftobjs.c +++ b/src/3rdparty/freetype/src/base/ftobjs.c @@ -244,7 +244,7 @@ FT_BASE_DEF( void ) ft_glyphslot_free_bitmap( FT_GlyphSlot slot ) { - if ( slot->internal->flags & FT_GLYPH_OWN_BITMAP ) + if ( slot->internal && slot->internal->flags & FT_GLYPH_OWN_BITMAP ) { FT_Memory memory = FT_FACE_MEMORY( slot->face ); @@ -337,14 +337,18 @@ /* free bitmap buffer if needed */ ft_glyphslot_free_bitmap( slot ); - /* free glyph loader */ - if ( FT_DRIVER_USES_OUTLINES( driver ) ) + /* slot->internal might be 0 in out-of-memory situations */ + if ( slot->internal ) { - FT_GlyphLoader_Done( slot->internal->loader ); - slot->internal->loader = 0; - } + /* free glyph loader */ + if ( FT_DRIVER_USES_OUTLINES( driver ) ) + { + FT_GlyphLoader_Done( slot->internal->loader ); + slot->internal->loader = 0; + } - FT_FREE( slot->internal ); + FT_FREE( slot->internal ); + } } @@ -1096,7 +1100,7 @@ if ( error ) { destroy_charmaps( face, memory ); - if ( clazz->done_face ) + if ( clazz->done_face && face ) clazz->done_face( face ); FT_FREE( internal ); FT_FREE( face ); diff --git a/src/3rdparty/freetype/src/base/ftstream.c b/src/3rdparty/freetype/src/base/ftstream.c index 569e46c..2082345 100644 --- a/src/3rdparty/freetype/src/base/ftstream.c +++ b/src/3rdparty/freetype/src/base/ftstream.c @@ -211,7 +211,7 @@ FT_Stream_ReleaseFrame( FT_Stream stream, FT_Byte** pbytes ) { - if ( stream->read ) + if ( stream && stream->read ) { FT_Memory memory = stream->memory; diff --git a/src/3rdparty/freetype/src/truetype/ttinterp.c b/src/3rdparty/freetype/src/truetype/ttinterp.c index f9c3656..143ca65 100644 --- a/src/3rdparty/freetype/src/truetype/ttinterp.c +++ b/src/3rdparty/freetype/src/truetype/ttinterp.c @@ -799,8 +799,6 @@ return driver->context; Fail: - FT_FREE( exec ); - return 0; } diff --git a/src/3rdparty/freetype/src/truetype/ttpload.c b/src/3rdparty/freetype/src/truetype/ttpload.c index 9d3381b..38674a1 100644 --- a/src/3rdparty/freetype/src/truetype/ttpload.c +++ b/src/3rdparty/freetype/src/truetype/ttpload.c @@ -483,10 +483,10 @@ tt_face_free_hdmx( TT_Face face ) { FT_Stream stream = face->root.stream; - FT_Memory memory = stream->memory; - + FT_Memory memory = stream ? stream->memory : NULL; - FT_FREE( face->hdmx_record_sizes ); + if ( face->hdmx_record_sizes ) + FT_FREE( face->hdmx_record_sizes ); FT_FRAME_RELEASE( face->hdmx_table ); } diff --git a/src/3rdparty/harfbuzz/src/harfbuzz-shaper.cpp b/src/3rdparty/harfbuzz/src/harfbuzz-shaper.cpp index 2e3ef38..f92bb55 100644 --- a/src/3rdparty/harfbuzz/src/harfbuzz-shaper.cpp +++ b/src/3rdparty/harfbuzz/src/harfbuzz-shaper.cpp @@ -969,6 +969,7 @@ HB_Face HB_NewFace(void *font, HB_GetFontTableFunc tableFunc) face->tmpAttributes = 0; face->tmpLogClusters = 0; face->glyphs_substituted = false; + face->buffer = 0; HB_Error error; HB_Stream stream; @@ -1004,7 +1005,10 @@ HB_Face HB_NewFace(void *font, HB_GetFontTableFunc tableFunc) for (unsigned int i = 0; i < HB_ScriptCount; ++i) face->supported_scripts[i] = checkScript(face, i); - hb_buffer_new(&face->buffer); + if (hb_buffer_new(&face->buffer) != HB_Err_Ok) { + HB_FreeFace(face); + return 0; + } return face; } @@ -1124,6 +1128,8 @@ HB_Bool HB_SelectScript(HB_ShaperItem *shaper_item, const HB_OpenTypeFeature *fe HB_Bool HB_OpenTypeShape(HB_ShaperItem *item, const hb_uint32 *properties) { + HB_GlyphAttributes *tmpAttributes; + unsigned int *tmpLogClusters; HB_Face face = item->face; @@ -1131,8 +1137,16 @@ HB_Bool HB_OpenTypeShape(HB_ShaperItem *item, const hb_uint32 *properties) hb_buffer_clear(face->buffer); - face->tmpAttributes = (HB_GlyphAttributes *) realloc(face->tmpAttributes, face->length*sizeof(HB_GlyphAttributes)); - face->tmpLogClusters = (unsigned int *) realloc(face->tmpLogClusters, face->length*sizeof(unsigned int)); + tmpAttributes = (HB_GlyphAttributes *) realloc(face->tmpAttributes, face->length*sizeof(HB_GlyphAttributes)); + if (!tmpAttributes) + return false; + face->tmpAttributes = tmpAttributes; + + tmpLogClusters = (unsigned int *) realloc(face->tmpLogClusters, face->length*sizeof(unsigned int)); + if (!tmpLogClusters) + return false; + face->tmpLogClusters = tmpLogClusters; + for (int i = 0; i < face->length; ++i) { hb_buffer_add_glyph(face->buffer, item->glyphs[i], properties ? properties[i] : 0, i); face->tmpAttributes[i] = item->attributes[i]; diff --git a/src/3rdparty/phonon/phonon/abstractmediastream.h b/src/3rdparty/phonon/phonon/abstractmediastream.h index c4cde85..be45861 100644 --- a/src/3rdparty/phonon/phonon/abstractmediastream.h +++ b/src/3rdparty/phonon/phonon/abstractmediastream.h @@ -103,7 +103,7 @@ class AbstractMediaStreamPrivate; class PHONON_EXPORT AbstractMediaStream : public QObject { Q_OBJECT - Q_DECLARE_PRIVATE(AbstractMediaStream) + Q_DECLARE_SCOPED_PRIVATE(AbstractMediaStream) friend class MediaObject; friend class MediaObjectPrivate; friend class StreamInterface; diff --git a/src/3rdparty/phonon/phonon/iodevicestream_p.h b/src/3rdparty/phonon/phonon/iodevicestream_p.h index 5eb90bc..527ff17 100644 --- a/src/3rdparty/phonon/phonon/iodevicestream_p.h +++ b/src/3rdparty/phonon/phonon/iodevicestream_p.h @@ -39,7 +39,7 @@ class IODeviceStreamPrivate; class IODeviceStream : public AbstractMediaStream { Q_OBJECT - Q_DECLARE_PRIVATE(IODeviceStream) + Q_DECLARE_SCOPED_PRIVATE(IODeviceStream) public: explicit IODeviceStream(QIODevice *ioDevice, QObject *parent = 0); ~IODeviceStream(); diff --git a/src/corelib/animation/qabstractanimation.h b/src/corelib/animation/qabstractanimation.h index e4b1fcc..8da0935 100644 --- a/src/corelib/animation/qabstractanimation.h +++ b/src/corelib/animation/qabstractanimation.h @@ -125,7 +125,7 @@ protected: private: Q_DISABLE_COPY(QAbstractAnimation) - Q_DECLARE_PRIVATE(QAbstractAnimation) + Q_DECLARE_SCOPED_PRIVATE(QAbstractAnimation) }; #endif //QT_NO_ANIMATION diff --git a/src/corelib/animation/qanimationgroup.h b/src/corelib/animation/qanimationgroup.h index 93c6fb1..5b07524 100644 --- a/src/corelib/animation/qanimationgroup.h +++ b/src/corelib/animation/qanimationgroup.h @@ -76,7 +76,7 @@ protected: private: Q_DISABLE_COPY(QAnimationGroup) - Q_DECLARE_PRIVATE(QAnimationGroup) + Q_DECLARE_SCOPED_PRIVATE(QAnimationGroup) }; #endif //QT_NO_ANIMATION diff --git a/src/corelib/animation/qparallelanimationgroup.h b/src/corelib/animation/qparallelanimationgroup.h index 07808f1..8422102 100644 --- a/src/corelib/animation/qparallelanimationgroup.h +++ b/src/corelib/animation/qparallelanimationgroup.h @@ -73,7 +73,7 @@ protected: private: Q_DISABLE_COPY(QParallelAnimationGroup) - Q_DECLARE_PRIVATE(QParallelAnimationGroup) + Q_DECLARE_SCOPED_PRIVATE(QParallelAnimationGroup) Q_PRIVATE_SLOT(d_func(), void _q_uncontrolledAnimationFinished()) }; diff --git a/src/corelib/animation/qpauseanimation.h b/src/corelib/animation/qpauseanimation.h index 6907d0a..b84e940 100644 --- a/src/corelib/animation/qpauseanimation.h +++ b/src/corelib/animation/qpauseanimation.h @@ -72,7 +72,7 @@ protected: private: Q_DISABLE_COPY(QPauseAnimation) - Q_DECLARE_PRIVATE(QPauseAnimation) + Q_DECLARE_SCOPED_PRIVATE(QPauseAnimation) }; #endif //QT_NO_ANIMATION diff --git a/src/corelib/animation/qpropertyanimation.h b/src/corelib/animation/qpropertyanimation.h index e07444c..6631f67 100644 --- a/src/corelib/animation/qpropertyanimation.h +++ b/src/corelib/animation/qpropertyanimation.h @@ -78,7 +78,7 @@ protected: private: Q_PRIVATE_SLOT(d_func(), void _q_targetDestroyed()) Q_DISABLE_COPY(QPropertyAnimation) - Q_DECLARE_PRIVATE(QPropertyAnimation) + Q_DECLARE_SCOPED_PRIVATE(QPropertyAnimation) }; #endif //QT_NO_ANIMATION diff --git a/src/corelib/animation/qsequentialanimationgroup.h b/src/corelib/animation/qsequentialanimationgroup.h index 5d43356..81a7ff5 100644 --- a/src/corelib/animation/qsequentialanimationgroup.h +++ b/src/corelib/animation/qsequentialanimationgroup.h @@ -83,7 +83,7 @@ protected: private: Q_DISABLE_COPY(QSequentialAnimationGroup) - Q_DECLARE_PRIVATE(QSequentialAnimationGroup) + Q_DECLARE_SCOPED_PRIVATE(QSequentialAnimationGroup) Q_PRIVATE_SLOT(d_func(), void _q_uncontrolledAnimationFinished()) }; diff --git a/src/corelib/animation/qvariantanimation.h b/src/corelib/animation/qvariantanimation.h index b2d52d5..0afe80f 100644 --- a/src/corelib/animation/qvariantanimation.h +++ b/src/corelib/animation/qvariantanimation.h @@ -113,7 +113,7 @@ private: static void registerInterpolator(Interpolator func, int interpolationType); Q_DISABLE_COPY(QVariantAnimation) - Q_DECLARE_PRIVATE(QVariantAnimation) + Q_DECLARE_SCOPED_PRIVATE(QVariantAnimation) }; template diff --git a/src/corelib/arch/symbian/qatomic_symbian.cpp b/src/corelib/arch/symbian/qatomic_symbian.cpp index 170b737..9bec0f5 100644 --- a/src/corelib/arch/symbian/qatomic_symbian.cpp +++ b/src/corelib/arch/symbian/qatomic_symbian.cpp @@ -42,6 +42,37 @@ #include #include +#include + +// Heap and handle info printer. This code is placed here as it happens to make it the very last static to be destroyed in a Qt app. +// This way we can report on heap cells and handles that are really not owned by anything which still exists. +// This information can be used to detect whether memory leaks are happening, particularly if these numbers grow as the app is used more. +struct SPrintExitInfo +{ + SPrintExitInfo() + { + RThread().HandleCount(initProcessHandleCount,initThreadHandleCount); + initCells = User::CountAllocCells(); + } + ~SPrintExitInfo() + { + RProcess myProc; + TFullName fullName = myProc.FileName(); + TInt cells = User::CountAllocCells(); + TInt processHandleCount=0; + TInt threadHandleCount=0; + RThread().HandleCount(processHandleCount,threadHandleCount); + RDebug::Print(_L("%S exiting with %d allocated cells, %d handles"), + &fullName, + cells - initCells, + (processHandleCount + threadHandleCount) - (initProcessHandleCount + initThreadHandleCount)); + } + TInt initCells; + TInt initProcessHandleCount; + TInt initThreadHandleCount; +} printExitInfo; + + #if defined(Q_CC_RVCT) #include "../arm/qatomic_arm.cpp" diff --git a/src/corelib/concurrent/qfuturewatcher.h b/src/corelib/concurrent/qfuturewatcher.h index 04d5680..948ecca 100644 --- a/src/corelib/concurrent/qfuturewatcher.h +++ b/src/corelib/concurrent/qfuturewatcher.h @@ -59,7 +59,7 @@ class QFutureWatcherBasePrivate; class Q_CORE_EXPORT QFutureWatcherBase : public QObject { Q_OBJECT - Q_DECLARE_PRIVATE(QFutureWatcherBase) + Q_DECLARE_SCOPED_PRIVATE(QFutureWatcherBase) public: QFutureWatcherBase(QObject *parent = 0); diff --git a/src/corelib/concurrent/qthreadpool.h b/src/corelib/concurrent/qthreadpool.h index 0ddefd1..dddf962 100644 --- a/src/corelib/concurrent/qthreadpool.h +++ b/src/corelib/concurrent/qthreadpool.h @@ -58,7 +58,7 @@ class QThreadPoolPrivate; class Q_CORE_EXPORT QThreadPool : public QObject { Q_OBJECT - Q_DECLARE_PRIVATE(QThreadPool) + Q_DECLARE_SCOPED_PRIVATE(QThreadPool) Q_PROPERTY(int expiryTimeout READ expiryTimeout WRITE setExpiryTimeout) Q_PROPERTY(int maxThreadCount READ maxThreadCount WRITE setMaxThreadCount) Q_PROPERTY(int activeThreadCount READ activeThreadCount) diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp index 76ffb6a..818e555 100644 --- a/src/corelib/global/qglobal.cpp +++ b/src/corelib/global/qglobal.cpp @@ -1910,6 +1910,15 @@ QSysInfo::SymVersion QSysInfo::symbianVersion() */ /*! + T *q_check_ptr(T *pointer) + \relates + + Users Q_CHECK_PTR on \a pointer, then returns \a pointer. + + This can be used as an inline version of Q_CHECK_PTR. +*/ + +/*! \macro const char* Q_FUNC_INFO() \relates @@ -2162,7 +2171,7 @@ void qt_message_output(QtMsgType msgType, const char *buf) _LIT(format, "[Qt Message] %S"); const int maxBlockSize = 256 - ((const TDesC &)format).Length(); const TPtrC8 ptr(reinterpret_cast(buf)); - HBufC* hbuffer = HBufC::NewL(qMin(maxBlockSize, ptr.Length())); + HBufC* hbuffer = q_check_ptr(HBufC::New(qMin(maxBlockSize, ptr.Length()))); for (int i = 0; i < ptr.Length(); i += hbuffer->Length()) { hbuffer->Des().Copy(ptr.Mid(i, qMin(maxBlockSize, ptr.Length()-i))); RDebug::Print(format, hbuffer); @@ -2464,7 +2473,11 @@ bool qputenv(const char *varName, const QByteArray& value) QByteArray buffer(varName); buffer += '='; buffer += value; - return putenv(qstrdup(buffer.constData())) == 0; + char* envVar = qstrdup(buffer.constData()); + int result = putenv(envVar); + if (result != 0) // error. we have to delete the string. + delete[] envVar; + return result == 0; #endif } @@ -3231,7 +3244,7 @@ bool QInternal::callFunction(InternalFunction func, void **args) #include -/*! \macro QT_TRANSLATE_SYMBIAN_LEAVE_TO_EXCEPTION(function) +/*! \macro QT_TRAP_THROWING(function) \relates \ingroup qts60 @@ -3251,14 +3264,14 @@ bool QInternal::callFunction(InternalFunction func, void **args) CAknTitlePane* titlePane = S60->titlePane(); if (titlePane) { TPtrC captionPtr(qt_QString2TPtrC(caption)); - QT_TRANSLATE_SYMBIAN_LEAVE_TO_EXCEPTION(titlePane->SetTextL(captionPtr)); + QT_TRAP_THROWING(titlePane->SetTextL(captionPtr)); } \endcode - \sa QT_TRANSLATE_EXCEPTION_TO_SYMBIAN_ERROR(), QT_TRANSLATE_EXCEPTION_TO_SYMBIAN_LEAVE() + \sa QT_TRYCATCH_ERROR(), QT_TRYCATCH_LEAVING() */ -/*! \macro QT_TRANSLATE_EXCEPTION_TO_SYMBIAN_ERROR(error, function) +/*! \macro QT_TRYCATCH_ERROR(error, function) \relates \ingroup qts60 @@ -3278,7 +3291,7 @@ bool QInternal::callFunction(InternalFunction func, void **args) { TPtrC name; TInt err; - QT_TRANSLATE_EXCEPTION_TO_SYMBIAN_ERROR(err, name.Set(qt_QString2TPtrC(serverName))); + QT_TRYCATCH_ERROR(err, name.Set(qt_QString2TPtrC(serverName))); if (err != KErrNone) return err; return iServer.Connect(name); @@ -3286,10 +3299,10 @@ bool QInternal::callFunction(InternalFunction func, void **args) \endcode } - \sa QT_TRANSLATE_EXCEPTION_TO_SYMBIAN_LEAVE(), QT_TRANSLATE_SYMBIAN_LEAVE_TO_EXCEPTION() + \sa QT_TRYCATCH_LEAVING(), QT_TRAP_THROWING() */ -/*! \macro QT_TRANSLATE_EXCEPTION_TO_SYMBIAN_LEAVE(function) +/*! \macro QT_TRYCATCH_LEAVING(function) \relates \ingroup qts60 @@ -3309,11 +3322,11 @@ bool QInternal::callFunction(InternalFunction func, void **args) { iStatus = KRequestPending; SetActive(); - QT_TRANSLATE_EXCEPTION_TO_SYMBIAN_LEAVE(m_dispatcher->wakeUpWasCalled()); + QT_TRYCATCH_LEAVING(m_dispatcher->wakeUpWasCalled()); } \endcode - \sa QT_TRANSLATE_SYMBIAN_LEAVE_TO_EXCEPTION(), QT_TRANSLATE_EXCEPTION_TO_SYMBIAN_ERROR() + \sa QT_TRAP_THROWING(), QT_TRYCATCH_ERROR() */ #include @@ -3336,15 +3349,21 @@ public: \warning This function is only available on Symbian. - \sa qt_translateExceptionToSymbianErrorL(), qt_translateExceptionToSymbianError() + \sa qt_exception2SymbianLeaveL(), qt_exception2SymbianError() */ -void qt_translateSymbianErrorToException(int error) +void qt_throwIfError(int error) { if (error >= KErrNone) return; // do nothing - not an exception switch (error) { case KErrNoMemory: throw std::bad_alloc(); + case KErrArgument: + throw std::invalid_argument("from Symbian error"); + case KErrOverflow: + throw std::overflow_error("from Symbian error"); + case KErrUnderflow: + throw std::underflow_error("from Symbian error"); default: throw QSymbianLeaveException(error); } @@ -3357,11 +3376,11 @@ void qt_translateSymbianErrorToException(int error) \warning This function is only available on Symbian. - \sa qt_translateSymbianErrorToException(), qt_translateExceptionToSymbianError() + \sa qt_throwIfError(), qt_exception2SymbianError() */ -void qt_translateExceptionToSymbianErrorL(const std::exception& aThrow) +void qt_exception2SymbianLeaveL(const std::exception& aThrow) { - User::Leave(qt_translateExceptionToSymbianError(aThrow)); + User::Leave(qt_exception2SymbianError(aThrow)); } /*! \relates @@ -3371,9 +3390,9 @@ void qt_translateExceptionToSymbianErrorL(const std::exception& aThrow) \warning This function is only available on Symbian. - \sa qt_translateSymbianErrorToException(), qt_translateExceptionToSymbianErrorL() + \sa qt_throwIfError(), qt_exception2SymbianLeaveL() */ -int qt_translateExceptionToSymbianError(const std::exception& aThrow) +int qt_exception2SymbianError(const std::exception& aThrow) { const std::type_info& atype = typeid(aThrow); int err = KErrGeneral; @@ -3382,19 +3401,22 @@ int qt_translateExceptionToSymbianError(const std::exception& aThrow) err = KErrNoMemory; else if(atype == typeid(QSymbianLeaveException)) err = static_cast(aThrow).error; - else if(atype == typeid(std::invalid_argument)) - err = KErrArgument; - else if(atype == typeid(std::out_of_range)) - // std::out_of_range is of type logic_error which by definition means that it is - // "presumably detectable before the program executes". - // std::out_of_range is used to report an argument is not within the expected range. - // The description of KErrArgument says an argument is out of range. Hence the mapping. - err = KErrArgument; - else if(atype == typeid(std::overflow_error)) - err = KErrOverflow; - else if(atype == typeid(std::underflow_error)) - err = KErrUnderflow; - + else { + if(atype == typeid(std::invalid_argument)) + err = KErrArgument; + else if(atype == typeid(std::out_of_range)) + // std::out_of_range is of type logic_error which by definition means that it is + // "presumably detectable before the program executes". + // std::out_of_range is used to report an argument is not within the expected range. + // The description of KErrArgument says an argument is out of range. Hence the mapping. + err = KErrArgument; + else if(atype == typeid(std::overflow_error)) + err = KErrOverflow; + else if(atype == typeid(std::underflow_error)) + err = KErrUnderflow; + qWarning("translation from std exception \"%s\" to %d", aThrow.what(), err); + } + return err; } #endif diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index e6508a8..257e3db 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -1662,6 +1662,9 @@ Q_CORE_EXPORT void qBadAlloc(); # define Q_CHECK_PTR(p) do { if (!(p)) qBadAlloc(); } while (0) #endif +template +inline T *q_check_ptr(T *p) { Q_CHECK_PTR(p); return p; } + #if (defined(Q_CC_GNU) && !defined(Q_OS_SOLARIS)) || defined(Q_CC_HPACC) # define Q_FUNC_INFO __PRETTY_FUNCTION__ #elif defined(_MSC_VER) @@ -2283,6 +2286,11 @@ inline const QForeachContainer *qForeachContainer(const QForeachContainerBase #endif #define Q_DECLARE_PRIVATE(Class) \ + inline Class##Private* d_func() { return reinterpret_cast(d_ptr); } \ + inline const Class##Private* d_func() const { return reinterpret_cast(d_ptr); } \ + friend class Class##Private; + +#define Q_DECLARE_SCOPED_PRIVATE(Class) \ inline Class##Private* d_func() { return reinterpret_cast(d_ptr.data()); } \ inline const Class##Private* d_func() const { return reinterpret_cast(d_ptr.data()); } \ friend class Class##Private; @@ -2378,33 +2386,32 @@ QT_END_NAMESPACE namespace std { class exception; } #endif QT_BEGIN_NAMESPACE -Q_CORE_EXPORT void qt_translateSymbianErrorToException(int error); -Q_CORE_EXPORT void qt_translateExceptionToSymbianErrorL(const std::exception& ex); -Q_CORE_EXPORT int qt_translateExceptionToSymbianError(const std::exception& ex); +Q_CORE_EXPORT void qt_throwIfError(int error); +Q_CORE_EXPORT void qt_exception2SymbianLeaveL(const std::exception& ex); +Q_CORE_EXPORT int qt_exception2SymbianError(const std::exception& ex); -#define QT_TRANSLATE_SYMBIAN_LEAVE_TO_EXCEPTION(f) \ +#define QT_TRAP_THROWING(_f) \ { \ - TInt error; \ - TRAP(error, f); \ - if (error) \ - qt_translateSymbianErrorToException(error); \ + TInt ____error; \ + TRAP(____error, _f); \ + qt_throwIfError(____error); \ } -#define QT_TRANSLATE_EXCEPTION_TO_SYMBIAN_ERROR(err, f) \ +#define QT_TRYCATCH_ERROR(_err, _f) \ { \ - err = KErrNone; \ + _err = KErrNone; \ try { \ - f; \ - } catch (const std::exception &ex) { \ - err = qt_translateExceptionToSymbianError(ex); \ + _f; \ + } catch (const std::exception &____ex) { \ + _err = qt_exception2SymbianError(____ex); \ } \ } -#define QT_TRANSLATE_EXCEPTION_TO_SYMBIAN_LEAVE(f) \ +#define QT_TRYCATCH_LEAVING(_f) \ { \ - TInt err; \ - QT_TRANSLATE_EXCEPTION_TO_SYMBIAN_ERROR(err, f) \ - User::LeaveIfError(err); \ + TInt ____err; \ + QT_TRYCATCH_ERROR(____err, _f) \ + User::LeaveIfError(____err); \ } #endif diff --git a/src/corelib/io/qabstractfileengine.h b/src/corelib/io/qabstractfileengine.h index 54eb6de..07c92d2 100644 --- a/src/corelib/io/qabstractfileengine.h +++ b/src/corelib/io/qabstractfileengine.h @@ -196,7 +196,7 @@ protected: QScopedPointer d_ptr; private: - Q_DECLARE_PRIVATE(QAbstractFileEngine) + Q_DECLARE_SCOPED_PRIVATE(QAbstractFileEngine) Q_DISABLE_COPY(QAbstractFileEngine) }; diff --git a/src/corelib/io/qbuffer.h b/src/corelib/io/qbuffer.h index e078d05..ce5f605 100644 --- a/src/corelib/io/qbuffer.h +++ b/src/corelib/io/qbuffer.h @@ -96,7 +96,7 @@ protected: qint64 writeData(const char *data, qint64 len); private: - Q_DECLARE_PRIVATE(QBuffer) + Q_DECLARE_SCOPED_PRIVATE(QBuffer) Q_DISABLE_COPY(QBuffer) Q_PRIVATE_SLOT(d_func(), void _q_emitSignals()) diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp index edbe5f0..9787566 100644 --- a/src/corelib/io/qdir.cpp +++ b/src/corelib/io/qdir.cpp @@ -86,7 +86,7 @@ class QDirPrivate QDir *q_ptr; Q_DECLARE_PUBLIC(QDir) - friend class QScopedPointer; + friend class QScopedPointerDeleter; protected: QDirPrivate(QDir*, const QDir *copy=0); ~QDirPrivate(); @@ -288,10 +288,10 @@ inline void QDirPrivate::sortFileList(QDir::SortFlags sort, QFileInfoList &l, names->append(l.at(i).fileName()); } } else { - QDirSortItem *si = new QDirSortItem[n]; + QScopedArrayPointer si(new QDirSortItem[n]); for (int i = 0; i < n; ++i) si[i].item = l.at(i); - qSort(si, si+n, QDirSortItemComparator(sort)); + qSort(si.data(), si.data()+n, QDirSortItemComparator(sort)); // put them back in the list(s) if(infos) { for (int i = 0; i < n; ++i) @@ -301,7 +301,6 @@ inline void QDirPrivate::sortFileList(QDir::SortFlags sort, QFileInfoList &l, for (int i = 0; i < n; ++i) names->append(si[i].item.fileName()); } - delete [] si; } } } @@ -334,8 +333,9 @@ void QDirPrivate::detach(bool createFileEngine) { qAtomicDetach(data); if (createFileEngine) { + QAbstractFileEngine *newFileEngine = QAbstractFileEngine::create(data->path); delete data->fileEngine; - data->fileEngine = QAbstractFileEngine::create(data->path); + data->fileEngine = newFileEngine; } } diff --git a/src/corelib/io/qdir.h b/src/corelib/io/qdir.h index f54fbdc..5ef4356 100644 --- a/src/corelib/io/qdir.h +++ b/src/corelib/io/qdir.h @@ -60,7 +60,7 @@ class Q_CORE_EXPORT QDir protected: QScopedPointer d_ptr; private: - Q_DECLARE_PRIVATE(QDir) + Q_DECLARE_SCOPED_PRIVATE(QDir) public: enum Filter { Dirs = 0x001, Files = 0x002, diff --git a/src/corelib/io/qfile.h b/src/corelib/io/qfile.h index f448609..24ce617 100644 --- a/src/corelib/io/qfile.h +++ b/src/corelib/io/qfile.h @@ -64,7 +64,7 @@ class Q_CORE_EXPORT QFile : public QIODevice #ifndef QT_NO_QOBJECT Q_OBJECT #endif - Q_DECLARE_PRIVATE(QFile) + Q_DECLARE_SCOPED_PRIVATE(QFile) public: diff --git a/src/corelib/io/qfileinfo.h b/src/corelib/io/qfileinfo.h index 5295b16..c73823a 100644 --- a/src/corelib/io/qfileinfo.h +++ b/src/corelib/io/qfileinfo.h @@ -168,7 +168,7 @@ public: protected: QScopedPointer d_ptr; private: - Q_DECLARE_PRIVATE(QFileInfo) + Q_DECLARE_SCOPED_PRIVATE(QFileInfo) }; Q_DECLARE_TYPEINFO(QFileInfo, Q_MOVABLE_TYPE); diff --git a/src/corelib/io/qfilesystemwatcher.h b/src/corelib/io/qfilesystemwatcher.h index 60458e5..76a6c60 100644 --- a/src/corelib/io/qfilesystemwatcher.h +++ b/src/corelib/io/qfilesystemwatcher.h @@ -57,7 +57,7 @@ class QFileSystemWatcherPrivate; class Q_CORE_EXPORT QFileSystemWatcher : public QObject { Q_OBJECT - Q_DECLARE_PRIVATE(QFileSystemWatcher) + Q_DECLARE_SCOPED_PRIVATE(QFileSystemWatcher) public: QFileSystemWatcher(QObject *parent = 0); diff --git a/src/corelib/io/qfilesystemwatcher_symbian.cpp b/src/corelib/io/qfilesystemwatcher_symbian.cpp index aeb19db..c8c1d82 100644 --- a/src/corelib/io/qfilesystemwatcher_symbian.cpp +++ b/src/corelib/io/qfilesystemwatcher_symbian.cpp @@ -80,7 +80,7 @@ void CNotifyChangeEvent::RunL() if (iStatus.Int() == KErrNone){ fsSession.NotifyChange(ENotifyAll, iStatus, watchedPath); SetActive(); - QT_TRANSLATE_EXCEPTION_TO_SYMBIAN_LEAVE(engine->emitPathChanged(this)); + QT_TRYCATCH_LEAVING(engine->emitPathChanged(this)); } else { qWarning("CNotifyChangeEvent::RunL() - Failed to order change notifications: %d", iStatus.Int()); } diff --git a/src/corelib/io/qfsfileengine.h b/src/corelib/io/qfsfileengine.h index feca09b..0fd87a4 100644 --- a/src/corelib/io/qfsfileengine.h +++ b/src/corelib/io/qfsfileengine.h @@ -56,7 +56,7 @@ class QFSFileEnginePrivate; class Q_CORE_EXPORT QFSFileEngine : public QAbstractFileEngine { - Q_DECLARE_PRIVATE(QFSFileEngine) + Q_DECLARE_SCOPED_PRIVATE(QFSFileEngine) public: QFSFileEngine(); explicit QFSFileEngine(const QString &file); diff --git a/src/corelib/io/qfsfileengine_unix.cpp b/src/corelib/io/qfsfileengine_unix.cpp index 84394fe..2421282 100644 --- a/src/corelib/io/qfsfileengine_unix.cpp +++ b/src/corelib/io/qfsfileengine_unix.cpp @@ -1003,11 +1003,7 @@ QString QFSFileEngine::fileName(FileName file) const int size = PATH_CHUNK_SIZE; while (1) { - s = (char *) ::realloc(s, size); - if (s == 0) { - len = -1; - break; - } + s = q_check_ptr((char *) ::realloc(s, size)); len = ::readlink(d->nativeFilePath.constData(), s, size); if (len < 0) { ::free(s); diff --git a/src/corelib/io/qiodevice.h b/src/corelib/io/qiodevice.h index 866fa72..d8237a7 100644 --- a/src/corelib/io/qiodevice.h +++ b/src/corelib/io/qiodevice.h @@ -165,7 +165,7 @@ protected: #endif private: - Q_DECLARE_PRIVATE(QIODevice) + Q_DECLARE_SCOPED_PRIVATE(QIODevice) Q_DISABLE_COPY(QIODevice) #ifdef QT3_SUPPORT diff --git a/src/corelib/io/qprocess.h b/src/corelib/io/qprocess.h index bff5f7e..a4025a1 100644 --- a/src/corelib/io/qprocess.h +++ b/src/corelib/io/qprocess.h @@ -191,7 +191,7 @@ protected: qint64 writeData(const char *data, qint64 len); private: - Q_DECLARE_PRIVATE(QProcess) + Q_DECLARE_SCOPED_PRIVATE(QProcess) Q_DISABLE_COPY(QProcess) Q_PRIVATE_SLOT(d_func(), bool _q_canReadStandardOutput()) diff --git a/src/corelib/io/qresource.h b/src/corelib/io/qresource.h index 0bf9660..49dacea 100644 --- a/src/corelib/io/qresource.h +++ b/src/corelib/io/qresource.h @@ -94,7 +94,7 @@ protected: QScopedPointer d_ptr; private: - Q_DECLARE_PRIVATE(QResource) + Q_DECLARE_SCOPED_PRIVATE(QResource) }; QT_END_NAMESPACE diff --git a/src/corelib/io/qresource_p.h b/src/corelib/io/qresource_p.h index f58f9a2..452d8e1 100644 --- a/src/corelib/io/qresource_p.h +++ b/src/corelib/io/qresource_p.h @@ -61,7 +61,7 @@ class QResourceFileEnginePrivate; class QResourceFileEngine : public QAbstractFileEngine { private: - Q_DECLARE_PRIVATE(QResourceFileEngine) + Q_DECLARE_SCOPED_PRIVATE(QResourceFileEngine) public: explicit QResourceFileEngine(const QString &path); ~QResourceFileEngine(); diff --git a/src/corelib/io/qsettings.cpp b/src/corelib/io/qsettings.cpp index b324441..1650526 100644 --- a/src/corelib/io/qsettings.cpp +++ b/src/corelib/io/qsettings.cpp @@ -217,6 +217,11 @@ QConfFile::QConfFile(const QString &fileName, bool _userPerms) usedHashFunc()->insert(name, this); } +QConfFile::~QConfFile() +{ + usedHashFunc()->remove(name); +} + ParsedSettingsMap QConfFile::mergedKeyMap() const { ParsedSettingsMap result = originalKeys; @@ -263,7 +268,7 @@ QConfFile *QConfFile::fromName(const QString &fileName, bool _userPerms) ConfFileHash *usedHash = usedHashFunc(); ConfFileCache *unusedCache = unusedCacheFunc(); - QConfFile *confFile; + QConfFile *confFile = 0; QMutexLocker locker(globalMutex()); if (!(confFile = usedHash->value(absPath))) { @@ -1232,12 +1237,11 @@ QConfFileSettingsPrivate::~QConfFileSettingsPrivate() for (int i = 0; i < NumConfFiles; ++i) { if (confFiles[i] && !confFiles[i]->ref.deref()) { - if (usedHash) - usedHash->remove(confFiles[i]->name); - if (confFiles[i]->size == 0) { delete confFiles[i].take(); } else if (unusedCache) { + if (usedHash) + usedHash->remove(confFiles[i]->name); QT_TRY { // compute a better size? unusedCache->insert(confFiles[i]->name, confFiles[i].data(), diff --git a/src/corelib/io/qsettings.h b/src/corelib/io/qsettings.h index 0d382b66..a082d6a 100644 --- a/src/corelib/io/qsettings.h +++ b/src/corelib/io/qsettings.h @@ -80,7 +80,7 @@ class Q_CORE_EXPORT QSettings #else QScopedPointer d_ptr; #endif - Q_DECLARE_PRIVATE(QSettings) + Q_DECLARE_SCOPED_PRIVATE(QSettings) public: enum Status { diff --git a/src/corelib/io/qsettings_p.h b/src/corelib/io/qsettings_p.h index a49a063..883e2fe 100644 --- a/src/corelib/io/qsettings_p.h +++ b/src/corelib/io/qsettings_p.h @@ -149,6 +149,8 @@ inline QString QSettingsGroup::toString() const class Q_AUTOTEST_EXPORT QConfFile { public: + ~QConfFile(); + ParsedSettingsMap mergedKeyMap() const; bool isWritable() const; diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp index 2d5bea6..f7120e1 100644 --- a/src/corelib/io/qtemporaryfile.cpp +++ b/src/corelib/io/qtemporaryfile.cpp @@ -289,7 +289,7 @@ static int qt_mkstemps(char *path, int slen) //************* QTemporaryFileEngine class QTemporaryFileEngine : public QFSFileEngine { - Q_DECLARE_PRIVATE(QFSFileEngine) + Q_DECLARE_SCOPED_PRIVATE(QFSFileEngine) public: QTemporaryFileEngine(const QString &file, bool fileIsTemplate = true) : QFSFileEngine(file), filePathIsTemplate(fileIsTemplate) diff --git a/src/corelib/io/qtemporaryfile.h b/src/corelib/io/qtemporaryfile.h index a597a93..c0b41bb 100644 --- a/src/corelib/io/qtemporaryfile.h +++ b/src/corelib/io/qtemporaryfile.h @@ -64,7 +64,7 @@ class Q_CORE_EXPORT QTemporaryFile : public QFile #ifndef QT_NO_QOBJECT Q_OBJECT #endif - Q_DECLARE_PRIVATE(QTemporaryFile) + Q_DECLARE_SCOPED_PRIVATE(QTemporaryFile) public: QTemporaryFile(); diff --git a/src/corelib/io/qtextstream.h b/src/corelib/io/qtextstream.h index fc4794e..9d4b3d0 100644 --- a/src/corelib/io/qtextstream.h +++ b/src/corelib/io/qtextstream.h @@ -72,7 +72,7 @@ class QTextDecoder; class QTextStreamPrivate; class Q_CORE_EXPORT QTextStream // text stream class { - Q_DECLARE_PRIVATE(QTextStream) + Q_DECLARE_SCOPED_PRIVATE(QTextStream) public: enum RealNumberNotation { diff --git a/src/corelib/kernel/qabstracteventdispatcher.h b/src/corelib/kernel/qabstracteventdispatcher.h index 0550dde..93815f6 100644 --- a/src/corelib/kernel/qabstracteventdispatcher.h +++ b/src/corelib/kernel/qabstracteventdispatcher.h @@ -58,7 +58,7 @@ template struct QPair; class Q_CORE_EXPORT QAbstractEventDispatcher : public QObject { Q_OBJECT - Q_DECLARE_PRIVATE(QAbstractEventDispatcher) + Q_DECLARE_SCOPED_PRIVATE(QAbstractEventDispatcher) public: typedef QPair TimerInfo; diff --git a/src/corelib/kernel/qabstractitemmodel.h b/src/corelib/kernel/qabstractitemmodel.h index dc7d7bd..90d04cd 100644 --- a/src/corelib/kernel/qabstractitemmodel.h +++ b/src/corelib/kernel/qabstractitemmodel.h @@ -283,7 +283,7 @@ protected: QModelIndexList persistentIndexList() const; private: - Q_DECLARE_PRIVATE(QAbstractItemModel) + Q_DECLARE_SCOPED_PRIVATE(QAbstractItemModel) Q_DISABLE_COPY(QAbstractItemModel) }; diff --git a/src/corelib/kernel/qcore_symbian_p.cpp b/src/corelib/kernel/qcore_symbian_p.cpp index a3a85b0..c681b1f 100644 --- a/src/corelib/kernel/qcore_symbian_p.cpp +++ b/src/corelib/kernel/qcore_symbian_p.cpp @@ -61,13 +61,12 @@ Q_CORE_EXPORT HBufC* qt_QString2HBufC(const QString& aString) #else TPtrC16 ptr(qt_QString2TPtrC(aString)); #endif - buffer = HBufC::New(ptr.Length()); - Q_CHECK_PTR(buffer); + buffer = q_check_ptr(HBufC::New(ptr.Length())); buffer->Des().Copy(ptr); return buffer; } -Q_CORE_EXPORT QString qt_TDesC2QStringL(const TDesC& aDescriptor) +Q_CORE_EXPORT QString qt_TDesC2QString(const TDesC& aDescriptor) { #ifdef QT_NO_UNICODE return QString::fromLocal8Bit(aDescriptor.Ptr(), aDescriptor.Length()); @@ -82,9 +81,8 @@ QHBufC::QHBufC() } QHBufC::QHBufC(const QHBufC &src) + : m_hBufC(q_check_ptr(src.m_hBufC->Alloc())) { - m_hBufC = src.m_hBufC->Alloc(); - Q_CHECK_PTR(m_hBufC); } /*! diff --git a/src/corelib/kernel/qcore_symbian_p.h b/src/corelib/kernel/qcore_symbian_p.h index bd8f304..453c3d3 100644 --- a/src/corelib/kernel/qcore_symbian_p.h +++ b/src/corelib/kernel/qcore_symbian_p.h @@ -65,8 +65,8 @@ QT_BEGIN_NAMESPACE Q_CORE_EXPORT HBufC* qt_QString2HBufC(const QString& aString); -Q_CORE_EXPORT QString qt_TDesC2QStringL(const TDesC& aDescriptor); -inline QString qt_TDes2QStringL(const TDes& aDescriptor) { return qt_TDesC2QStringL(aDescriptor); } +Q_CORE_EXPORT QString qt_TDesC2QString(const TDesC& aDescriptor); +inline QString qt_TDes2QString(const TDes& aDescriptor) { return qt_TDesC2QString(aDescriptor); } static inline QSize qt_TSize2QSize(const TSize& ts) { diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index c07a6e9..90d8f2f 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -1114,6 +1114,9 @@ void QCoreApplication::postEvent(QObject *receiver, QEvent *event, int priority) event->d = reinterpret_cast(quintptr(data->loopLevel)); } + // delete the event on exceptions to protect against memory leaks till the event is + // properly owned in the postEventList + QScopedPointer eventDeleter(event); if (data->postEventList.isEmpty() || data->postEventList.last().priority >= priority) { // optimization: we can simply append if the last event in // the queue has higher or equal priority @@ -1128,6 +1131,7 @@ void QCoreApplication::postEvent(QObject *receiver, QEvent *event, int priority) QPostEventList::iterator at = qUpperBound(begin, end, priority); data->postEventList.insert(at, QPostEvent(receiver, event, priority)); } + eventDeleter.take(); event->posted = true; ++receiver->d_func()->postedEvents; data->canWait = false; diff --git a/src/corelib/kernel/qcoreapplication.h b/src/corelib/kernel/qcoreapplication.h index 48e65a7..60b0882 100644 --- a/src/corelib/kernel/qcoreapplication.h +++ b/src/corelib/kernel/qcoreapplication.h @@ -76,7 +76,7 @@ class Q_CORE_EXPORT QCoreApplication : public QObject Q_PROPERTY(QString organizationName READ organizationName WRITE setOrganizationName) Q_PROPERTY(QString organizationDomain READ organizationDomain WRITE setOrganizationDomain) - Q_DECLARE_PRIVATE(QCoreApplication) + Q_DECLARE_SCOPED_PRIVATE(QCoreApplication) public: QCoreApplication(int &argc, char **argv); ~QCoreApplication(); diff --git a/src/corelib/kernel/qeventdispatcher_glib_p.h b/src/corelib/kernel/qeventdispatcher_glib_p.h index 80ec9fa..bcb655b 100644 --- a/src/corelib/kernel/qeventdispatcher_glib_p.h +++ b/src/corelib/kernel/qeventdispatcher_glib_p.h @@ -67,7 +67,7 @@ class QEventDispatcherGlibPrivate; class Q_CORE_EXPORT QEventDispatcherGlib : public QAbstractEventDispatcher { Q_OBJECT - Q_DECLARE_PRIVATE(QEventDispatcherGlib) + Q_DECLARE_SCOPED_PRIVATE(QEventDispatcherGlib) public: explicit QEventDispatcherGlib(QObject *parent = 0); diff --git a/src/corelib/kernel/qeventdispatcher_symbian.cpp b/src/corelib/kernel/qeventdispatcher_symbian.cpp index 34a20da..3293d47 100644 --- a/src/corelib/kernel/qeventdispatcher_symbian.cpp +++ b/src/corelib/kernel/qeventdispatcher_symbian.cpp @@ -194,7 +194,7 @@ void QWakeUpActiveObject::RunL() { iStatus = KRequestPending; SetActive(); - QT_TRANSLATE_EXCEPTION_TO_SYMBIAN_LEAVE(m_dispatcher->wakeUpWasCalled()); + QT_TRYCATCH_LEAVING(m_dispatcher->wakeUpWasCalled()); } QTimerActiveObject::QTimerActiveObject(QEventDispatcherSymbian *dispatcher, SymbianTimerInfo *timerInfo) @@ -224,7 +224,7 @@ void QTimerActiveObject::DoCancel() void QTimerActiveObject::RunL() { int error; - QT_TRANSLATE_EXCEPTION_TO_SYMBIAN_ERROR(error, Run()); + QT_TRYCATCH_ERROR(error, Run()); if (error < 0) { CActiveScheduler::Current()->Error(error); // stop and report here, as this timer will be deleted on scope exit } @@ -274,6 +274,11 @@ void QTimerActiveObject::Start() } } +SymbianTimerInfo::SymbianTimerInfo() +: timerAO(0) +{ +} + SymbianTimerInfo::~SymbianTimerInfo() { delete timerAO; @@ -314,7 +319,7 @@ void QCompleteDeferredAOs::RunL() iStatus = KRequestPending; SetActive(); - QT_TRANSLATE_EXCEPTION_TO_SYMBIAN_LEAVE(m_dispatcher->reactivateDeferredActiveObjects()); + QT_TRYCATCH_LEAVING(m_dispatcher->reactivateDeferredActiveObjects()); } QSelectThread::QSelectThread() @@ -587,7 +592,7 @@ void QSocketActiveObject::RunL() if (!okToRun()) return; - QT_TRANSLATE_EXCEPTION_TO_SYMBIAN_LEAVE(m_dispatcher->socketFired(this)); + QT_TRYCATCH_LEAVING(m_dispatcher->socketFired(this)); } void QSocketActiveObject::deleteLater() @@ -619,11 +624,11 @@ QEventDispatcherSymbian::~QEventDispatcherSymbian() void QEventDispatcherSymbian::startingUp() { if( !CActiveScheduler::Current() ) { - m_activeScheduler = new(ELeave)CQtActiveScheduler(); + m_activeScheduler = q_check_ptr(new CQtActiveScheduler()); // CBase derived class needs to be checked on new CActiveScheduler::Install(m_activeScheduler); } - m_wakeUpAO = new(ELeave) QWakeUpActiveObject(this); - m_completeDeferredAOs = new(ELeave) QCompleteDeferredAOs(this); + m_wakeUpAO = q_check_ptr(new QWakeUpActiveObject(this)); + m_completeDeferredAOs = q_check_ptr(new QCompleteDeferredAOs(this)); // We already might have posted events, wakeup once to process them wakeUp(); } @@ -742,7 +747,7 @@ bool QEventDispatcherSymbian::processEvents ( QEventLoop::ProcessEventsFlags fla m_noSocketEvents = oldNoSocketEventsValue; } QT_CATCH (const std::exception& ex) { #ifndef QT_NO_EXCEPTIONS - CActiveScheduler::Current()->Error(qt_translateExceptionToSymbianError(ex)); + CActiveScheduler::Current()->Error(qt_exception2SymbianError(ex)); #endif } @@ -896,7 +901,7 @@ bool QEventDispatcherSymbian::hasPendingEvents() void QEventDispatcherSymbian::registerSocketNotifier ( QSocketNotifier * notifier ) { - QSocketActiveObject *socketAO = new (ELeave) QSocketActiveObject(this, notifier); + QSocketActiveObject *socketAO = q_check_ptr(new QSocketActiveObject(this, notifier)); m_notifiers.insert(notifier, socketAO); m_selectThread.requestSocketEvents(notifier, &socketAO->iStatus); } @@ -930,7 +935,7 @@ void QEventDispatcherSymbian::registerTimer ( int timerId, int interval, QObject timer->inTimerEvent = false; timer->receiver = object; timer->dispatcher = this; - timer->timerAO = new(ELeave) QTimerActiveObject(this, timer.data()); + timer->timerAO = q_check_ptr(new QTimerActiveObject(this, timer.data())); m_timerList.insert(timerId, timer); timer->timerAO->Start(); @@ -952,16 +957,20 @@ bool QEventDispatcherSymbian::unregisterTimer ( int timerId ) bool QEventDispatcherSymbian::unregisterTimers ( QObject * object ) { - QList idsToRemove = registeredTimers(object); - - if (idsToRemove.isEmpty()) + if (m_timerList.isEmpty()) return false; - - for (int c = 0; c < idsToRemove.size(); ++c) { - unregisterTimer(idsToRemove[c].first); + + bool unregistered = false; + for (QHash::iterator i = m_timerList.begin(); i != m_timerList.end(); ) { + if ((*i)->receiver == object) { + i = m_timerList.erase(i); + unregistered = true; + } else { + ++i; + } } - return true; + return unregistered; } QList QEventDispatcherSymbian::registeredTimers ( QObject * object ) const diff --git a/src/corelib/kernel/qeventdispatcher_symbian_p.h b/src/corelib/kernel/qeventdispatcher_symbian_p.h index b39d6df..310d74d 100644 --- a/src/corelib/kernel/qeventdispatcher_symbian_p.h +++ b/src/corelib/kernel/qeventdispatcher_symbian_p.h @@ -112,6 +112,7 @@ private: struct SymbianTimerInfo : public QSharedData { + SymbianTimerInfo(); ~SymbianTimerInfo(); int timerId; @@ -183,7 +184,7 @@ private: class QSelectThread : public QThread { - Q_DECLARE_PRIVATE(QThread) + Q_DECLARE_SCOPED_PRIVATE(QThread) public: QSelectThread(); @@ -217,7 +218,7 @@ public: // from CActiveScheduler class Q_CORE_EXPORT QEventDispatcherSymbian : public QAbstractEventDispatcher { - Q_DECLARE_PRIVATE(QAbstractEventDispatcher) + Q_DECLARE_SCOPED_PRIVATE(QAbstractEventDispatcher) public: QEventDispatcherSymbian(QObject *parent = 0); diff --git a/src/corelib/kernel/qeventdispatcher_unix_p.h b/src/corelib/kernel/qeventdispatcher_unix_p.h index e0ac5da..c52965a 100644 --- a/src/corelib/kernel/qeventdispatcher_unix_p.h +++ b/src/corelib/kernel/qeventdispatcher_unix_p.h @@ -181,7 +181,7 @@ class QEventDispatcherUNIXPrivate; class Q_CORE_EXPORT QEventDispatcherUNIX : public QAbstractEventDispatcher { Q_OBJECT - Q_DECLARE_PRIVATE(QEventDispatcherUNIX) + Q_DECLARE_SCOPED_PRIVATE(QEventDispatcherUNIX) public: explicit QEventDispatcherUNIX(QObject *parent = 0); diff --git a/src/corelib/kernel/qeventdispatcher_win_p.h b/src/corelib/kernel/qeventdispatcher_win_p.h index ca5dbf8..37578a0 100644 --- a/src/corelib/kernel/qeventdispatcher_win_p.h +++ b/src/corelib/kernel/qeventdispatcher_win_p.h @@ -67,7 +67,7 @@ LRESULT CALLBACK qt_internal_proc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp) class Q_CORE_EXPORT QEventDispatcherWin32 : public QAbstractEventDispatcher { Q_OBJECT - Q_DECLARE_PRIVATE(QEventDispatcherWin32) + Q_DECLARE_SCOPED_PRIVATE(QEventDispatcherWin32) void createInternalHwnd(); friend class QGuiEventDispatcherWin32; diff --git a/src/corelib/kernel/qeventloop.h b/src/corelib/kernel/qeventloop.h index 60d