mirror of
https://github.com/gcc-mirror/gcc.git
synced 2024-11-21 13:40:47 +00:00
gccrs: libproc_macro: Fix Tokenstream growth
TokenStream did not copy back enough old data to the new location. This commit also add more explicit memcpy usages in order to facilitate change to utf-8 later. libgrust/ChangeLog: * libproc_macro/ffistring.cc (FFIString::make_ffistring): Add explicit sizeof and utf-8 warning. (FFIString::clone): Add explicit sizeof and utf-8 warning. * libproc_macro/ident.cc (Ident::clone): Likewise. (Ident::make_ident): Likewise. * libproc_macro/tokenstream.cc (TokenStream::grow): Fix vector growth. (TokenStream__clone): Add explicit sizeof. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
This commit is contained in:
parent
22ba7ea9ee
commit
cf58150bea
@ -42,7 +42,8 @@ FFIString
|
||||
FFIString::make_ffistring (const unsigned char *data, std::uint64_t len)
|
||||
{
|
||||
unsigned char *inner = new unsigned char[len];
|
||||
std::memcpy (inner, data, len);
|
||||
// FIXME: UTF-8 Update this with sizeof codepoint instead
|
||||
std::memcpy (inner, data, len * sizeof (unsigned char));
|
||||
return {inner, len};
|
||||
}
|
||||
|
||||
@ -50,7 +51,8 @@ FFIString
|
||||
FFIString::clone () const
|
||||
{
|
||||
unsigned char *inner = new unsigned char[this->len];
|
||||
std::memcpy (inner, this->data, this->len);
|
||||
// FIXME: UTF-8 Update this with sizeof codepoint instead
|
||||
std::memcpy (inner, this->data, this->len * sizeof (unsigned char));
|
||||
return {inner, this->len};
|
||||
}
|
||||
|
||||
|
@ -56,8 +56,9 @@ Ident
|
||||
Ident::clone () const
|
||||
{
|
||||
unsigned char *val = new unsigned char[this->len];
|
||||
std::memcpy (val, this->val, this->len);
|
||||
return {this->is_raw, val, this->len, this->span};
|
||||
// FIXME: UTF-8 Update this with sizeof codepoint instead
|
||||
std::memcpy (val, this->val, this->len * sizeof (char));
|
||||
return {this->is_raw, val, this->len};
|
||||
}
|
||||
|
||||
Ident
|
||||
@ -73,8 +74,9 @@ Ident::make_ident (const unsigned char *str, std::uint64_t len, Span span,
|
||||
bool raw)
|
||||
{
|
||||
unsigned char *val = new unsigned char[len];
|
||||
std::memcpy (val, str, len);
|
||||
return {raw, val, len, span};
|
||||
// FIXME: UTF-8 Update this with sizeof codepoint instead
|
||||
std::memcpy (val, str, len * sizeof (char));
|
||||
return {raw, val, len};
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -51,7 +51,7 @@ TokenStream::grow (std::uint64_t delta)
|
||||
auto new_capacity = capacity + (delta != 0 ? delta : 1);
|
||||
auto *new_data = new TokenTree[new_capacity];
|
||||
capacity = new_capacity;
|
||||
std::memcpy (new_data, data, size);
|
||||
std::memcpy (new_data, data, size * sizeof (TokenTree));
|
||||
delete[] data;
|
||||
data = new_data;
|
||||
}
|
||||
@ -107,7 +107,7 @@ extern "C" TokenStream
|
||||
TokenStream__clone (const TokenStream *ts)
|
||||
{
|
||||
auto *data = new TokenTree[ts->capacity];
|
||||
std::memcpy (data, ts->data, ts->size);
|
||||
std::memcpy (data, ts->data, ts->size * sizeof (TokenTree));
|
||||
return {data, ts->size, ts->capacity};
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user