Make amtl headers BSD-licensed and clean up outstanding style issues.

This commit is contained in:
David Anderson 2013-08-22 17:11:17 -07:00
parent c373527851
commit d6a6194e68
10 changed files with 261 additions and 185 deletions

View File

@ -1,29 +1,41 @@
/* vim: set ts=2 sw=2 tw=99 et: // vim: set sts=8 ts=2 sw=2 tw=99 et:
* //
* Copyright (C) 2012 David Anderson // Copyright (C) 2013, David Anderson and AlliedModders LLC
* // All rights reserved.
* This file is part of SourcePawn. //
* // Redistribution and use in source and binary forms, with or without
* SourcePawn is free software: you can redistribute it and/or modify it under // modification, are permitted provided that the following conditions are met:
* the terms of the GNU General Public License as published by the Free //
* Software Foundation, either version 3 of the License, or (at your option) // * Redistributions of source code must retain the above copyright notice, this
* any later version. // list of conditions and the following disclaimer.
* // * Redistributions in binary form must reproduce the above copyright notice,
* SourcePawn is distributed in the hope that it will be useful, but WITHOUT ANY // this list of conditions and the following disclaimer in the documentation
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS // and/or other materials provided with the distribution.
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // * Neither the name of AlliedModders LLC nor the names of its contributors
* // may be used to endorse or promote products derived from this software
* You should have received a copy of the GNU General Public License along with // without specific prior written permission.
* SourcePawn. If not, see http://www.gnu.org/licenses/. //
*/ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
#ifndef _include_sourcepawn_allocatorpolicies_h_ // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
#define _include_sourcepawn_allocatorpolicies_h_ // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#ifndef _include_amtl_allocatorpolicies_h_
#define _include_amtl_allocatorpolicies_h_
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
namespace ke { namespace ke {
// The default system allocator policy will crash on out-of-memory.
class SystemAllocatorPolicy class SystemAllocatorPolicy
{ {
protected: protected:
@ -50,4 +62,4 @@ class SystemAllocatorPolicy
} }
#endif // _include_sourcepawn_allocatorpolicies_h_ #endif // _include_amtl_allocatorpolicies_h_

View File

@ -1,36 +1,39 @@
/** // vim: set sts=8 ts=2 sw=2 tw=99 et:
* vim: set sts=2 ts=8 sw=2 tw=99 noet : //
* ============================================================================= // Copyright (C) 2013, David Anderson and AlliedModders LLC
* SourcePawn // All rights reserved.
* Copyright (C) 2004-2009 AlliedModders LLC. All rights reserved. //
* ============================================================================= // Redistribution and use in source and binary forms, with or without
* // modification, are permitted provided that the following conditions are met:
* This program is free software; you can redistribute it and/or modify it under //
* the terms of the GNU General Public License, version 3.0, as published by the // * Redistributions of source code must retain the above copyright notice, this
* Free Software Foundation. // list of conditions and the following disclaimer.
* // * Redistributions in binary form must reproduce the above copyright notice,
* This program is distributed in the hope that it will be useful, but WITHOUT // this list of conditions and the following disclaimer in the documentation
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS // and/or other materials provided with the distribution.
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more // * Neither the name of AlliedModders LLC nor the names of its contributors
* details. // may be used to endorse or promote products derived from this software
* // without specific prior written permission.
* You should have received a copy of the GNU General Public License along with //
* this program. If not, see <http://www.gnu.org/licenses/>. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* As a special exception, AlliedModders LLC gives you permission to link the // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* code of this program (as well as its derivative works) to "Half-Life 2," the // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* by the Valve Corporation. You must obey the GNU General Public License in // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* all respects for all other code used. Additionally, AlliedModders LLC grants // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* this exception to all derivative works. AlliedModders LLC defines further // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* or <http://www.sourcemod.net/license.php>. // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
*/ // POSSIBILITY OF SUCH DAMAGE.
#ifndef _include_sourcepawn_inline_list_h_
#define _include_sourcepawn_inline_list_h_ #ifndef _include_amtl_inline_list_h_
#define _include_amtl_inline_list_h_
#include <stddef.h> #include <stddef.h>
namespace ke {
template <typename T> class InlineList; template <typename T> class InlineList;
template <typename T> template <typename T>
@ -133,5 +136,7 @@ class InlineList
} }
}; };
#endif // _include_sourcepawn_inline_list_h_ }
#endif // _include_amtl_inline_list_h_

View File

@ -1,21 +1,34 @@
// vim: set ts=8 sts=2 sw=2 tw=99 et: // vim: set sts=8 ts=2 sw=2 tw=99 et:
// //
// This file is part of SourcePawn. // Copyright (C) 2013, David Anderson and AlliedModders LLC
// All rights reserved.
// //
// SourcePawn is free software: you can redistribute it and/or modify // Redistribution and use in source and binary forms, with or without
// it under the terms of the GNU General Public License as published by // modification, are permitted provided that the following conditions are met:
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// //
// SourcePawn is distributed in the hope that it will be useful, // * Redistributions of source code must retain the above copyright notice, this
// but WITHOUT ANY WARRANTY; without even the implied warranty of // list of conditions and the following disclaimer.
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // * Redistributions in binary form must reproduce the above copyright notice,
// GNU General Public License for more details. // this list of conditions and the following disclaimer in the documentation
// // and/or other materials provided with the distribution.
// You should have received a copy of the GNU General Public License // * Neither the name of AlliedModders LLC nor the names of its contributors
// along with SourcePawn. If not, see <http://www.gnu.org/licenses/>. // may be used to endorse or promote products derived from this software
#ifndef _include_sourcepawn_thread_posix_h_ // without specific prior written permission.
#define _include_sourcepawn_thread_posix_h_ //
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#ifndef _include_amtl_thread_posix_h_
#define _include_amtl_thread_posix_h_
#include <pthread.h> #include <pthread.h>
#include <sys/time.h> #include <sys/time.h>
@ -196,5 +209,5 @@ class Thread
} // namespace ke } // namespace ke
#endif // _include_sourcepawn_thread_posix_h_ #endif // _include_amtl_thread_posix_h_

View File

@ -1,21 +1,34 @@
// vim: set ts=8 sts=2 sw=2 tw=99 et: // vim: set sts=8 ts=2 sw=2 tw=99 et:
// //
// This file is part of SourcePawn. // Copyright (C) 2013, David Anderson and AlliedModders LLC
// All rights reserved.
// //
// SourcePawn is free software: you can redistribute it and/or modify // Redistribution and use in source and binary forms, with or without
// it under the terms of the GNU General Public License as published by // modification, are permitted provided that the following conditions are met:
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// //
// SourcePawn is distributed in the hope that it will be useful, // * Redistributions of source code must retain the above copyright notice, this
// but WITHOUT ANY WARRANTY; without even the implied warranty of // list of conditions and the following disclaimer.
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // * Redistributions in binary form must reproduce the above copyright notice,
// GNU General Public License for more details. // this list of conditions and the following disclaimer in the documentation
// // and/or other materials provided with the distribution.
// You should have received a copy of the GNU General Public License // * Neither the name of AlliedModders LLC nor the names of its contributors
// along with SourcePawn. If not, see <http://www.gnu.org/licenses/>. // may be used to endorse or promote products derived from this software
#ifndef _include_sourcepawn_threads_ // without specific prior written permission.
#define _include_sourcepawn_threads_ //
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#ifndef _include_amtl_threads_
#define _include_amtl_threads_
#include <assert.h> #include <assert.h>
#if defined(_MSC_VER) #if defined(_MSC_VER)
@ -249,4 +262,4 @@ class IRunnable
# include "am-thread-posix.h" # include "am-thread-posix.h"
#endif #endif
#endif // _include_sourcepawn_threads_ #endif // _include_amtl_threads_

View File

