Discussion:
[gdal-dev] Minimum supported C and C++ standards
Kurt Schwehr
2016-05-06 21:07:26 UTC
Permalink
There has been lively discussion on if/when GDAL moves to require compilers
with newer C and C++ standard versions. This email is meant to fork the
this discussion away from the local stack + memset -> std::vector
discussion. I'm trying to draft a proposal based on the discussion, but it
is a lot hardered.

I suggest folks think about starting off with an empty (or nearly empty)
white list of features and give a look at documents like:

https://chromium-cpp.appspot.com/.

GDAL is very different than Chromium, but I think it is great that they
have a place for contributors to get a summary of what is considered okay
and what is blacklisted.

We currently have experiments with override/final and std::mutex/lock_guard
for those compiling with GDAL >= C++11. I think starting off with nullptr
might be a good and one of the simplest places to start. Even suggested a
while ago making nullptr be a #define to NULL for C++03 and we current have
#ifdef NULL_AS_NULLPTR #define NULL nullptr in cpl_port.h, so it is already
setup for people to try.
Even Rouault
2016-05-07 15:27:19 UTC
Permalink
Post by Kurt Schwehr
There has been lively discussion on if/when GDAL moves to require compilers
with newer C and C++ standard versions. This email is meant to fork the
this discussion away from the local stack + memset -> std::vector
discussion. I'm trying to draft a proposal based on the discussion, but it
is a lot hardered.
I suggest folks think about starting off with an empty (or nearly empty)
https://chromium-cpp.appspot.com/.
My personal issue is that most of the stuff mentionned in there is alien to me.
At best only a rough theoretical understanding with no practical use. Perhaps
I should find some time to educate myself on C++11/14 but reading pages like
http://en.cppreference.com/w/cpp/utility/forward doesn't give a strong
incentive to do so ;-)
Post by Kurt Schwehr
GDAL is very different than Chromium, but I think it is great that they
have a place for contributors to get a summary of what is considered okay
and what is blacklisted.
I'll try to give my perspective over those choices of language features.

As Mateusz righly wrote, GDAL is a mix of C (not that much if you exclude the
external libraries that are internalized), C++ consisting of C with classes
(and avoiding the over use of classes that is typical in a bunch of Java
projects), a few uses of templates for methods working on different data types
in performance sensitive places.

C++03 already offers so many things to master that I can guess that C++11 and
C++14 have added again more "interesting" stuff on top of the old ways (since
hardly nothing prevents you from using a shiny C++ feature next to/together
with a C72 one. Which is porbably one of the main issue of the evolution of
C++). Those new features certainly solve problems, but I'm pretty sure they
also add new potential problems... I recommend having a look at
http://horstmann.com/cpp/pitfalls.html and looking at the date. Now imagine
what a later edition ~20 years later could be with all new C++ features.
Actually look at the snippet in appendix for a good candidate (actually
derived from a tutorial explaing rvalue reference)

Remembering a number of submitted patches, I'm pretty sure some occasional (or
not so occasional) contributors to GDAL are not software engineers as their
first qualification, which is OK since some parts of GDAL are really domain
specific. And even those who are in the software business are not necessarily
familiar with all C++ features, or on the contrary are familiar enough to know
they don't want to use them, or worse, others can believe that they are
familiar with them, but misuse them in subtle ways (never seen an
enthusiastic fresh graduate wanting to apply blindly in your project the nice
stuff seen in books?). IMHO we should try to focus to attract developers that
are more interested by geospatial stuff than by C++ subtelties. GDAL purpose is
not to be a showcase for C++ features, but to solve real-world problems.
Hopefully everybody agrees with that.

If we move to a later C++ standard, or even use features of C++98 we currently
don't use, I'd advocate for using things that are obviously making the code
better / more readable. Honestly who finds that
"std::unique_ptr<int *, std::function<void(char *)>> Vals(CPLCalloc(256, 0),
CPLFree);" is obviously more readable, efficient and less error prone than
"std::vector Vals(256,0)" ?

In my opinion the features of the language you use (of course, once you've
understood and mastered them to the point where they are familiar to you
without needing to open a programming book) play only a minor role in the
maintenance and extensibility of the code (at least, they shouldn't !). The
real challenges are to understand the overall design, the details of the
algorithms, the formats, the interactions between different parts of the code,
what is performance sensitive and what is not, the history ... So definitely
one of the best investment (and less risky) for maintenance is to add comments
where they are needed.

Perhaps rather than thinking to which C++ features we wish, we should
concentrate on the problems we want to solve. The reasoning should be "We have
this problem/need, we currently use solution X to address it, but this has the
following defects and I think that feature Y is the best way to solve it".
And if that's about existing code, we must keep in mind that every change has
the potential to break working things, so the ratio benefit / risk must be >> 1
(>> meaning here "significantly greater than", and not the right bitshift
operator, or the closing of 2 levels of templates, or the input stream
operator, or an overloaded operator with a semantics left to the good will of
the programmer)

The scope of changes should be also defined : restricted to internal
implementation details or impacting the API ?

Tihs is a more trivial consideration, but code churn does make backporting
harder (patches no longer apply cleanly). Although it's an inconvenience that
is acceptable if it makes the future (significantly) better.

Cheers,

Even

(*) The following code compiles warning free with -std=c++11 -Wall -Wextra -
pedantic with GCC 5.2.0 but asserts at runtime. Find why. OK, you may find it
easily since I mentionned this would assert. Now imagine this is a code
contribution that you review. Would you figure out the error ?
Of course, with C or C with classes, the language already offers room for bugs.
But the more language features, the more bug opportunities you add.

#include <string>
#include <cassert>

class Base
{
protected:
std::string x;
public:
Base(const std::string& xin) : x(xin) {}
Base(Base const & rhs) : x(rhs.x) { }
Base(Base&& rhs) { x = rhs.x; rhs.x = "moved"; }
};

class Derived: public Base
{
protected:
std::string y;
public:
Derived(const std::string& xin) : Base(xin), y(xin) { }
Derived(Derived const & rhs) : Base(rhs), y(rhs.y) { }
Derived(Derived&& rhs) : Base(rhs) { y = rhs.y; rhs.y = "moved"; }
~Derived() { assert(y == x); }
};

Derived foo(Derived d)
{
return d;
}

int main()
{
foo(Derived("x"));
return 0;
}
--
Spatialys - Geospatial professional services
http://www.spatialys.com
David Strip
2016-05-07 16:59:15 UTC
Permalink
_______________________________________________
gdal-dev mailing list
gdal-***@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/gdal-dev
Kurt Schwehr
2016-05-07 17:10:23 UTC
Permalink
This is example demonstrates that we are in-general fighting hard against
C++... up-hill both ways in a blizzard. :) This is why starting with zero
features and working our way up with a white list gives examples of correct
usage. It looks like a lot of GDAL development happens by
copy-paste-tweak, so good examples are key. And for every issue, we have
solutions that are valid C/C++03/C++11/C++14... the best solution is not
necessarily in any particular one.
Post by Even Rouault
If we move to a later C++ standard, or even use features of C++98 we currently
don't use, I'd advocate for using things that are obviously making the code
better / more readable. Honestly who finds that
"std::unique_ptr<int *, std::function<void(char *)>> Vals(CPLCalloc(256, 0),
CPLFree);" is obviously more readable, efficient and less error prone than
"std::vector Vals(256,0)" ?
This is cart before the horse but... as fast as I can so expect typos. Now
just think of a ~1K long function or method with tons of instances and lots
of places to bailout successfully or as failures. We have > 9K
free/CPLFree/CPLdelete/CPLDestroys that could be < ~100.

