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

use a singleton pattern to register the gdal driver once in one place #4628

Merged
merged 6 commits into from Mar 13, 2024

Conversation

kevinkreiser
Copy link
Member

fixes #4623 (hopefully)

@@ -169,7 +186,7 @@ std::string serializeGeoTIFF(Api& request, const std::shared_ptr<const GriddedDa
char** geotiff_options = NULL;
geotiff_options = CSLSetNameValue(geotiff_options, "COMPRESS", "PACKBITS");

// TODO: check if there's an easy way to only instantiate the driver once
gdal_singleton_t::get();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this first time this is called (per process) the constructor above is called and the driver registration happens. subsequent calls are no-ops

@@ -191,12 +191,15 @@ else()
message(FATAL_ERROR "Required target protobuf::libprotobuf-lite or protobuf::libprotobuf is not defined")
endif()

# gdal
set(gdal_target "")
# unless you said you didnt want gdal we try to turn it on, if we cant we tell you
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i thought it would be better to default turning it ON if we can and if we couldnt we simply report that was the case. if you tell it you definitely dont want it by setting it to OFF then we dont even try

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm but doesn’t OFF still want to pull in GDAL::GDAL in tyr’s cmakelists? That’s what that variable was for, though you could handle that with a cmake expression in tyr as well, that’s probably more explicit than the previous var

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep will do that real quick

Copy link
Member

@nilsnolde nilsnolde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks. Just one question about GDAL=OFF @kevinkreiser . Could even do one CI build without, but no need to either IMO

Copy link
Member

@nilsnolde nilsnolde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I approved from my phone, just seeing one nitty thing. also, can you remove the gtiff driver loading thing in the isochrone.cc test? once that's gone, we know for sure this PR works for the actor.

src/tyr/CMakeLists.txt Outdated Show resolved Hide resolved
@kevinkreiser
Copy link
Member Author

can you remove the gtiff driver loading thing in the isochrone.cc test

ha! yeah i grepped the include and src directories but forgot to grep test!

@nilsnolde
Copy link
Member

Oh jeez I’m really sorry, lousy review: I forgot about the docs in docs/docs/building.md, they still say default is OFF.

Anyways no worries if you don’t feel like it

@@ -355,7 +355,6 @@ void check_raster_edges(size_t x, size_t y, uint16_t* data) {
}

TEST(Isochrones, test_geotiff_output_distance) {
GDALRegister_GTiff();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i dont really like removing these because the tests themselves use gdal directly to load the response from the library. now in this case technically we can remove them because hidden in the source of the serializer we are doing this initialization but the tests (and just in general any calling code) shouldnt know/assume that its preconditions are met by something it calls into. the only way to get around this would be to expose gdal initialization as a public api in the library and have the tests call that but i hate that idea even worse.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I didn’t check that.. I kinda assumed those driver inits were there to make the test work (it wouldn’t have without). That’s true.. anyways, the alternative to test this bit is indeed worse.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the other idea is to leave them there though what i would do is in the suite initialization call it once

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both is fine with me tbh, I get your point, but also think it’ll be fine probably forever ®

@kevinkreiser kevinkreiser merged commit 40ce71b into master Mar 13, 2024
9 checks passed
@kevinkreiser kevinkreiser deleted the kk_initgdalsingleton branch March 13, 2024 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GeoTIFF segfaulting on Mac ARM python bindings
2 participants