Saturday, December 02, 2017

GSoC 2017 summary

As previously mentioned, wxWidgets has participated in Google Summer of Code again in 2017, after a 2 year hiatus. We had only 2 projects this time, but the good news is that both of them were successful and, as of 15 minutes ago, been merged into Git master and will be available in the upcoming 3.1.1 release.

The first project, by Jose Lorenzo, enhanced wxWebView::RunScript() to allow returning values from JavaScript code executed by this function back to C++. This wasn't a particularly big change, but it is an important one as it makes it possible to write mixed C++/JavaScript applications using wxWidgets for the standard UI parts and wxWebView for richer or more dynamic parts.

The second project, by Prashant Kumar, had a much greater scope and added support for handling gesture events, such as pinch-zoom or double-finger-rotate. This required adding new API covering the quite different native APIs provided by MSW, GTK+ and macOS and implementing it for all these platforms, congratulations to Prashant for getting it all done! The only snag is that we don't really have any multi-touch-capable devices to test this work with, so it's possible that the new code still has some issues -- but, in the best open source tradition, we count on our uses to let us know about them.

Finally, while it doesn't affect wxWidgets users directly, GSoC is also nice because it provides a rare opportunity for different wxWidgets developers to meet together at the mentor summit after its end. And this year this allowed me to finally see Mariano Reingart, who was himself a GSoC student a few years ago and was a mentor this year, in person for the first time ever:

Thanks again to our students and, of course, huge thanks to our mentors: Cătălin Răceanu, Mariano Reingart and Steven Lamerton, as well as to Bryan Petty who took care of all the organisational chores. Finally, we are obviously very grateful to Google itself and the GSoC team there, for making all this possible. We hope to be able to take part in GSoC 2018, which will already start soon, so please help us by spreading the word about this programme among any students you know and let us know if you have any interesting ideas for the student projects.

Sunday, November 12, 2017

Surreptitious Submodule Switch

During the last couple of days, we've transitioned all the third party libraries used by wxWidgets, such as libpng, libjpeg and so on, to use Git submodules instead of just subdirectories in the main repository. If you don't use Git to get the latest and greatestfor the appropriate definition of "great" wxWidgets, you don't need need to read further as it shouldn't affect you in any way except for resulting in faster and more frequent updates to these libraries (but still consider starting to use sources from Git to help us with testing!).

If you do use Git, you will notice that your next update, i.e. git pull or git fetch && git merge --ff-only origin/master, will delete all files in src/{expat, jpeg, png, tiff, zlib} directories. Do not be alarmed by this but do run

git submodule update --init
to initialize and get the latest contents of all the submodules. This will, unfortunately, take quite some time, and if you use a not too ancient version of Git (2.8 or later), you should be able to speed the process up significantly by doing
git fetch --recurse-submodules -j2
instead, where "2" could be replaced by any number up to 5 (higher would be useless with only 5 submodules).

During subsequent updates, if you notice any change to one of the submodules, you need to only rerun git submodule update (without the --init option) and it will be much faster. Other than that, your use of wxWidgets Git repository shouldn't have to change in any way, the only difference is now most of Git commands won't recurse into submodules, at least by default, so git grep, for example, won't find any matches in the subdirectories mentioned above by default. However mostly the new behaviour is more useful, and you can use the same --recurse-submodules option with a few Git commands to change it if really needed.

Of course, if you do find any problems due to the switch to submodules or third party libraries upgrades that have taken place together with it (we now use the latest versions of all of them, notably jumping from libjpeg 6b released in 1998 to 9b, released in 2016), please let us know on the mailing lists, as usual.

Sunday, May 28, 2017

Configure is now less forgiving

Just a word of warning: it was previously possibly to write ../configure --enable-bloordyblop and configure would happily run and just ignore the unknown option. This could be seen as being nicely lenient but, in fact, was much more often aggravating as it allowed typos in configure options to slip through, resulting in many "WTF are my library binaries still not optimised even though I did use --enable-optimize?". The answer is, of course, as previously mentioned, wxWidgets British roots: you were supposed to use --enable-optimise instead. But while sticking to the right spelling might be commendable, not giving any errors for the wrongalternative one is definitely not. Moreover, this was never intentional and happened only as an unfortunate side effect of how Autoconf AC_CONFIG_SUBDIRS()macro worked

And this has finally changed: since this recent commit, which will be part of upcoming 3.1.1 release, unrecognised configure options will result in an immediate error. And while the new behaviour is better, it does risk breaking a few of the existing build scripts, e.g. if you use obsolete options (such as --enable-compat24) or, indeed, if you made a typo in one of them. In this case, please just remove the options that don't exist any more (they were previously ignored anyhow) or fix the typos. And in the unlikely case when you really need to pass an unsupported option to wx configure script (why would you do this?), you can always explicitly use --disable-option-checking on the command line to continue doing so -- and you will even get an error if you make a typo in this one!

Friday, May 05, 2017

Our GSoC 2017 students and projects

After an average of one post every 6 months or so on this blog, good news just can't stop coming now, with a second post in just 3 days. This one is to announce that wxWidgets has been allocated two slots in this year Google Summer of Code program and Prashant Kumar and Jose Lorenzo will be working on adding support for multi-touch gestures and providing better integration with JavaScript in wxWebView this summer.

