Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not use complex typed static variables #34

Open
espakm opened this issue Feb 9, 2016 · 4 comments
Open

Do not use complex typed static variables #34

espakm opened this issue Feb 9, 2016 · 4 comments

Comments

@espakm
Copy link

espakm commented Feb 9, 2016

The pythonqt.dll crashes when you try to load it dynamically on Windows. The crash happens at this point:

static void registerMetaTypeToPythonConverter(int metaTypeId, PythonQtConvertMetaTypeToPythonCB* cb) { _metaTypeToPythonConverters.insert(metaTypeId, cb); }

The static function refers to a static variable that has complex type (QHash). The static variable is not initialised.

The issue is described here:
http://stackoverflow.com/questions/5114683/loading-dll-not-initializing-static-c-classes
Basically, complex typed static variables should be avoided in dll-s.

Pull request follows. I tried to get rid of every references to complex typed static variables. The object typed (non pointer) static data members I replaced by static getters that declare the variable as pointer, assignes NULL to it, and then does a NULL check and assigns a 'new' instance at the first time.

There were many static locals declared with type QByteArray but used only as const char * later. I changed the types to 'const char *' wherever I could.

In other cases the static locals were used only as performance tweak. There, I simply removed the 'static' keyword. All of them were trivial functions, the 'static' keyword was not necessary and I doubt that it made noticeable difference in execution time.

@espakm
Copy link
Author

espakm commented Feb 9, 2016

#35

@jcfr
Copy link
Member

jcfr commented Feb 9, 2016

Thanks for the PR 👍

I will have a look asap.

In the mean time, could you also discuss the issue on the PythonQt list ? See http://sourceforge.net/p/pythonqt/discussion/631392/

@espakm
Copy link
Author

espakm commented Feb 10, 2016

@jcfr
Copy link
Member

jcfr commented Feb 10, 2016

Great. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants