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: use type std::size_t for index in Collection element accessors and size() #408

Merged
merged 7 commits into from
Apr 22, 2023

Conversation

c-dilks
Copy link
Contributor

@c-dilks c-dilks commented Apr 20, 2023

BEGINRELEASENOTES

  • fix type inconsistency between Collection::size() and index for const object accessors

ENDRELEASENOTES

fix #406

@tmadlener
Copy link
Collaborator

Thanks for working on this. I think you also have to change the definitions to match here:

{{ class.bare_type }} {{ collection_type }}::operator[](unsigned int index) const {
return {{ class.bare_type }}(m_storage.entries[index]);
}
{{ class.bare_type }} {{ collection_type }}::at(unsigned int index) const {
return {{ class.bare_type }}(m_storage.entries.at(index));
}
Mutable{{ class.bare_type }} {{ collection_type }}::operator[](unsigned int index) {
return Mutable{{ class.bare_type }}(m_storage.entries[index]);
}
Mutable{{ class.bare_type }} {{ collection_type }}::at(unsigned int index) {
return Mutable{{ class.bare_type }}(m_storage.entries.at(index));
}

Copy link
Collaborator

@tmadlener tmadlener left a comment

Choose a reason for hiding this comment

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

Thanks for spotting and fixing this.

@c-dilks
Copy link
Contributor Author

c-dilks commented Apr 20, 2023

Looks like the key4hep CI failure is also happening on master.

I can try to make VectorMembers and OneToManyRelations use size_t here too, but I may need help making sure everything that needs to change is changed.

@tmadlener
Copy link
Collaborator

Looks like the key4hep CI failure is also happening on master.

Yes that is a slightly annoying but known issue, see #403.

@c-dilks
Copy link
Contributor Author

c-dilks commented Apr 20, 2023

All right, I think that's all of them. I didn't bother to change the internal for loops, e.g.,

for (unsigned i = 0; i < value.{{ relation.name }}_size(); ++i) {

since that may be a bit overkill; my main concern was from the user-facing side of the generated C++ code.

I didn't touch any of the SIOBlock code, but at first glance I didn't find any user-facing unsigned types to worry about.

Do we need to add size_t anywhere in this file?

# Types considered to be builtin
BUILTIN_TYPES = ["int", "long", "float", "double",
"unsigned int", "unsigned", "unsigned long",
"char", "short", "bool", "long long",
"unsigned long long"]
# Fixed width types defined in <cstdint>. Omitting int8_t and uint8_t since they
# are often only aliases for signed char and unsigned char, which tends to break
# expectations towards the behavior of integer types. Also omitting the _fastN_t
# and leastN_t since those are probably already covered by the usual integer
# types.
ALLOWED_FIXED_WIDTH_TYPES = ["int16_t", "int32_t", "int64_t",
"uint16_t", "uint32_t", "uint64_t"]

@tmadlener
Copy link
Collaborator

The BUILTIN_TYPES effectively just determine which types can be used in the yaml files to define a datamodel, so I think we don't need size_t in there. At least until someone actually requests it.

Thanks again for going through all the bits and pieces here. Waiting for CI to succeed and then I think this can be merged.

@jmcarcell
Copy link
Member

jmcarcell commented Apr 20, 2023

Maybe std::size_t instead of size_t? I don't have an opinion on that but std::size_t is more C++-like

@tmadlener
Copy link
Collaborator

Good point. I don't have a strong opinion on it either. Strictly speaking #include <cstddef> and std::size_t would probably be the most standard conformant way to do this. For all practical purposes it probably doesn't matter too much, but since we are already here we might as well go ahead and use std::size_t and add the necessary include to the Collection.h.jinja2 template.

@c-dilks
Copy link
Contributor Author

c-dilks commented Apr 21, 2023

Good point. I don't have a strong opinion on it either. Strictly speaking #include <cstddef> and std::size_t would probably be the most standard conformant way to do this. For all practical purposes it probably doesn't matter too much, but since we are already here we might as well go ahead and use std::size_t and add the necessary include to the Collection.h.jinja2 template.

Done in f9880d6.

Do we need #include<cstddef> in Object.h.jinja2 and MutableObject.h.jinja2 too, or anywhere else?

@tmadlener
Copy link
Collaborator

Do we need #include<cstddef> in Object.h.jinja2 and MutableObject.h.jinja2 too, or anywhere else?

Good catch. Those should be the only ones for this PR.

@c-dilks c-dilks changed the title fix: use type size_t for index in Collection element accessors fix: use type std::size_t for index in Collection element accessors and size() Apr 21, 2023
@tmadlener tmadlener merged commit 705721d into AIDASoft:master Apr 22, 2023
@c-dilks c-dilks deleted the collection-accessor-index-type branch April 22, 2023 21:39
tmadlener pushed a commit to tmadlener/podio that referenced this pull request May 4, 2023
…rs and `size()` (AIDASoft#408)

* fix: use type `size_t` for index in `Collection` element accessors

* fix: `unsigned int` -> `size_t` in `Collection.cc.jinja2`

* fix: use `size_t` in `macro multi_relation_handling`

* fix: `size_t` -> `std::size_t`

* fix: add `#include <cstddef>` to `{,Mutable}Object.h.jinja2`
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.

type inconsistency between Collection::size() and index for const object accessors
3 participants