@ -1,21 +1,34 @@
// vim: set ts=8 sts=2 sw=2 tw=99 et: // vim: set sts=8 ts=2 sw=2 tw=99 et:
// //
// This file is part of SourcePawn. // Copyright (C) 2013, David Anderson and AlliedModders LLC
// All rights reserved.
// //
// SourcePawn is free software: you can redistribute it and/or modify // Redistribution and use in source and binary forms, with or without
// it under the terms of the GNU General Public License as published by // modification, are permitted provided that the following conditions are met:
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// //
// SourcePawn is distributed in the hope that it will be useful, // * Redistributions of source code must retain the above copyright notice, this
// but WITHOUT ANY WARRANTY; without even the implied warranty of // list of conditions and the following disclaimer.
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // * Redistributions in binary form must reproduce the above copyright notice,
// GNU General Public License for more details. // this list of conditions and the following disclaimer in the documentation
// // and/or other materials provided with the distribution.
// You should have received a copy of the GNU General Public License // * Neither the name of AlliedModders LLC nor the names of its contributors
// along with SourcePawn. If not, see <http://www.gnu.org/licenses/>. // may be used to endorse or promote products derived from this software
#ifndef _include_sourcepawn_thread_windows_h_ // without specific prior written permission.
#define _include_sourcepawn_thread_windows_h_ //
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#ifndef _include_amtl_thread_windows_h_
#define _include_amtl_thread_windows_h_
#include <windows.h> #include <windows.h>
@ -145,4 +158,4 @@ class Thread
} // namespace ke } // namespace ke
#endif // _include_sourcepawn_thread_windows_h_ #endif // _include_amtl_thread_windows_h_

View File

@ -1,23 +1,34 @@
/* vim: set ts=4 sw=4 tw=99 et: // vim: set sts=8 ts=2 sw=2 tw=99 et:
* //
* Copyright (C) 2012-2013 David Anderson // Copyright (C) 2013, David Anderson and AlliedModders LLC
* // All rights reserved.
* This file is part of SourcePawn. //
* // Redistribution and use in source and binary forms, with or without
* SourcePawn is free software: you can redistribute it and/or modify it under // modification, are permitted provided that the following conditions are met:
* the terms of the GNU General Public License as published by the Free //
* Software Foundation, either version 3 of the License, or (at your option) // * Redistributions of source code must retain the above copyright notice, this
* any later version. // list of conditions and the following disclaimer.
* // * Redistributions in binary form must reproduce the above copyright notice,
* SourcePawn is distributed in the hope that it will be useful, but WITHOUT ANY // this list of conditions and the following disclaimer in the documentation
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS // and/or other materials provided with the distribution.
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // * Neither the name of AlliedModders LLC nor the names of its contributors
* // may be used to endorse or promote products derived from this software
* You should have received a copy of the GNU General Public License along with // without specific prior written permission.
* SourcePawn. If not, see http://www.gnu.org/licenses/. //
*/ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
#ifndef _include_jitcraft_utility_h_ // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
#define _include_jitcraft_utility_h_ // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#ifndef _include_amtl_utility_h_
#define _include_amtl_utility_h_
#include <assert.h> #include <assert.h>
#include <stddef.h> #include <stddef.h>
@ -306,8 +317,6 @@ Max(const T &t1, const T &t2)
return t1 > t2 ? t1 : t2; return t1 > t2 ? t1 : t2;
} }
#define OFFSETOF(Class, Member) reinterpret_cast<size_t>(&((Class *)NULL)->Member)
#if defined(_MSC_VER) #if defined(_MSC_VER)
# define KE_SIZET_FMT "%Iu" # define KE_SIZET_FMT "%Iu"
#elif defined(__GNUC__) #elif defined(__GNUC__)
@ -324,4 +333,4 @@ Max(const T &t1, const T &t2)
} }
#endif // _include_jitcraft_utility_h_ #endif // _include_amtl_utility_h_

View File

