Get length of a string variable using the C interface? #4800
-
|
To read a string variable using the C interface, I need (I think) to pre-allocate a |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 2 replies
-
|
Hmm. This appears to be a feature gap in the C api. For many of the functions that return strings (like adios2_variable_type_string()), you call the function with a NULL buffer pointer first to get the size filled in, then call it again with a properly allocated buffer. This is not possible with the simple adios2_get() API that is used for string variables. The only reasonable workaround I can suggest is to use a buffer that you know is large enough. That's not a great answer, but it's the only thing I can think of at the moment. |
Beta Was this translation helpful? Give feedback.
-
|
That is unfortunate. I asked the question because I'm trying to fix a segfault due to a file I have where the string is longer than a buffer size hard-coded in a package (that's not mine!). If I managed to write a PR for a new function like |
Beta Was this translation helpful? Give feedback.
-
|
I've got a PR on this problem already in the queue. You're welcome to snag it in the interim to try. |
Beta Was this translation helpful? Give feedback.
-
|
OK, PR #4801 that addressed this issue has been merged with master. It will appear in release 2.12 when that happens (not yet scheduled). |
Beta Was this translation helpful? Give feedback.
-
|
@eisenhauer is there the same issue for an attribute whose value is a string? I'm looking at |
Beta Was this translation helpful? Give feedback.
-
|
Oy. Yes, it seems that the same issue exists for attributes. I should have noticed that too. And unfortunately it's worse because because attributes can be an array of strings (for some reason that I'm sure seemed good at the time). Sigh. Let me see about extending the fix. |
Beta Was this translation helpful? Give feedback.
Hmm. This appears to be a feature gap in the C api. For many of the functions that return strings (like adios2_variable_type_string()), you call the function with a NULL buffer pointer first to get the size filled in, then call it again with a properly allocated buffer. This is not possible with the simple adios2_get() API that is used for string variables. The only reasonable workaround I can suggest is to use a buffer that you know is large enough. That's not a great answer, but it's the only thing I can think of at the moment.