[sip] random crashes when using QMetaEnum

Phil Thompson phil at riverbankcomputing.com
Fri Sep 11 14:17:34 BST 2020


On 08/09/2020 13:39, Denis Rouzaud wrote:
> Hi list,
> 
> For an enum (not scoped based), I am running this code:
> 
> for i in range(0, 100):
>     idx =
> QgsDataSourceUri.staticMetaObject.indexOfEnumerator(QgsDataSourceUri.SslMode.__name__)
>     meta_enum = QgsDataSourceUri.staticMetaObject.enumerator(idx)
>     print(meta_enum.isValid())
>     sleep(.3)
> 
> I usually get a crash after 2 to 6 iterations.
> Code is hereunder.
> 
> As far as I can tell, this happens to any version of SIP above 4.19.17 
> (not
> tested under).
> 
> Cheers,
> Denis
> 
> The enum is defined as follows:
> 
> class CORE_EXPORT QgsDataSourceUri
> 
> {
> 
>     Q_GADGET
> 
>   public:
> 
>     enum SslMode
> 
>     {
> 
>       SslPrefer,
> 
>       SslDisable,
> 
>       SslAllow,
> 
>       SslRequire,
> 
>       SslVerifyCa,
> 
>       SslVerifyFull
> 
>     };
> 
>     Q_ENUM( SslMode )
> 
>     QgsDataSourceUri();
> 
> 
> The sip file:
> 
> class QgsDataSourceUri
> 
> {
> 
> %TypeHeaderCode
> 
> #include "qgsdatasourceuri.h"
> 
> %End
> 
>   public:
> 
>     static const QMetaObject staticMetaObject;
> 
>   public:
> 
>     enum SslMode
> 
>     {
> 
>       SslPrefer,
> 
>       SslDisable,
> 
>       SslAllow,
> 
>       SslRequire,
> 
>       SslVerifyCa,
> 
>       SslVerifyFull
> 
>     };
> 
>     QgsDataSourceUri();

I can't reproduce this with a test case I can actually run...

from time import sleep

from PyQt5.QtCore import QState


for i in range(0, 100):
     idx = QState.staticMetaObject.indexOfEnumerator(
             QState.ChildMode.__name__)
     meta_enum = QState.staticMetaObject.enumerator(idx)
     print(meta_enum.isValid())
     sleep(.3)

...using current versions.

Phil


More information about the PyQt mailing list