This repository was archived by the owner on Nov 5, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +7
-21
lines changed
Expand file tree Collapse file tree 3 files changed +7
-21
lines changed Original file line number Diff line number Diff line change @@ -16,10 +16,6 @@ namespace lib_ruby_parser
1616
1717 Bytes::~Bytes ()
1818 {
19- if (borrowed)
20- {
21- return ;
22- }
2319 if (size_ != 0 && bytes_ != nullptr )
2420 {
2521 free (bytes_);
@@ -59,11 +55,9 @@ namespace lib_ruby_parser
5955 {
6056 this ->size_ = other.size_ ;
6157 this ->bytes_ = other.bytes_ ;
62- this ->borrowed = other.borrowed ;
6358
6459 other.size_ = 0 ;
6560 other.bytes_ = nullptr ;
66- other.borrowed = true ;
6761 }
6862
6963 Bytes &Bytes::operator =(Bytes &&other)
@@ -74,11 +68,9 @@ namespace lib_ruby_parser
7468 }
7569 this ->size_ = other.size_ ;
7670 this ->bytes_ = other.bytes_ ;
77- this ->borrowed = other.borrowed ;
7871
7972 other.size_ = 0 ;
8073 other.bytes_ = nullptr ;
81- other.borrowed = true ;
8274
8375 return *this ;
8476 }
@@ -129,9 +121,10 @@ namespace lib_ruby_parser
129121 return byte_ptr_to_owned_string (utf8_ptr);
130122 }
131123
132- void Bytes::mark_borrowed ()
124+ void Bytes::nullify ()
133125 {
134- this ->borrowed = true ;
126+ this ->bytes_ = nullptr ;
127+ this ->size_ = 0 ;
135128 }
136129
137130 bool Bytes::operator ==(const Bytes &other)
Original file line number Diff line number Diff line change @@ -17,11 +17,6 @@ namespace lib_ruby_parser
1717 // Size of the byte sequence
1818 uint32_t size_;
1919
20- // Indicates that Bytes are "borrowed",
21- // when set to true disables cleanup in destructor.
22- // TODO: remove this hack by making a cleanup on all call sites.
23- bool borrowed = false ;
24-
2520 public:
2621 // Destructor
2722 ~Bytes ();
@@ -65,9 +60,7 @@ namespace lib_ruby_parser
6560 // Invalid UTF-8 bytes are replaced with a special REPLACEMENT char.
6661 std::string to_string_lossy () const ;
6762
68- // Marks `this` as borrowed, so that destructor will not free the inner pointer.
69- // TODO: remove this hack.
70- void mark_borrowed ();
63+ void nullify ();
7164
7265 bool operator ==(const Bytes &other);
7366 bool operator ==(const std::string &other);
Original file line number Diff line number Diff line change @@ -108,9 +108,9 @@ namespace lib_ruby_parser
108108 {
109109 auto encoding = std::string (encoding_ptr.ptr , encoding_ptr.size );
110110 auto input = Bytes ((char *)input_ptr.ptr , input_ptr.size );
111- input.mark_borrowed ();
112111
113- auto cpp_result = decoder->rewrite (encoding, std::move (input));
112+ auto cpp_result = decoder->rewrite (encoding, input);
113+ input.nullify ();
114114
115115 if (std::holds_alternative<Bytes>(cpp_result.data ))
116116 {
@@ -217,9 +217,9 @@ namespace lib_ruby_parser
217217 {
218218 auto token = token_from_raw_token (raw_token);
219219 auto input = Bytes (input_ptr);
220- input.mark_borrowed ();
221220
222221 auto cpp_result = rewriter->rewrite_token (token, input);
222+ input.nullify ();
223223
224224 RawTokenRewriterResult c_result;
225225
You can’t perform that action at this time.
0 commit comments