From owner-freebsd-ports@freebsd.org Fri Apr 15 12:31:07 2016 Return-Path: Delivered-To: freebsd-ports@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id CB527ADA328 for ; Fri, 15 Apr 2016 12:31:07 +0000 (UTC) (envelope-from freebsd-ports@m.gmane.org) Received: from plane.gmane.org (plane.gmane.org [80.91.229.3]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 9460B1203 for ; Fri, 15 Apr 2016 12:31:07 +0000 (UTC) (envelope-from freebsd-ports@m.gmane.org) Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1ar2f8-0007o2-Ba for freebsd-ports@freebsd.org; Fri, 15 Apr 2016 14:15:50 +0200 Received: from dhcp-077-248-147-050.chello.nl ([77.248.147.50]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 15 Apr 2016 14:15:50 +0200 Received: from rakuco by dhcp-077-248-147-050.chello.nl with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 15 Apr 2016 14:15:50 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: freebsd-ports@freebsd.org From: Raphael Kubo da Costa Subject: Re: Need some help with c++/qt5 code Date: Fri, 15 Apr 2016 14:15:43 +0200 Lines: 56 Message-ID: <86inzjdq4w.fsf@FreeBSD.org> References: <570F85E3.6060000@ShaneWare.Biz> Mime-Version: 1.0 Content-Type: text/plain X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: dhcp-077-248-147-050.chello.nl User-Agent: Gnus/5.130016 (Ma Gnus v0.16) Emacs/24.5 (berkeley-unix) Cancel-Lock: sha1:2cDHSzwNYjZSCCbZZ90eKf4zJbk= X-BeenThere: freebsd-ports@freebsd.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Porting software to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 15 Apr 2016 12:31:07 -0000 Dimitry Andric writes: > On 14 Apr 2016, at 13:58, Shane Ambler wrote: >> >> Hi there, while I am comfortable with c and python, I only know a little >> c++ and could use some help. > ... >> class TPanelFactory >> { >> QString m_panelType; >> static QMap m_table; >> >> public: >> TPanelFactory(QString panelType); >> ~TPanelFactory(); >> >> QString getPanelType() const { return m_panelType; } >> >> virtual void initialize(TPanel *panel) = 0; >> virtual TPanel *createPanel(QWidget *parent); >> static TPanel *createPanel(QWidget *parent, QString panelType); >> }; >> >> m_table is then in the source file as >> >> QMap TPanelFactory::m_table; >> >> The segfault happens in the constructor - >> >> TPanelFactory::TPanelFactory(QString panelType) >> : m_panelType(panelType) >> { >> assert(m_table.count(panelType) == 0); >> m_table[m_panelType] = this; >> } >> >> the last line causes the segfault, if I comment it out then main() is >> entered, but I expect removing that line will bite back soon enough. >> >> How can I get this working? >> >> Why would this fail on FreeBSD but not OSX or windows? > > Most likely the program depends on the initialization order of global > constructors. This is bad practice, and should be avoided. I agree. Maybe using Q_GLOBAL_STATIC helps? - Remove m_table from TPanelFactory. - In pane.cpp, you do something like this: typedef QMap PanelMapType; Q_GLOBAL_STATIC(PanelMapType, s_panelMap); you then need to replace uses of m_table with s_panelMap and use s_panelMap->operation() instead of m_table.operation().