8
8
#include " env-inl.h"
9
9
#include " js_stream.h"
10
10
#include " string_bytes.h"
11
+ #include " util.h"
11
12
#include " util-inl.h"
12
13
#include " v8.h"
13
14
@@ -37,11 +38,6 @@ template int StreamBase::WriteString<LATIN1>(
37
38
const FunctionCallbackInfo<Value>& args);
38
39
39
40
40
- struct Free {
41
- void operator ()(char * ptr) const { free (ptr); }
42
- };
43
-
44
-
45
41
int StreamBase::ReadStartJS (const FunctionCallbackInfo<Value>& args) {
46
42
return ReadStart ();
47
43
}
@@ -127,9 +123,9 @@ int StreamBase::Writev(const FunctionCallbackInfo<Value>& args) {
127
123
}
128
124
}
129
125
130
- std::unique_ptr <char [], Free > storage;
126
+ MallocedBuffer <char > storage;
131
127
if (storage_size > 0 )
132
- storage = std::unique_ptr <char [], Free>( Malloc ( storage_size) );
128
+ storage = MallocedBuffer <char >( storage_size);
133
129
134
130
offset = 0 ;
135
131
if (!all_buffers) {
@@ -145,7 +141,7 @@ int StreamBase::Writev(const FunctionCallbackInfo<Value>& args) {
145
141
146
142
// Write string
147
143
CHECK_LE (offset, storage_size);
148
- char * str_storage = storage.get () + offset;
144
+ char * str_storage = storage.data + offset;
149
145
size_t str_size = storage_size - offset;
150
146
151
147
Local<String> string = chunk->ToString (env->context ()).ToLocalChecked ();
@@ -164,7 +160,7 @@ int StreamBase::Writev(const FunctionCallbackInfo<Value>& args) {
164
160
165
161
StreamWriteResult res = Write (*bufs, count, nullptr , req_wrap_obj);
166
162
SetWriteResultPropertiesOnWrapObject (env, req_wrap_obj, res);
167
- if (res.wrap != nullptr && storage ) {
163
+ if (res.wrap != nullptr && storage_size > 0 ) {
168
164
res.wrap ->SetAllocatedStorage (storage.release (), storage_size);
169
165
}
170
166
return res.err ;
@@ -263,26 +259,26 @@ int StreamBase::WriteString(const FunctionCallbackInfo<Value>& args) {
263
259
CHECK_EQ (count, 1 );
264
260
}
265
261
266
- std::unique_ptr <char [], Free > data;
262
+ MallocedBuffer <char > data;
267
263
268
264
if (try_write) {
269
265
// Copy partial data
270
- data = std::unique_ptr <char [], Free>( Malloc ( buf.len ) );
271
- memcpy (data.get () , buf.base , buf.len );
266
+ data = MallocedBuffer <char >( buf.len );
267
+ memcpy (data.data , buf.base , buf.len );
272
268
data_size = buf.len ;
273
269
} else {
274
270
// Write it
275
- data = std::unique_ptr <char [], Free>( Malloc ( storage_size) );
271
+ data = MallocedBuffer <char >( storage_size);
276
272
data_size = StringBytes::Write (env->isolate (),
277
- data.get () ,
273
+ data.data ,
278
274
storage_size,
279
275
string,
280
276
enc);
281
277
}
282
278
283
279
CHECK_LE (data_size, storage_size);
284
280
285
- buf = uv_buf_init (data.get () , data_size);
281
+ buf = uv_buf_init (data.data , data_size);
286
282
287
283
uv_stream_t * send_handle = nullptr ;
288
284
0 commit comments