@ -1,21 +1,32 @@
/* vim: set ts=2 sw=2 tw=99 et: // vim: set sts=8 ts=2 sw=2 tw=99 et:
* //
* Copyright (C) 2012 David Anderson // Copyright (C) 2013, David Anderson and AlliedModders LLC
* // All rights reserved.
* This file is part of SourcePawn. //
* // Redistribution and use in source and binary forms, with or without
* SourcePawn is free software: you can redistribute it and/or modify it under // modification, are permitted provided that the following conditions are met:
* the terms of the GNU General Public License as published by the Free //
* Software Foundation, either version 3 of the License, or (at your option) // * Redistributions of source code must retain the above copyright notice, this
* any later version. // list of conditions and the following disclaimer.
* // * Redistributions in binary form must reproduce the above copyright notice,
* SourcePawn is distributed in the hope that it will be useful, but WITHOUT ANY // this list of conditions and the following disclaimer in the documentation
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS // and/or other materials provided with the distribution.
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // * Neither the name of AlliedModders LLC nor the names of its contributors
* // may be used to endorse or promote products derived from this software
* You should have received a copy of the GNU General Public License along with // without specific prior written permission.
* SourcePawn. If not, see http://www.gnu.org/licenses/. //
*/ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#ifndef _INCLUDE_KEIMA_TPL_CPP_VECTOR_H_ #ifndef _INCLUDE_KEIMA_TPL_CPP_VECTOR_H_
#define _INCLUDE_KEIMA_TPL_CPP_VECTOR_H_ #define _INCLUDE_KEIMA_TPL_CPP_VECTOR_H_
@ -31,9 +42,9 @@ class Vector : public AllocPolicy
{ {
public: public:
Vector(AllocPolicy = AllocPolicy()) Vector(AllocPolicy = AllocPolicy())
: data(NULL), : data_(NULL),
nitems(0), nitems_(0),
maxsize(0) maxsize_(0)
{ {
} }
@ -44,23 +55,23 @@ class Vector : public AllocPolicy
void steal(Vector &other) { void steal(Vector &other) {
zap(); zap();
data = other.data; data_ = other.data_;
nitems = other.nitems; nitems_ = other.nitems_;
maxsize = other.maxsize; maxsize_ = other.maxsize_;
other.reset(); other.reset();
} }
bool append(const T& item) { bool append(const T& item) {
if (!growIfNeeded(1)) if (!growIfNeeded(1))
return false; return false;
new (&data[nitems]) T(item); new (&data_[nitems_]) T(item);
nitems++; nitems_++;
return true; return true;
} }
void infallibleAppend(const T &item) { void infallibleAppend(const T &item) {
assert(growIfNeeded(1)); assert(growIfNeeded(1));
new (&data[nitems]) T(item); new (&data_[nitems_]) T(item);
nitems++; nitems_++;
} }
T popCopy() { T popCopy() {
T t = at(length() - 1); T t = at(length() - 1);
@ -68,23 +79,23 @@ class Vector : public AllocPolicy
return t; return t;
} }
void pop() { void pop() {
assert(nitems); assert(nitems_);
data[nitems - 1].~T(); data_[nitems_ - 1].~T();
nitems--; nitems_--;
} }
bool empty() const { bool empty() const {
return length() == 0; return length() == 0;
} }
size_t length() const { size_t length() const {
return nitems; return nitems_;
} }
T& at(size_t i) { T& at(size_t i) {
assert(i < length()); assert(i < length());
return data[i]; return data_[i];
} }
const T& at(size_t i) const { const T& at(size_t i) const {
assert(i < length()); assert(i < length());
return data[i]; return data_[i];
} }
T& operator [](size_t i) { T& operator [](size_t i) {
return at(i); return at(i);
@ -93,7 +104,7 @@ class Vector : public AllocPolicy
return at(i); return at(i);
} }
void clear() { void clear() {
nitems = 0; nitems_ = 0;
} }
const T &back() const { const T &back() const {
return at(length() - 1); return at(length() - 1);
@ -103,7 +114,7 @@ class Vector : public AllocPolicy
} }
T *buffer() const { T *buffer() const {
return data; return data_;
} }
bool ensure(size_t desired) { bool ensure(size_t desired) {
@ -115,49 +126,49 @@ class Vector : public AllocPolicy
private: private:
void zap() { void zap() {
for (size_t i = 0; i < nitems; i++) for (size_t i = 0; i < nitems_; i++)
data[i].~T(); data_[i].~T();
this->free(data); this->free(data_);
} }
void reset() { void reset() {
data = NULL; data_ = NULL;
nitems = 0; nitems_ = 0;
maxsize = 0; maxsize_ = 0;
} }
bool growIfNeeded(size_t needed) bool growIfNeeded(size_t needed)
{ {
if (!IsUintPtrAddSafe(nitems, needed)) { if (!IsUintPtrAddSafe(nitems_, needed)) {
this->reportAllocationOverflow(); this->reportAllocationOverflow();
return false; return false;
} }
if (nitems + needed < maxsize) if (nitems_ + needed < maxsize_)
return true; return true;
if (maxsize == 0) if (maxsize_ == 0)
maxsize = 8; maxsize_ = 8;
while (nitems + needed > maxsize) { while (nitems_ + needed > maxsize_) {
if (!IsUintPtrMultiplySafe(maxsize, 2)) { if (!IsUintPtrMultiplySafe(maxsize_, 2)) {
this->reportAllocationOverflow(); this->reportAllocationOverflow();
return false; return false;
} }
maxsize *= 2; maxsize_ *= 2;
} }
T* newdata = (T*)this->malloc(sizeof(T) * maxsize); T* newdata = (T*)this->malloc(sizeof(T) * maxsize_);
if (newdata == NULL) if (newdata == NULL)
return false; return false;
for (size_t i = 0; i < nitems; i++) { for (size_t i = 0; i < nitems_; i++) {
new (&newdata[i]) T(data[i]); new (&newdata[i]) T(data_[i]);
data[i].~T(); data_[i].~T();
} }
this->free(data); this->free(data_);
data = newdata; data_ = newdata;
return true; return true;
} }
private: private:
T* data; T* data_;
size_t nitems; size_t nitems_;
size_t maxsize; size_t maxsize_;
}; };
} }

