Comments (11)
Although maybe it's more correct to "chomp" the returned vector.
from sketchup-api-c-wrapper.
No, as long as it works without the extra character, we can get rid of it. Please test and make a pull request.
from sketchup-api-c-wrapper.
That vector
or char
is fed to SUStringGetUTF8
which expects char*
. Further more the documentation describe:
This function does not allocate memory. You must provide an array of sufficient length to get the entire string. The output string will be NULL terminated.
The +1 to the vector size is to ensure enough memory is allocated.
std::string
is then receiving a NULL terminated char*
- which is standard way to represent a string in C. It knows to stop at NULL. No need to "chomp".
Unless anyone is seeing incorrect string lengths returned? (That would be a good case for setting up in a test unit.)
from sketchup-api-c-wrapper.
I am seeing an extra char - that's why I brought it up.
from sketchup-api-c-wrapper.
It may bot be the null terminator, but I do get some extra thing at the end of a string. This image is from windows command line using less.exe pager. So some maybe binary thing there - no time now to investigate.
from sketchup-api-c-wrapper.
hmm...
That would be junk uninitialised data. Might be the creation of the vector;
std::vector<char> char_array(out_length);
Does it change if it's all initialized to null?
std::vector<char> char_array(out_length, 0);
Let me use that as a sample for the unit tests I'm scaffolding.
from sketchup-api-c-wrapper.
BTW the GetString()
function you postyed has the same issue.
from sketchup-api-c-wrapper.
I'm seeing that the std::string
's size is one larger and contain a NULL byte:
I'll investigate closer.
from sketchup-api-c-wrapper.
Ah, it was this line:
That copies all the bytes, including NULL bytes.
Replacing it with std::string str(char_array.data());
made it scan and stop at the NULL terminator.
However, that prevents String from representing binary data.
Maybe it's better to keep using begin()
and end()
but omit trying to read the extra NULL termination.
from sketchup-api-c-wrapper.
On second though, SUStringSetUTF8
relies on NULL termination, so there is no way it can represent binary data.
I'll switch to .data()
and include it in my test unit PR.
from sketchup-api-c-wrapper.
Btw Jim, those weird characters were probably a result of Release mode uninitialized char
in the vector. In Debug it looks to init to 0 - but Debug allocate memory differently.
from sketchup-api-c-wrapper.
Related Issues (20)
- Question about ctgmath and tgmath.h HOT 3
- Removing member variables of derived classes - single_member branch HOT 3
- Consider using a .editorconfig file HOT 4
- No Visual Studio / XCode project/solutions? HOT 13
- Test units - GoogleTest
- Type checking for TypedValue getters? HOT 6
- TypedValue::bool_value() HOT 4
- Question on SUStringRelease for a vector<SUStringRef> HOT 3
- Natviz for Wrapper objects HOT 2
- Expected behaviour of Radians roll-around? HOT 4
- Warnings: Returning address of local variable HOT 7
- Raise error level
- Editor Config with CMake? HOT 1
- CMake configuration for XCode HOT 6
- Reading TypedValue Arrays from a Model HOT 5
- When to check for validity of parameters, and when not to HOT 4
- Function that returns a list of all verticeswith their correct transforms. HOT 1
- Destructors and inheritance; risk of UB HOT 5
- [[maybe_unused]] an alternative to _unused HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sketchup-api-c-wrapper.