Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: utils/archive/utils.dart

Issue 10825139: Free the C memory for ArchiveInputStream when the stream is garbage collected. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix a renamed function Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #library("utils"); 5 #library("utils");
6 6
7 #import("dart-ext:dart_archive"); 7 #import("dart-ext:dart_archive");
8 #import("dart:isolate"); 8 #import("dart:isolate");
9 #import("archive.dart", prefix: "archive"); 9 #import("archive.dart", prefix: "archive");
10 10
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 } 51 }
52 52
53 /** Converts [input] to a [Uint8List] that C can process easily. */ 53 /** Converts [input] to a [Uint8List] that C can process easily. */
54 Uint8List bytesForC(List<int> input) { 54 Uint8List bytesForC(List<int> input) {
55 var list = new Uint8List(input.length); 55 var list = new Uint8List(input.length);
56 list.setRange(0, input.length, input); 56 list.setRange(0, input.length, input);
57 return list; 57 return list;
58 } 58 }
59 59
60 /** 60 /**
61 * Attaches [callback] as a finalizer for [object]. After [object] has been
62 * garbage collected, [callback] will be called and passed [peer] as an
63 * argument.
64 *
65 * Neither [callback] nor [peer] should contain any references to [object];
66 * otherwise, [object] will never be collected and [callback] will never be
67 * called.
68 */
69 void attachFinalizer(object, void callback(peer), [peer])
70 native "Archive_AttachFinalizer";
71
72 /**
73 * A reference to a single value.
74 *
75 * This is primarily meant to be used when a finalizer needs to refer to a field
76 * on the object being finalized that may be set to null during the lifetime of
77 * the object. Since the object itself has been garbage collected once the
78 * finalizer runs, it needs a second-order reference to check if the field is
79 * null.
80 */
81 class Reference<E> {
82 E value;
83 Reference(this.value);
84 }
85
86 /**
61 * Returns a [Future] that completes immediately upon hitting the event loop. 87 * Returns a [Future] that completes immediately upon hitting the event loop.
62 */ 88 */
63 Future async() { 89 Future async() {
64 var completer = new Completer(); 90 var completer = new Completer();
65 new Timer(0, (_) => completer.complete(null)); 91 new Timer(0, (_) => completer.complete(null));
66 return completer.future; 92 return completer.future;
67 } 93 }
68 94
69 /** An error raised by the archive library. */ 95 /** An error raised by the archive library. */
70 class ArchiveException implements archive.ArchiveException { 96 class ArchiveException implements archive.ArchiveException {
71 /** A description of the error that occurred. */ 97 /** A description of the error that occurred. */
72 final String message; 98 final String message;
73 99
74 /** The error code for the error, or null. */ 100 /** The error code for the error, or null. */
75 final int errno; 101 final int errno;
76 102
77 ArchiveException(this.message, [this.errno]); 103 ArchiveException(this.message, [this.errno]);
78 104
79 String toString() { 105 String toString() {
80 if (errno == null) return "Archive error: $message"; 106 if (errno == null) return "Archive error: $message";
81 return "Archive error $errno: $message"; 107 return "Archive error $errno: $message";
82 } 108 }
83 } 109 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698