Congratulations to Prashant and Jose and thanks to everybody else who applied (but, unfortunately, couldn't be accepted) to work on wxWidgets and also to our mentors: Cătălin Răceanu, Mariano Reingart and Steven Lamerton. And good luck to all involved!

Tuesday, May 02, 2017

3.0.3 Released

We have finally, after a long delay, released 3.0.3, please see the announcement or go directly to the release page. As with the previous 3.0.x releases, there are no important new features in this release, but there are quite a few bug fixes as well as support for the relatively recent compiler, platforms and third-party libraries versions which were not yet (widely) available at the time of 3.0.2, so upgrading to it is strongly recommended for all 3.0 users, especially because it is so simple: the new release is 100% compatible with 3.0.2 and doesn't require any changes to your applications code or, if you are using shared libraries, not even recompiling it.

As always, thanks to everyone who has contributed to this release (at least 66 people according to git commit information, but certainly more in practice) and helped with preparing it, by building the binaries, documentation and testing it!

Monday, March 27, 2017

Last call for proposals for GSoC 2017

This is just a reminder that wxWidgets is one of the mentoring organizations in this year Google Summer of Code program and we are looking for proposals from motivated students with knowledge of C++ and interest for cross-platform development.

There is less than a week remaining before the deadline for submitting GSoC applications, so, if you are a student, or know of a student, interested in participating, please hurry up!

Sunday, February 19, 2017

Safer S...

I want, of course, to talk about "Safer Strings" today.

TL;DR: Add /DwxNO_UNSAFE_WXSTRING_CONV=1 to your compiler options today.

wxWidgets has had implicit conversion of wxString to const char* since the dawn of time (or about 1992, at any rate). This was always dangerous, as it allowed someone to accidentally write:

void show_and_free(const char* p) { ...; free(p); }
wxString s("...");
with catastrophic consequences, but such situations were relatively rare and it was thought that the convenience of having this implicit conversion overweighted the dangers. This is also why when we added Unicode support later, we also added implicit conversion to const wchar_t* and, when we added "STL" build mode, in which interoperability with the standard library is increased further even at the price of backwards compatibility, we added implicit conversions to std::string and std::wstring as well.

Unfortunately, with the merge of ANSI and Unicode build modes in wxWidgets 3, another, much more dangerous, problem has appeared because in the new combined mode we can now have a string containing Unicode characters not representable in the current locale encoding. And converting such strings to either char* or std::string inevitably results in a loss of data in this case, e.g.

double convert_temperature_to_celsius(const char* p) {
    const char* end;
    double t = strtod(p, &end);
    return 5.*(t - 32)/9.;

wxString s = wxGetTextFromUser("Enter temperature");
could, confusingly, result in always returning -17.77777, corresponding to 0°F, if the user decided to terminate the temperature entry with "°F" to explicitly indicate the scale used and the current encoding couldn't represent the degree symbol (which is the case of e.g. CP1250 under Microsoft Windows). In this case, conversion of wxString to char* would fail and p would be just empty.

Of course, this wouldn't happen if the code just used wxString::ToDouble() directly, or used wxChar and wxStrtod(), or used UTF-8, capable of representing any Unicode character, as encoding (which is practically always the case under Unix systems nowadays). So there are a lot of ways to write this code correctly, but, unfortunately, it was still too simple to write it wrongly accidentally lose the data entered by the user in this case. Clearly, implicit conversions potentially losing data are a bad idea, but we couldn't just turn them off in wxWidgets 3, as it would have broken almost all the existing programs which, empirically, all used these conversions in many places.

For the same reason, we still won't be able to turn this conversion off by default, even in wxWidgets 3.2. However now we at least provide a way to opt-in into safer behaviour. The arguably less interesting part of the changes is that you can now change the value of the compile-time wxUSE_UNSAFE_WXSTRING_CONV option when building the library. It is set to 1 by default, for compatibility, but if you build wxWidgets for the use in your own project, you are strongly advised to set it to 0 to permanently disable the unsafe, in the sense described above, implicit conversions.

Many people, however, don't build their own library, but use the one provided by their package manager under Unix/macOS or download our MSW binaries. These official binaries will continue to provide the unsafe conversions for compatibility, but you can define wxNO_UNSAFE_WXSTRING_CONV when building your own project to disable their use in your code without rebuilding the library. This symbol can be just #define'd before including any wxWidgets headers, but it is better to define it globally, in the compiler options in your make- or project file: just add /DwxNO_UNSAFE_WXSTRING_CONV=1 to it. And the main point of this long post is to convince you that you NEED TO DO just that: please define wxNO_UNSAFE_WXSTRING_CONV for your code and fix the resulting compilation errors to ensure that you don't lose any data entered by the user.

Fixing the compilation errors will, generally speaking, involve doing one of two things:

  • Either stop using char* (or std::string in the STL build) entirely and use wxString directly.
  • Or convert it to wchar_t* (or std::wstring) or convert wxString to UTF-8 encoding which will never lose data, using methods such as utf8_str(), which is a convenient synonym for mb_str(wxConvUTF8), or ToStdString(wxConvUTF8).
Of course, if you really need to use the current locale encoding, e.g. because you call a C standard library function using it, you will still need to perform the conversion to it, using just plain mb_str() and there will still be a possibility of the conversion to it failing, but at least now it won't happen implicitly.

Thanks for reading all this and, if you jumped to the end, hoping to quickly find the conclusion instead of reading this wall of text, please see the conclusion in the very beginning!