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

(many) Support string+bigint and bigint+string concatenation #475

Merged
merged 1 commit into from
May 10, 2024

Conversation

perlun
Copy link
Collaborator

@perlun perlun commented May 9, 2024

No description provided.

@perlun perlun added the experimental compilation Issues which are relevant when using experimental compilation label May 9, 2024
@perlun perlun added this to the 0.5.0 milestone May 9, 2024
@@ -39,7 +59,7 @@ namespace perlang
ASCIIString::~ASCIIString()
{
if (owned_) {
delete[] bytes_;
free((void*)bytes_);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was an oversight in the old code; it worked but.. mixing malloc and delete isn't really a great idea. Either go with malloc+free or new+delete but never a combination of those. Since we are dealing with plain, C-style char* pointers that we then do memcpy and stuff using, I think C-style allocation makes a bit of sense in this case.

@perlun perlun force-pushed the feature/string-and-bigint-concatenation branch from f9246d9 to dcc0d62 Compare May 9, 2024 19:50
memcpy((void*)bytes, str.c_str(), str.length());
memcpy((void*)(bytes + str.length()), rhs.bytes(), rhs.length());
memcpy(bytes, str.c_str(), str.length());
memcpy((bytes + str.length()), rhs.bytes(), rhs.length());
Copy link
Collaborator Author

@perlun perlun May 9, 2024

Choose a reason for hiding this comment

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

(Removed these void* casts both here and in utf8_string.cc. char* can be implicitly cast to void*, so let's perhaps use that fact to make the code a little bit easier on the reader.

@perlun perlun enabled auto-merge (squash) May 9, 2024 19:51
@perlun perlun force-pushed the feature/string-and-bigint-concatenation branch from dcc0d62 to d4ba0d4 Compare May 10, 2024 20:35
@perlun perlun merged commit 0aaf6a2 into master May 10, 2024
11 checks passed
@perlun perlun deleted the feature/string-and-bigint-concatenation branch May 10, 2024 20:39
@perlun perlun added the stdlib Things related to the Perlang API/stdlib label May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
experimental compilation Issues which are relevant when using experimental compilation stdlib Things related to the Perlang API/stdlib
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant