Skip to content

Conversation

@mgovers
Copy link
Member

@mgovers mgovers commented Jan 19, 2026

Cherry-picked changes from #1264

Re-opened a new PR as #1264 was superceded by #1266.

This PR is also rebased off main rather than #1241 to allow easier development.

Signed-off-by: Martijn Govers <Martijn.Govers@Alliander.com>
@mgovers mgovers requested a review from TonyXiang8787 January 19, 2026 10:38
@mgovers mgovers self-assigned this Jan 19, 2026
@mgovers mgovers added the feature New feature or request label Jan 19, 2026
Copy link
Member

@TonyXiang8787 TonyXiang8787 left a comment

Choose a reason for hiding this comment

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

Since we are here, please fix the additional problems in the dataset pointer check. Namely for the attribute pointers.

void PGM_dataset_const_add_attribute_buffer(PGM_Handle* handle, PGM_ConstDataset* dataset, char const* component,
char const* attribute, void const* data) {
call_with_catch(handle, [dataset, component, attribute, data] {
safe_ptr_get(cast_to_cpp(dataset))
.add_attribute_buffer(safe_str_view(component), safe_str_view(attribute), safe_ptr(data));
});
}

void PGM_dataset_writable_set_attribute_buffer(PGM_Handle* handle, PGM_WritableDataset* dataset, char const* component,
char const* attribute, void* data) {
call_with_catch(handle, [dataset, component, attribute, data] {
safe_ptr_get(cast_to_cpp(dataset))
.set_attribute_buffer(safe_str_view(component), safe_str_view(attribute), safe_ptr(data));
});
}

void PGM_dataset_mutable_add_attribute_buffer(PGM_Handle* handle, PGM_MutableDataset* dataset, char const* component,
char const* attribute, void* data) {
call_with_catch(handle, [dataset, component, attribute, data] {
safe_ptr_get(cast_to_cpp(dataset))
.add_attribute_buffer(safe_str_view(component), safe_str_view(attribute), safe_ptr(data));
});
}

These data pointers should be allowed to be nullptr, if the total number of the elements in the component is zero. Users may still create such an attribute buffer (e.g. empyt vector or empty span, or empty numpy array) in an automatic way. But the data pointer maybe nullptr which is well defined.

@mgovers
Copy link
Member Author

mgovers commented Jan 20, 2026

Since we are here, please fix the additional problems in the dataset pointer check. Namely for the attribute pointers.

void PGM_dataset_const_add_attribute_buffer(PGM_Handle* handle, PGM_ConstDataset* dataset, char const* component,
char const* attribute, void const* data) {
call_with_catch(handle, [dataset, component, attribute, data] {
safe_ptr_get(cast_to_cpp(dataset))
.add_attribute_buffer(safe_str_view(component), safe_str_view(attribute), safe_ptr(data));
});
}

void PGM_dataset_writable_set_attribute_buffer(PGM_Handle* handle, PGM_WritableDataset* dataset, char const* component,
char const* attribute, void* data) {
call_with_catch(handle, [dataset, component, attribute, data] {
safe_ptr_get(cast_to_cpp(dataset))
.set_attribute_buffer(safe_str_view(component), safe_str_view(attribute), safe_ptr(data));
});
}

void PGM_dataset_mutable_add_attribute_buffer(PGM_Handle* handle, PGM_MutableDataset* dataset, char const* component,
char const* attribute, void* data) {
call_with_catch(handle, [dataset, component, attribute, data] {
safe_ptr_get(cast_to_cpp(dataset))
.add_attribute_buffer(safe_str_view(component), safe_str_view(attribute), safe_ptr(data));
});
}

These data pointers should be allowed to be nullptr, if the total number of the elements in the component is zero. Users may still create such an attribute buffer (e.g. empyt vector or empty span, or empty numpy array) in an automatic way. But the data pointer maybe nullptr which is well defined.

i am implementing that as we speak but it is something we really want to allow? currently, it will introduce segmentation violations EDIT: my test was incorrect. it works as intended

…disallowed

Signed-off-by: Martijn Govers <Martijn.Govers@Alliander.com>
@mgovers mgovers requested a review from TonyXiang8787 January 20, 2026 08:15
@sonarqubecloud
Copy link

@TonyXiang8787 TonyXiang8787 added this pull request to the merge queue Jan 20, 2026
Merged via the queue into main with commit ac3ac75 Jan 20, 2026
31 checks passed
@TonyXiang8787 TonyXiang8787 deleted the feature/minor-refactor-model-cpp branch January 20, 2026 10:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants