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

Fix parquet_field_list read_func lambda capture invalid this pointer #16440

Merged
merged 3 commits into from
Jul 31, 2024

Conversation

davidwendt
Copy link
Contributor

Description

Fixes internal parquet_field_list subclass constructors capturing invalid this pointer when passing objects to std::make_tuple. The std::make_tuple usage creates a parameter object that is constructed, moved, and destroyed. The this pointer is captured during constructor call. The move constructor is called which creates its own separate this pointer (all member data is moved/copied appropriately). The original this pointer is invalidated by the following destructor. The lambda that was captured in the constructor no longer contains a valid this value in the final moved object.

This PR removes the dependency on the this pointer in the lambda and captures the vector reference instead which is preserved correctly in the object move. The ctor, move, dtor pattern occurs because of how std::make_tuple is implemented by the standard library.

Closes #16408

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@davidwendt davidwendt added bug Something isn't working 3 - Ready for Review Ready for review by team libcudf Affects libcudf (C++/CUDA) code. non-breaking Non-breaking change labels Jul 30, 2024
@davidwendt davidwendt self-assigned this Jul 30, 2024
@davidwendt davidwendt requested a review from a team as a code owner July 30, 2024 20:25
@davidwendt davidwendt requested review from ttnghia and zpuller and removed request for a team July 30, 2024 20:25
@bdice
Copy link
Contributor

bdice commented Jul 31, 2024

Thank you for the fix and the detailed writeup @davidwendt. Here is a cookie expressing my gratitude. 🍪

Copy link
Contributor

@vyasr vyasr left a comment

Choose a reason for hiding this comment

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

One question, but I don't need to review again.

@@ -137,10 +137,10 @@ class parquet_field_bool : public parquet_field {
struct parquet_field_bool_list : public parquet_field_list<bool, FieldType::BOOLEAN_TRUE> {
parquet_field_bool_list(int f, std::vector<bool>& v) : parquet_field_list(f, v)
{
auto const read_value = [this](uint32_t i, CompactProtocolReader* cpr) {
auto const read_value = [&val = v](uint32_t i, CompactProtocolReader* cpr) mutable {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you need the mutable keyword? You're capturing by reference so I would have assumed not.

Copy link
Member

Choose a reason for hiding this comment

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

Exactly, I wanted to ask the same question otherwise LGTM

Copy link
Member

Choose a reason for hiding this comment

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

Same comment as Yunsong here

Copy link
Contributor Author

@davidwendt davidwendt Jul 31, 2024

Choose a reason for hiding this comment

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

The mutable specifier is defined here: https://en.cppreference.com/w/cpp/language/lambda

mutable Allows body to modify the objects captured by copy, and to call their non-const member functions.

I added the specifier since all of the lambdas call non-const member functions on val.
But I tried compiling it without the specifier and the 12.3 compiler seemed ok so I can technically remove it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Since you're capturing val by reference, not by copy, I don't think it's necessary. Not a big deal though.

@AyodeAwe AyodeAwe merged commit ed5e4aa into rapidsai:branch-24.08 Jul 31, 2024
78 of 79 checks passed
@davidwendt davidwendt deleted the fix-reader-lambda-capture branch July 31, 2024 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3 - Ready for Review Ready for review by team bug Something isn't working libcudf Affects libcudf (C++/CUDA) code. non-breaking Non-breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants