1.1 --- a/src/FixedArray.cpp Mon Jun 10 00:46:29 2013 +0100
1.2 +++ b/src/FixedArray.cpp Mon Jun 10 01:04:43 2013 +0100
1.3 @@ -1,78 +1,78 @@
1.4 -/*
1.5 - * Copyright (C) 2012 David Anderson
1.6 - *
1.7 - * This file is part of SourcePawn.
1.8 - *
1.9 - * SourcePawn is free software: you can redistribute it and/or modify it under
1.10 - * the terms of the GNU General Public License as published by the Free
1.11 - * Software Foundation, either version 3 of the License, or (at your option)
1.12 - * any later version.
1.13 - *
1.14 - * SourcePawn is distributed in the hope that it will be useful, but WITHOUT ANY
1.15 - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.16 - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
1.17 - *
1.18 - * You should have received a copy of the GNU General Public License along with
1.19 - * SourcePawn. If not, see http://www.gnu.org/licenses/.
1.20 - */
1.21 -#include <limits.h>
1.22 -#include <string.h>
1.23 -#include "FixedArray.h"
1.24 -#include "Zone.h"
1.25 -#include "Heap-inl.h"
1.26 -
1.27 -using namespace ke;
1.28 -
1.29 -static const unsigned kMaxFixedArrayLength = ((INT_MAX - sizeof(FixedArray)) / sizeof(ke::Object *));
1.30 -
1.31 -FixedArray *
1.32 -FixedArray::New(Zone *zone, unsigned length, Heap::Tenure tenure)
1.33 -{
1.34 - if (length >= kMaxFixedArrayLength) {
1.35 - zone->reportError(Message_ArrayTooBig);
1.36 - return NULL;
1.37 - }
1.38 -
1.39 - Local<FixedArray> array(zone, FixedArray::cast(zone->allocate(MapKind_FixedArray, SizeFor(length), tenure)));
1.40 - if (!array)
1.41 - return NULL;
1.42 -
1.43 - array->length_ = length;
1.44 - memset(array->vec(), 0, length * sizeof(Object *));
1.45 - return array;
1.46 -}
1.47 -
1.48 -ByteArray *
1.49 -ByteArray::New(Zone *zone, unsigned length, Heap::Tenure tenure)
1.50 -{
1.51 - if (length >= kMaxFixedArrayLength) {
1.52 - zone->reportError(Message_ArrayTooBig);
1.53 - return NULL;
1.54 - }
1.55 -
1.56 - Local<ByteArray> array(zone, ByteArray::cast(zone->allocate(MapKind_ByteArray, SizeFor(length), tenure)));
1.57 - if (!array)
1.58 - return NULL;
1.59 -
1.60 - array->length_ = length;
1.61 - memset(array->raw(), 0, length);
1.62 - return array;
1.63 -}
1.64 -
1.65 -ByteArray *
1.66 -ByteArray::New(Zone *zone, Handle<Map> map, unsigned length, Heap::Tenure tenure)
1.67 -{
1.68 - if (length >= kMaxFixedArrayLength) {
1.69 - zone->reportError(Message_ArrayTooBig);
1.70 - return NULL;
1.71 - }
1.72 -
1.73 - Local<ByteArray> array(zone, ByteArray::cast(zone->allocate(map, SizeFor(length), tenure)));
1.74 - if (!array)
1.75 - return NULL;
1.76 -
1.77 - array->length_ = length;
1.78 - memset(array->raw(), 0, length);
1.79 - return array;
1.80 -}
1.81 -
1.82 +/*
1.83 + * Copyright (C) 2012 David Anderson
1.84 + *
1.85 + * This file is part of SourcePawn.
1.86 + *
1.87 + * SourcePawn is free software: you can redistribute it and/or modify it under
1.88 + * the terms of the GNU General Public License as published by the Free
1.89 + * Software Foundation, either version 3 of the License, or (at your option)
1.90 + * any later version.
1.91 + *
1.92 + * SourcePawn is distributed in the hope that it will be useful, but WITHOUT ANY
1.93 + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.94 + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
1.95 + *
1.96 + * You should have received a copy of the GNU General Public License along with
1.97 + * SourcePawn. If not, see http://www.gnu.org/licenses/.
1.98 + */
1.99 +#include <limits.h>
1.100 +#include <string.h>
1.101 +#include "FixedArray.h"
1.102 +#include "Zone.h"
1.103 +#include "Heap-inl.h"
1.104 +
1.105 +using namespace ke;
1.106 +
1.107 +static const unsigned kMaxFixedArrayLength = ((INT_MAX - sizeof(FixedArray)) / sizeof(ke::Object *));
1.108 +
1.109 +FixedArray *
1.110 +FixedArray::New(Zone *zone, unsigned length, Heap::Tenure tenure)
1.111 +{
1.112 + if (length >= kMaxFixedArrayLength) {
1.113 + zone->reportError(Message_ArrayTooBig);
1.114 + return NULL;
1.115 + }
1.116 +
1.117 + Local<FixedArray> array(zone, FixedArray::cast(zone->allocate(MapKind_FixedArray, SizeFor(length), tenure)));
1.118 + if (!array)
1.119 + return NULL;
1.120 +
1.121 + array->length_ = length;
1.122 + memset(array->vec(), 0, length * sizeof(Object *));
1.123 + return array;
1.124 +}
1.125 +
1.126 +ByteArray *
1.127 +ByteArray::New(Zone *zone, unsigned length, Heap::Tenure tenure)
1.128 +{
1.129 + if (length >= kMaxFixedArrayLength) {
1.130 + zone->reportError(Message_ArrayTooBig);
1.131 + return NULL;
1.132 + }
1.133 +
1.134 + Local<ByteArray> array(zone, ByteArray::cast(zone->allocate(MapKind_ByteArray, SizeFor(length), tenure)));
1.135 + if (!array)
1.136 + return NULL;
1.137 +
1.138 + array->length_ = length;
1.139 + memset(array->raw(), 0, length);
1.140 + return array;
1.141 +}
1.142 +
1.143 +ByteArray *
1.144 +ByteArray::New(Zone *zone, Handle<Map> map, unsigned length, Heap::Tenure tenure)
1.145 +{
1.146 + if (length >= kMaxFixedArrayLength) {
1.147 + zone->reportError(Message_ArrayTooBig);
1.148 + return NULL;
1.149 + }
1.150 +
1.151 + Local<ByteArray> array(zone, ByteArray::cast(zone->allocate(map, SizeFor(length), tenure)));
1.152 + if (!array)
1.153 + return NULL;
1.154 +
1.155 + array->length_ = length;
1.156 + memset(array->raw(), 0, length);
1.157 + return array;
1.158 +}
1.159 +