View File

@ -36,7 +36,7 @@ struct floattbl_t
/* Jit wants fast access to this so we expose things as public */ /* Jit wants fast access to this so we expose things as public */
class BaseRuntime class BaseRuntime
: public SourcePawn::IPluginRuntime, : public SourcePawn::IPluginRuntime,
public InlineListNode<BaseRuntime> public ke::InlineListNode<BaseRuntime>
{ {
public: public:
BaseRuntime(); BaseRuntime();

View File

@ -2056,7 +2056,7 @@ void
JITX86::PatchAllJumpsForTimeout() JITX86::PatchAllJumpsForTimeout()
{ {
mutex_.AssertCurrentThreadOwns(); mutex_.AssertCurrentThreadOwns();
for (InlineList<BaseRuntime>::iterator iter = runtimes_.begin(); iter != runtimes_.end(); iter++) { for (ke::InlineList<BaseRuntime>::iterator iter = runtimes_.begin(); iter != runtimes_.end(); iter++) {
BaseRuntime *rt = *iter; BaseRuntime *rt = *iter;
for (size_t i = 0; i < rt->NumJitFunctions(); i++) { for (size_t i = 0; i < rt->NumJitFunctions(); i++) {
JitFunction *fun = rt->GetJitFunction(i); JitFunction *fun = rt->GetJitFunction(i);
@ -2075,7 +2075,7 @@ void
JITX86::UnpatchAllJumpsFromTimeout() JITX86::UnpatchAllJumpsFromTimeout()
{ {
mutex_.AssertCurrentThreadOwns(); mutex_.AssertCurrentThreadOwns();
for (InlineList<BaseRuntime>::iterator iter = runtimes_.begin(); iter != runtimes_.end(); iter++) { for (ke::InlineList<BaseRuntime>::iterator iter = runtimes_.begin(); iter != runtimes_.end(); iter++) {
BaseRuntime *rt = *iter; BaseRuntime *rt = *iter;
for (size_t i = 0; i < rt->NumJitFunctions(); i++) { for (size_t i = 0; i < rt->NumJitFunctions(); i++) {
JitFunction *fun = rt->GetJitFunction(i); JitFunction *fun = rt->GetJitFunction(i);

View File

@ -201,7 +201,7 @@ class JITX86
void *m_pJitEntry; /* Entry function */ void *m_pJitEntry; /* Entry function */
void *m_pJitReturn; /* Universal return address */ void *m_pJitReturn; /* Universal return address */
void *m_pJitTimeout; /* Universal timeout address */ void *m_pJitTimeout; /* Universal timeout address */
InlineList<BaseRuntime> runtimes_; ke::InlineList<BaseRuntime> runtimes_;
uintptr_t frame_id_; uintptr_t frame_id_;
uintptr_t level_; uintptr_t level_;
ke::Mutex mutex_; ke::Mutex mutex_;