Add WIN32 define for MSVC builds.
1 /* vim: set ts=4 sw=4 tw=99 et:
3 * Copyright (C) 2012 David Anderson
5 * This file is part of SourcePawn.
7 * SourcePawn is free software: you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License as published by the Free
9 * Software Foundation, either version 3 of the License, or (at your option)
12 * SourcePawn is distributed in the hope that it will be useful, but WITHOUT ANY
13 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with
17 * SourcePawn. If not, see http://www.gnu.org/licenses/.
19 #ifndef _include_sp2_list_h_
20 #define _include_sp2_list_h_
23 #include "FixedArray.h"
26 #include "Handles-inl.h"
31 class List : public Object
34 static List *New(Zone *zone, Heap::Tenure tenure = Heap::Tenure_Default) {
35 Local<List> list(zone, List::cast(zone->allocate(MapKind_List, sizeof(List), tenure)));
45 bool append(Zone *zone, Handle<T> obj) {
46 Local<List> list(zone, this);
47 if (!Grow(zone, list, 1))
50 list->array_->set(zone, list->length_, obj);
56 return T::cast(array_->at(i));
64 static bool Grow(Zone *zone, Handle<List> list, unsigned amount) {
65 if (!IsUint32AddSafe(list->length(), amount)) {
66 zone->reportAllocationOverflow();
70 unsigned newlen = list->length() + amount;
71 if (list->array_ && newlen < list->array_->length())
74 unsigned maxsize = list->array_ ? list->array_->length() : 8;
75 if (!IsUint32AddSafe(maxsize, amount)) {
76 zone->reportAllocationOverflow();
80 while (newlen > maxsize) {
81 if (!IsUint32MultiplySafe(maxsize, 2)) {
82 zone->reportAllocationOverflow();
88 Local<FixedArray> array(zone, FixedArray::New(zone, maxsize, Heap::Tenure_Default));
92 for (unsigned i = 0; i < list->length_; i++)
93 array->set(zone, i, list->array_->at(i));
101 // Begin GC descriptor.
102 static inline size_t offsetOfArray() {
103 return OFFSETOF(List, array_);
105 // End GC descriptor.
107 static inline List *cast(Object *obj) {
108 assert(!obj || obj->is(MapKind_List));
109 return reinterpret_cast<List *>(obj);
119 #endif // _include_sp2_list_h_