GDALMyBigObj *poInstance = CPLCalloc(sizeof(GDALMyBigObj);
...
if (oops) {
CPLDelete(poInstance)
return;
}
...
return; // kaboom
...
if (oops) {
CPLDelete(poInstance)
return;
}
...
if (oops) {
CPLDelete(poInstance)
return;
}

CPLDelete(poInstance)
return;

or worse

GDALMyBigObj *poInstance = CPLCalloc(sizeof(GDALMyBigObj);
...
if (oops) {
goto END;
}
...
// Careful what you do here because you are crossing gotos.
...
if (oops) {
goto END;
}
...
if (oops) {
goto END;
}
...
END:
CPLDelete(poInstance)
return;

when you could have... And yes, getting to this is not trivial. There are
multiple things here to discuss:

auto poInstance = std::make_unique<GDALMyBigObj>(arg1, arg2, arg3);

if(oops)
return; // Everything cleaned up nice
...

if(oops)
return; // Everything cleaned up nice
...

if(oops)
return; // Everything cleaned up nice
...

return; // Woohoo! Success!

My example of the deleter comes from real code where I don't what a heap
checker barfing at me when ever a test fails. Makes writing and debugging
tests insane....

// Apache 2.0 license...

{
// ...
unique_ptr<OGRFeature> feature(layer->GetNextFeature());
OGRGeometry *geometry = feature->GetGeometryRef();
ASSERT_NE(nullptr, geometry);

char *wkt_tmp = nullptr;
ASSERT_EQ(OGRERR_NONE, geometry->exportToWkt(&wkt_tmp));
std::unique_ptr<char, CplFreeDeleter> wkt(wkt_tmp);

wkt_tmp = nullptr;
ASSERT_STREQ("POINT (-109.27 10.3)", wkt.get());

}
David Strip
2016-05-07 19:00:22 UTC
Permalink
_______________________________________________
gdal-dev mailing list
gdal-***@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/gdal-dev
Andrew Bell
2016-05-07 20:48:56 UTC
Permalink
Post by Kurt Schwehr
This is cart before the horse but... as fast as I can so expect typos.
Now just think of a ~1K long function or method with tons of instances and
lots of places to bailout successfully or as failures.
This is why starting with zero features and working our way up with a white
Post by Kurt Schwehr
list gives examples of correct usage. It looks like a lot of GDAL
development happens by copy-paste-tweak, so good examples are key. And for
every issue, we have solutions that are valid C/C++03/C++11/C++14... the
best solution is not necessarily in any particular one.
Amen.
auto poInstance = std::make_unique<GDALMyBigObj>(arg1, arg2, arg3);
I think that some of you may be talking about features of a language that
you really aren't comfortable with. The notion of disallowing language
features because someone thinks they aren't useful or are confusing isn't
the way to go, IMO. C++, more than most other languages, goes through
pains before features are introduced. Nobody has to use all the features,
but all are useful to a subset of users and their proper use either makes
the code more clear, more efficient or less prone to bugs. (Yes, auto_ptr
was awful, but nobody uses auto_ptr anymore). Regardless of the language or
language feature, code can be clear or unclear and it's not the fault of
the feature for the lack of clarity. It may be that the reader hasn't seen
the use before or it may be that the writer didn't use feature in the best
way possible, but to make lists because Fred or Sam don't like this or that
isn't productive.

This example is more powerful than just the elimination of the
Post by Kurt Schwehr
opportunities for memory leaks. Kurt has snuck in the use of the
GDALMyBigObj constructor, which makes the initialization of the object more
transparent (and in fact assures that it occurs.) And if I correctly
understand std::make_unique, by making poinstance const, we can go farther
and guarantee that this pointer isn't assigned to another pointer, so that
the object will be destroyed at the end of current scope. (If the pointer
is assigned to another std::make_unique ptr, the scope of that pointer will
control when the object is destroyed).
As someone else said, GDAL code looks like C code, not like well-structured
C++. That's OK. But the notion of shoe-horning this or that feature into
the codebase seems fraught. If you're going to say that C++ 11 is OK, then
fine, use C++ 11 where appropriate in ways that make the code more
readable, more efficient or smaller. The reason to disallow a feature
shouldn't be about the whims of a developer or two, it should be because
compilers you are targeting don't support them or because you have ABI
issues. Reviewing code as it's submitted for clarity and efficiency is a
much better way to ensure quality code than is coming up with a
semi-arbitrary list of acceptable language features. Yes, sometimes even
"goto" is a good thing.

I also don't agree that more features mean more bugs. More features means
a language that takes more care to learn, but it doesn't mean more bugs.
If you're uncomfortable with move constructors, don't use them. But they
are useful at certain times for optimization. The provided example is just
confusing and useless code, not an indictment of move constructors. There
are plenty of newer language features that make code LESS susceptible to
bugs, when used properly.

P.S. - The above would just normally be written:

std::unique_ptr<GDALMyBigObj> obj(new GDALMyBigObj(arg1, arg2, arg3));

although without context, it's unclear that this is good bad or neither.
If I saw this code without a comment, I'd be tempted to change it to:

GDALMyBigObj obj(arg1, arg2, arg3);

because, hey, why not put it on the stack? The important bit here is that
someone needs to add a comment that it was put on the heap for a reason --
to keep the stack small.

P.P.S - I used to think lambdas were confusing, useless things. Having now
seen and written enough code containing lambdas, I'm happy to admit that I
was wrong.
--
Andrew Bell
***@gmail.com
Ari Jolma
2016-05-09 07:09:22 UTC
Permalink
Post by Kurt Schwehr
This is cart before the horse but... as fast as I can so expect
typos. Now just think of a ~1K long function or method with tons of
instances and lots of places to bailout successfully or as failures.
We have > 9K free/CPLFree/CPLdelete/CPLDestroys that could be < ~100.
I am definitely for having support for unique/smart pointers to objects.
In my experience one of the things making code difficult to understand
(and thus maintain/enhance) is long subroutines. Smart pointers would
often help a lot in that respect.

Ari
Post by Kurt Schwehr
GDALMyBigObj *poInstance = CPLCalloc(sizeof(GDALMyBigObj);
...
if (oops) {
CPLDelete(poInstance)
return;
}
...
return; // kaboom
...
if (oops) {
CPLDelete(poInstance)
return;
}
...
if (oops) {
CPLDelete(poInstance)
return;
}
CPLDelete(poInstance)
return;
or worse
GDALMyBigObj *poInstance = CPLCalloc(sizeof(GDALMyBigObj);
...
if (oops) {
goto END;
}
...
// Careful what you do here because you are crossing gotos.
...
if (oops) {
goto END;
}
...
if (oops) {
goto END;
}
...
CPLDelete(poInstance)
return;
when you could have... And yes, getting to this is not trivial.
auto poInstance = std::make_unique<GDALMyBigObj>(arg1, arg2, arg3);
if(oops)
return; // Everything cleaned up nice
...
if(oops)
return; // Everything cleaned up nice
...
if(oops)
return; // Everything cleaned up nice
...
return; // Woohoo! Success!
My example of the deleter comes from real code where I don't what a
heap checker barfing at me when ever a test fails. Makes writing and
debugging tests insane....
// Apache 2.0 license...
{
// ...
unique_ptr<OGRFeature> feature(layer->GetNextFeature());
OGRGeometry *geometry = feature->GetGeometryRef();
ASSERT_NE(nullptr, geometry);
char *wkt_tmp = nullptr;
ASSERT_EQ(OGRERR_NONE, geometry->exportToWkt(&wkt_tmp));
std::unique_ptr<char, CplFreeDeleter> wkt(wkt_tmp);
wkt_tmp = nullptr;
ASSERT_STREQ("POINT (-109.27 10.3)", wkt.get());
}
_______________________________________________
gdal-dev mailing list
http://lists.osgeo.org/mailman/listinfo/gdal-dev
Mateusz Loskot
2016-05-09 09:33:38 UTC
Permalink
Post by Kurt Schwehr
Post by Even Rouault
If we move to a later C++ standard, or even use features of C++98 we currently
don't use, I'd advocate for using things that are obviously making the code
better / more readable. Honestly who finds that
"std::unique_ptr<int *, std::function<void(char *)>> Vals(CPLCalloc(256, 0),
CPLFree);" is obviously more readable, efficient and less error prone than
"std::vector Vals(256,0)" ?
This is cart before the horse but... as fast as I can so expect typos. Now
just think of a ~1K long function or method with tons of instances and lots
of places to bailout successfully or as failures. We have > 9K
free/CPLFree/CPLdelete/CPLDestroys that could be < ~100.
[...]
...the very long story short, your desire is to introduce the RAII idiom
across GDAL codebase. Awesome!
I'm sure 99% of GDAL committers will welcome this idea.
Then, **next** question is how we want to implement it:
using C++11+ features, home-brewed smart pointer class(es), etc.

Upgrading to C++11+ just for the sake of upgrade, makes little sense to me.
Especially if folks are not certain about it, don't use those features daily,
don't feel comfortable...it may cause more harm.

Best regards,
--
Mateusz Loskot, http://mateusz.loskot.net
Kurt Schwehr
2016-05-09 17:28:48 UTC
Permalink
Here is my current take on language standards

- I am working on a C++11/14 C99/11 proposal. I despirately want to be
able to use C++11 to make GDAL more robust
- As it stands I will vote >>>against<<< my proposal any time soon - until
with have a bunch of proposals for changes to GDAL that require new
language versions or someone rewrites my proposal to be much more compelling
- We have lots of work that we can do to make GDAL maintenance / debugging
easier that does not require newer language versions
- We have successfully ( at least in my opinion ) stuck a toe in the C++11
world with CPL_FINAL, CPL_DISALLOW_COPY_ASSIGN, NULL_AS_NULLPTR, and
my std::lock_guard<std::mutex> experiments. We can probably do a bit more
if we are careful.
- I think having an experimental autotest2 C++11/14 only testing tree might
be the way to start. Those who want to can try it out or look through what
is possible and it won't impact the main tree or the existing C++ tests.


I would be happy to start contributing to
https://trac.osgeo.org/gdal/browser/trunk/autotest2, especially if we call
it experimental and I can get help with adding a build system. I have
5000 lines of C++ in 32 test files that mostly cover the port directory
right now. I got hung up on trying to create a working initial version in
a separate github tree. Adding it to the existing svn tree would get me
around that issue (it's an internal work thing). Here is
cpl_string_test.cc... it's super boring.

https://gist.github.com/schwehr/02128959ee78d56b553defa0a527bdf2

It's written using the Google C++ style guide and is based on gunit, gmock
and glog.

- https://google.github.io/styleguide/cppguide.html
- https://github.com/google/googletest
- https://github.com/google/glog
Post by Kurt Schwehr
Post by Even Rouault
If we move to a later C++ standard, or even use features of C++98 we currently
don't use, I'd advocate for using things that are obviously making the code
better / more readable. Honestly who finds that
"std::unique_ptr<int *, std::function<void(char *)>> Vals(CPLCalloc(256, 0),
CPLFree);" is obviously more readable, efficient and less error prone
than
Post by Kurt Schwehr
Post by Even Rouault
"std::vector Vals(256,0)" ?
This is cart before the horse but... as fast as I can so expect typos.
Now
Post by Kurt Schwehr
just think of a ~1K long function or method with tons of instances and
lots
Post by Kurt Schwehr
of places to bailout successfully or as failures. We have > 9K
free/CPLFree/CPLdelete/CPLDestroys that could be < ~100.
[...]
...the very long story short, your desire is to introduce the RAII idiom
across GDAL codebase. Awesome!
I'm sure 99% of GDAL committers will welcome this idea.
using C++11+ features, home-brewed smart pointer class(es), etc.
Upgrading to C++11+ just for the sake of upgrade, makes little sense to me.
Especially if folks are not certain about it, don't use those features daily,
don't feel comfortable...it may cause more harm.
Best regards,
--
Mateusz Loskot, http://mateusz.loskot.net
--
--
http://schwehr.org
Even Rouault
2016-05-09 18:17:09 UTC
Permalink
Post by Kurt Schwehr
Here is my current take on language standards
- I am working on a C++11/14 C99/11 proposal. I despirately want to be
able to use C++11 to make GDAL more robust
C++11 is probably OK, but C++14 support is really "new". For Linux distros, we
should try to make GDAL compilable on the current LTS and probably in the case
of Ubuntu last-1 LTS with their default compiler.

For example RHEL 7 ships with gcc 4.8.X, Ubuntu 14.04 too.
I've checked that gcc 4.8 refuses -std=c++14. It accepts -std=c++1y though, so
some features of C++14 might be available.

At least for the sake of our CI environements : Travis has no immediate plans
for now to ship with with Ubuntu 16.04 ( https://github.com/travis-ci/travis-
ci/issues/5821 )
Post by Kurt Schwehr
- As it stands I will vote >>>against<<< my proposal any time soon - until
with have a bunch of proposals for changes to GDAL that require new
language versions or someone rewrites my proposal to be much more
compelling -
Which proposal exactly ? AFAICS in this thread, it was more about polling
opinions.
Post by Kurt Schwehr
We have lots of work that we can do to make GDAL maintenance
/ debugging easier that does not require newer language versions
- We have successfully ( at least in my opinion ) stuck a toe in the C++11
world with CPL_FINAL, CPL_DISALLOW_COPY_ASSIGN, NULL_AS_NULLPTR, and
my std::lock_guard<std::mutex> experiments. We can probably do a bit more
if we are careful.
- I think having an experimental autotest2 C++11/14 only testing tree might
be the way to start. Those who want to can try it out or look through what
is possible and it won't impact the main tree or the existing C++ tests.
I would be happy to start contributing to
https://trac.osgeo.org/gdal/browser/trunk/autotest2, especially if we call
it experimental and I can get help with adding a build system. I have
5000 lines of C++ in 32 test files that mostly cover the port directory
right now. I got hung up on trying to create a working initial version in
a separate github tree. Adding it to the existing svn tree would get me
around that issue (it's an internal work thing). Here is
cpl_string_test.cc... it's super boring.
https://gist.github.com/schwehr/02128959ee78d56b553defa0a527bdf2
It's written using the Google C++ style guide and is based on gunit, gmock
and glog.
- https://google.github.io/styleguide/cppguide.html
- https://github.com/google/googletest
- https://github.com/google/glog
Are those available as ready to be installable packages ? (thinking about
integration with CI)
Post by Kurt Schwehr
Post by Kurt Schwehr
Post by Even Rouault
If we move to a later C++ standard, or even use features of C++98 we currently
don't use, I'd advocate for using things that are obviously making the code
better / more readable. Honestly who finds that
"std::unique_ptr<int *, std::function<void(char *)>>
Vals(CPLCalloc(256, 0),
CPLFree);" is obviously more readable, efficient and less error prone
than
Post by Kurt Schwehr
Post by Even Rouault
"std::vector Vals(256,0)" ?
This is cart before the horse but... as fast as I can so expect typos.
Now
Post by Kurt Schwehr
just think of a ~1K long function or method with tons of instances and
lots
Post by Kurt Schwehr
of places to bailout successfully or as failures. We have > 9K
free/CPLFree/CPLdelete/CPLDestroys that could be < ~100.
[...]
...the very long story short, your desire is to introduce the RAII idiom
across GDAL codebase. Awesome!
I'm sure 99% of GDAL committers will welcome this idea.
using C++11+ features, home-brewed smart pointer class(es), etc.
Upgrading to C++11+ just for the sake of upgrade, makes little sense to
me. Especially if folks are not certain about it, don't use those
features daily,
don't feel comfortable...it may cause more harm.
Best regards,
--
Mateusz Loskot, http://mateusz.loskot.net
--
Spatialys - Geospatial professional services
http://www.spatialys.com
Kurt Schwehr
2016-05-09 18:38:42 UTC
Permalink
Agreed on the 11 v 14 issues.
Post by Even Rouault
Post by Kurt Schwehr
Here is my current take on language standards
- I am working on a C++11/14 C99/11 proposal. I despirately want to be
able to use C++11 to make GDAL more robust
C++11 is probably OK, but C++14 support is really "new". For Linux distros, we
should try to make GDAL compilable on the current LTS and probably in the case
of Ubuntu last-1 LTS with their default compiler.
For example RHEL 7 ships with gcc 4.8.X, Ubuntu 14.04 too.
I've checked that gcc 4.8 refuses -std=c++14. It accepts -std=c++1y though, so
some features of C++14 might be available.
At least for the sake of our CI environements : Travis has no immediate plans
for now to ship with with Ubuntu 16.04 (
https://github.com/travis-ci/travis-
ci/issues/5821 )
Post by Kurt Schwehr
- As it stands I will vote >>>against<<< my proposal any time soon -
until
Post by Kurt Schwehr
with have a bunch of proposals for changes to GDAL that require new
language versions or someone rewrites my proposal to be much more
compelling -
Which proposal exactly ? AFAICS in this thread, it was more about polling
Post by Even Rouault
opinions.
I have not sent out the doc yet.
Post by Even Rouault
Post by Kurt Schwehr
We have lots of work that we can do to make GDAL maintenance
/ debugging easier that does not require newer language versions
- We have successfully ( at least in my opinion ) stuck a toe in the
C++11
Post by Kurt Schwehr
world with CPL_FINAL, CPL_DISALLOW_COPY_ASSIGN, NULL_AS_NULLPTR, and
my std::lock_guard<std::mutex> experiments. We can probably do a bit
more
Post by Kurt Schwehr
if we are careful.
- I think having an experimental autotest2 C++11/14 only testing tree
might
Post by Kurt Schwehr
be the way to start. Those who want to can try it out or look through
what
Post by Kurt Schwehr
is possible and it won't impact the main tree or the existing C++ tests.
I would be happy to start contributing to
https://trac.osgeo.org/gdal/browser/trunk/autotest2, especially if we
call
Post by Kurt Schwehr
it experimental and I can get help with adding a build system. I have
5000 lines of C++ in 32 test files that mostly cover the port directory
right now. I got hung up on trying to create a working initial version
in
Post by Kurt Schwehr
a separate github tree. Adding it to the existing svn tree would get me
around that issue (it's an internal work thing). Here is
cpl_string_test.cc... it's super boring.
https://gist.github.com/schwehr/02128959ee78d56b553defa0a527bdf2
It's written using the Google C++ style guide and is based on gunit,
gmock
Post by Kurt Schwehr
and glog.
- https://google.github.io/styleguide/cppguide.html
- https://github.com/google/googletest
- https://github.com/google/glog
Are those available as ready to be installable packages ? (thinking about
integration with CI)
The people who maintain gunit/gmock prefer that projects package the gunit
code inside their repos.

git clone ***@github.com:google/googletest.git
cd googletest
find . -type f | wc -l
340

du -hs
8.9M .

e.g. for libais, I just made third_party and put them in side that...

https://github.com/schwehr/libais/tree/master/third_party
Post by Even Rouault
Post by Kurt Schwehr
Post by Kurt Schwehr
Post by Even Rouault
If we move to a later C++ standard, or even use features of C++98 we
currently
don't use, I'd advocate for using things that are obviously making
the
Post by Kurt Schwehr
Post by Kurt Schwehr
Post by Even Rouault
code
better / more readable. Honestly who finds that
"std::unique_ptr<int *, std::function<void(char *)>>
Vals(CPLCalloc(256, 0),
CPLFree);" is obviously more readable, efficient and less error
prone
Post by Kurt Schwehr
than
Post by Kurt Schwehr
Post by Even Rouault
"std::vector Vals(256,0)" ?
This is cart before the horse but... as fast as I can so expect
typos.
Post by Kurt Schwehr
Now
Post by Kurt Schwehr
just think of a ~1K long function or method with tons of instances
and
Post by Kurt Schwehr
lots
Post by Kurt Schwehr
of places to bailout successfully or as failures. We have > 9K
free/CPLFree/CPLdelete/CPLDestroys that could be < ~100.
[...]
...the very long story short, your desire is to introduce the RAII
idiom
Post by Kurt Schwehr
across GDAL codebase. Awesome!
I'm sure 99% of GDAL committers will welcome this idea.
using C++11+ features, home-brewed smart pointer class(es), etc.
Upgrading to C++11+ just for the sake of upgrade, makes little sense to
me. Especially if folks are not certain about it, don't use those
features daily,
don't feel comfortable...it may cause more harm.
Best regards,
--
Mateusz Loskot, http://mateusz.loskot.net
--
Kurt Schwehr
2016-05-09 18:57:23 UTC
Permalink
See also for googletest on travis-ci:

https://github.com/google/googletest/blob/master/.travis.yml

And there is libgtest-dev on ubuntu, but the project stopped doing point
releases a long time ago (~2005).

https://github.com/easylogging/easyloggingpp/blob/master/.travis.yml
https://amodernstory.com/2015/07/27/upgrading-travisci-build-scripts/
Post by Kurt Schwehr
Agreed on the 11 v 14 issues.
Post by Even Rouault
Post by Kurt Schwehr
Here is my current take on language standards
- I am working on a C++11/14 C99/11 proposal. I despirately want to be
able to use C++11 to make GDAL more robust
C++11 is probably OK, but C++14 support is really "new". For Linux distros, we
should try to make GDAL compilable on the current LTS and probably in the case
of Ubuntu last-1 LTS with their default compiler.
For example RHEL 7 ships with gcc 4.8.X, Ubuntu 14.04 too.
I've checked that gcc 4.8 refuses -std=c++14. It accepts -std=c++1y though, so
some features of C++14 might be available.
At least for the sake of our CI environements : Travis has no immediate plans
for now to ship with with Ubuntu 16.04 (
https://github.com/travis-ci/travis-
ci/issues/5821 <https://github.com/travis-ci/travis-ci/issues/5821> )
Post by Kurt Schwehr
- As it stands I will vote >>>against<<< my proposal any time soon -
until
Post by Kurt Schwehr
with have a bunch of proposals for changes to GDAL that require new
language versions or someone rewrites my proposal to be much more
compelling -
Which proposal exactly ? AFAICS in this thread, it was more about polling
Post by Even Rouault
opinions.
I have not sent out the doc yet.
Post by Even Rouault
Post by Kurt Schwehr
We have lots of work that we can do to make GDAL maintenance
/ debugging easier that does not require newer language versions
- We have successfully ( at least in my opinion ) stuck a toe in the
C++11
Post by Kurt Schwehr
world with CPL_FINAL, CPL_DISALLOW_COPY_ASSIGN, NULL_AS_NULLPTR, and
my std::lock_guard<std::mutex> experiments. We can probably do a bit
more
Post by Kurt Schwehr
if we are careful.
- I think having an experimental autotest2 C++11/14 only testing tree
might
Post by Kurt Schwehr
be the way to start. Those who want to can try it out or look through
what
Post by Kurt Schwehr
is possible and it won't impact the main tree or the existing C++ tests.
I would be happy to start contributing to
https://trac.osgeo.org/gdal/browser/trunk/autotest2, especially if we
call
Post by Kurt Schwehr
it experimental and I can get help with adding a build system. I have
5000 lines of C++ in 32 test files that mostly cover the port directory
right now. I got hung up on trying to create a working initial version
in
Post by Kurt Schwehr
a separate github tree. Adding it to the existing svn tree would get me
around that issue (it's an internal work thing). Here is
cpl_string_test.cc... it's super boring.
https://gist.github.com/schwehr/02128959ee78d56b553defa0a527bdf2
It's written using the Google C++ style guide and is based on gunit,
gmock
Post by Kurt Schwehr
and glog.
- https://google.github.io/styleguide/cppguide.html
- https://github.com/google/googletest
- https://github.com/google/glog
Are those available as ready to be installable packages ? (thinking about
integration with CI)
The people who maintain gunit/gmock prefer that projects package the gunit
code inside their repos.
cd googletest
find . -type f | wc -l
340
du -hs
8.9M .
e.g. for libais, I just made third_party and put them in side that...
https://github.com/schwehr/libais/tree/master/third_party
Post by Even Rouault
Post by Kurt Schwehr
Post by Kurt Schwehr
Post by Even Rouault
If we move to a later C++ standard, or even use features of C++98
we
Post by Kurt Schwehr
Post by Kurt Schwehr
Post by Even Rouault
currently
don't use, I'd advocate for using things that are obviously making
the
Post by Kurt Schwehr
Post by Kurt Schwehr
Post by Even Rouault
code
better / more readable. Honestly who finds that
"std::unique_ptr<int *, std::function<void(char *)>>
Vals(CPLCalloc(256, 0),
CPLFree);" is obviously more readable, efficient and less error
prone
Post by Kurt Schwehr
than
Post by Kurt Schwehr
Post by Even Rouault
"std::vector Vals(256,0)" ?
This is cart before the horse but... as fast as I can so expect
typos.
Post by Kurt Schwehr
Now
Post by Kurt Schwehr
just think of a ~1K long function or method with tons of instances
and
Post by Kurt Schwehr
lots
Post by Kurt Schwehr
of places to bailout successfully or as failures. We have > 9K
free/CPLFree/CPLdelete/CPLDestroys that could be < ~100.
[...]
...the very long story short, your desire is to introduce the RAII
idiom
Post by Kurt Schwehr
across GDAL codebase. Awesome!
I'm sure 99% of GDAL committers will welcome this idea.
using C++11+ features, home-brewed smart pointer class(es), etc.
Upgrading to C++11+ just for the sake of upgrade, makes little sense
to
Post by Kurt Schwehr
me. Especially if folks are not certain about it, don't use those
features daily,
don't feel comfortable...it may cause more harm.
Best regards,
--
Mateusz Loskot, http://mateusz.loskot.net
--
--
--
http://schwehr.org
Even Rouault
2016-05-10 11:12:21 UTC
Permalink
I'd say that moving GDAL to GCC 5 and C++11 would be possible but tricky
on RHEL.
A developer still on RHEL 6 can do it and would be able to
put up with the effort considering that they are using such an old system
However a *user* on RHEL 7 has the latest and greatest system available
and would not appreciate the work required.
Since RHEL 7 ships with GCC 4.8 which has C++11 support, that shouldn't be a
problem, would it ? But yes, RHEL 6 would require more work.
--
Spatialys - Geospatial professional services
http://www.spatialys.com
Loading...