OLD | NEW |
---|---|
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
269 buffer_[position_] = '\0'; | 269 buffer_[position_] = '\0'; |
270 // Make sure nobody managed to add a 0-character to the | 270 // Make sure nobody managed to add a 0-character to the |
271 // buffer while building the string. | 271 // buffer while building the string. |
272 ASSERT(strlen(buffer_.start()) == static_cast<size_t>(position_)); | 272 ASSERT(strlen(buffer_.start()) == static_cast<size_t>(position_)); |
273 position_ = -1; | 273 position_ = -1; |
274 ASSERT(is_finalized()); | 274 ASSERT(is_finalized()); |
275 return buffer_.start(); | 275 return buffer_.start(); |
276 } | 276 } |
277 | 277 |
278 | 278 |
279 MemoryMappedExternalResource::MemoryMappedExternalResource(const char* filename) | |
280 : filename_(NULL), data_(NULL), length_(0), | |
mnaganov (inactive)
2011/01/16 10:16:02
Please either have a single line of initialization
marklam
2011/01/18 02:49:02
Done.
| |
281 remove_file_on_cleanup_(false) { | |
282 | |
mnaganov (inactive)
2011/01/16 10:16:02
Please remove this redundant empty line.
marklam
2011/01/18 02:49:02
Done.
| |
283 Init(filename); | |
284 } | |
285 | |
286 | |
287 MemoryMappedExternalResource:: | |
288 MemoryMappedExternalResource(const char* filename, | |
289 bool remove_file_on_cleanup) | |
290 : filename_(NULL), data_(NULL), length_(0), | |
291 remove_file_on_cleanup_(remove_file_on_cleanup) { | |
292 | |
293 Init(filename); | |
294 } | |
295 | |
296 | |
297 MemoryMappedExternalResource::~MemoryMappedExternalResource() { | |
298 // Release the resources if we had successfully acquired them: | |
299 if (file_) { | |
300 delete file_; | |
301 | |
mnaganov (inactive)
2011/01/16 10:16:02
I this empty line and the one below a redundant.
marklam
2011/01/18 02:49:02
Done.
| |
302 if (remove_file_on_cleanup_) { | |
303 OS::Remove(filename_); | |
304 } | |
305 | |
306 DeleteArray<char>(filename_); | |
307 } | |
308 } | |
309 | |
310 | |
311 void MemoryMappedExternalResource::Init(const char* filename) { | |
312 file_ = OS::MemoryMappedFile::open(filename); | |
313 if (file_) { | |
314 filename_ = StrDup(filename); | |
315 data_ = reinterpret_cast<char*>(file_->memory()); | |
316 length_ = file_->size(); | |
317 } | |
318 } | |
319 | |
320 | |
321 bool MemoryMappedExternalResource::EnsureIsAscii(bool abort_if_failed) const { | |
322 bool is_ascii = true; | |
323 | |
324 int line_no = 1; | |
325 const char* start_of_line = data_; | |
326 const char* end = data_ + length_; | |
327 for (const char* p = data_; p < end; p++) { | |
328 char c = *p; | |
329 if (c & 0x80) { | |
330 // Non-ascii detected: | |
331 is_ascii = false; | |
332 | |
333 // Report the error and abort if appropriate: | |
334 if (abort_if_failed) { | |
335 int char_no = (p - start_of_line) - 1; | |
336 | |
337 ASSERT(filename_ != NULL); | |
338 PrintF("\n\n\n" | |
339 "Abort: Non-Ascii character 0x%.2x in file %s line %d char %d", | |
340 c, filename_, line_no, char_no); | |
341 | |
342 const char* err_context = p - 10; | |
mnaganov (inactive)
2011/01/16 10:16:02
Please introduce a constant for this magic number.
marklam
2011/01/18 02:49:02
Done.
| |
343 if (err_context < data_) { | |
344 err_context = data_; | |
345 } | |
346 int err_context_length = p - err_context; | |
347 if (err_context_length) { | |
348 char buffer[11]; | |
349 strncpy(buffer, err_context, err_context_length); | |
350 buffer[err_context_length] = '\0'; | |
351 PrintF(" after \"%s\"", buffer); | |
mnaganov (inactive)
2011/01/16 10:16:02
You can use the "precision" field to specify the m
marklam
2011/01/18 02:49:02
Done.
| |
352 } | |
353 PrintF(".\n\n\n"); | |
354 abort(); | |
355 } | |
356 | |
357 break; // Non-ascii detected. No need to continue scanning. | |
358 } | |
359 if (c == '\n') { | |
360 start_of_line = p; | |
361 line_no++; | |
362 } | |
363 } | |
364 | |
365 return is_ascii; | |
366 } | |
367 | |
368 | |
279 } } // namespace v8::internal | 369 } } // namespace v8::internal |
OLD | NEW |