Update AMTL; replace AutoPtr/UniquePtr with STL.

This commit is contained in:
David Anderson
2020-05-18 18:19:16 -07:00
parent c2df49ee33
commit 7d7253c9cc
20 changed files with 78 additions and 58 deletions
+5 -3
View File
@@ -31,8 +31,10 @@
#include <stdlib.h>
#include <string.h>
#include <memory>
#include "CDataPack.h"
#include <amtl/am-autoptr.h>
CDataPack::CDataPack()
{
@@ -44,14 +46,14 @@ CDataPack::~CDataPack()
Initialize();
}
static ke::Vector<ke::AutoPtr<CDataPack>> sDataPackCache;
static ke::Vector<std::unique_ptr<CDataPack>> sDataPackCache;
CDataPack *CDataPack::New()
{
if (sDataPackCache.empty())
return new CDataPack();
CDataPack *pack = sDataPackCache.back().take();
CDataPack *pack = sDataPackCache.back().release();
sDataPackCache.pop();
pack->Initialize();
return pack;
+4 -1
View File
@@ -30,6 +30,9 @@
*/
#include <stdlib.h>
#include <memory>
#include "ExtensionSys.h"
#include <ILibrarySys.h>
#include <ISourceMod.h>
@@ -496,7 +499,7 @@ void CExtensionManager::TryAutoload()
g_pSM->BuildPath(Path_SM, path, sizeof(path), "extensions");
ke::AutoPtr<IDirectory> pDir(libsys->OpenDirectory(path));
std::unique_ptr<IDirectory> pDir(libsys->OpenDirectory(path));
if (!pDir)
return;
+1 -1
View File
@@ -206,7 +206,7 @@ HandleType_t HandleSystem::CreateType(const char *name,
pType->dispatch = dispatch;
if (name && name[0] != '\0')
{
pType->name = new ke::AString(name);
pType->name = std::make_unique<ke::AString>(name);
m_TypeLookup.insert(name, pType);
}
+6 -4
View File
@@ -32,12 +32,14 @@
#ifndef _INCLUDE_SOURCEMOD_HANDLESYSTEM_H_
#define _INCLUDE_SOURCEMOD_HANDLESYSTEM_H_
#include <IHandleSys.h>
#include <stdio.h>
#include <sm_namehashset.h>
#include <amtl/am-autoptr.h>
#include <memory>
#include <amtl/am-string.h>
#include <amtl/am-function.h>
#include <IHandleSys.h>
#include <sm_namehashset.h>
#include "common_logic.h"
#define HANDLESYS_MAX_HANDLES (1<<15)
@@ -105,7 +107,7 @@ struct QHandleType
TypeAccess typeSec;
HandleAccess hndlSec;
unsigned int opened;
ke::AutoPtr<ke::AString> name;
std::unique_ptr<ke::AString> name;
static inline bool matches(const char *key, const QHandleType *type)
{
+3 -4
View File
@@ -33,7 +33,6 @@
#include <IShareSys.h>
#include <IHandleSys.h>
#include <am-autoptr.h>
#include <am-string.h>
#include <am-utility.h>
#include <am-refcounting.h>
@@ -64,19 +63,19 @@ struct Native : public ke::Refcounted<Native>
Native(CNativeOwner *owner, const sp_nativeinfo_t *native)
: owner(owner),
native(native),
fake(NULL)
fake(nullptr)
{
}
Native(CNativeOwner *owner, FakeNative *fake)
: owner(owner),
native(NULL),
native(nullptr),
fake(fake)
{
}
CNativeOwner *owner;
const sp_nativeinfo_t *native;
ke::AutoPtr<FakeNative> fake;
std::unique_ptr<FakeNative> fake;
SPVM_NATIVE_FUNC func() const
{
+4 -4
View File
@@ -79,7 +79,7 @@ CPlugin::CPlugin(const char *file)
memset(&m_info, 0, sizeof(m_info));
m_pPhrases = g_Translator.CreatePhraseCollection();
m_pPhrases.reset(g_Translator.CreatePhraseCollection());
}
CPlugin::~CPlugin()
@@ -227,7 +227,7 @@ bool CPlugin::SetProperty(const char *prop, void *ptr)
IPluginRuntime *CPlugin::GetRuntime()
{
return m_pRuntime;
return m_pRuntime.get();
}
void CPlugin::EvictWithError(PluginStatus status, const char *error_fmt, ...)
@@ -483,7 +483,7 @@ bool CPlugin::TryCompile()
g_pSM->BuildPath(Path_SM, fullpath, sizeof(fullpath), "plugins/%s", m_filename);
char loadmsg[255];
m_pRuntime = g_pSourcePawn2->LoadBinaryFromFile(fullpath, loadmsg, sizeof(loadmsg));
m_pRuntime.reset(g_pSourcePawn2->LoadBinaryFromFile(fullpath, loadmsg, sizeof(loadmsg)));
if (!m_pRuntime) {
EvictWithError(Plugin_BadLoad, "Unable to load plugin (%s)", loadmsg);
return false;
@@ -658,7 +658,7 @@ time_t CPlugin::GetFileTimeStamp()
IPhraseCollection *CPlugin::GetPhrases()
{
return m_pPhrases;
return m_pPhrases.get();
}
void CPlugin::DependencyDropped(CPlugin *pOwner)
+6 -3
View File
@@ -32,9 +32,12 @@
#ifndef _INCLUDE_SOURCEMOD_PLUGINSYSTEM_H_
#define _INCLUDE_SOURCEMOD_PLUGINSYSTEM_H_
#include <time.h>
#include <errno.h>
#include <sys/stat.h>
#include <time.h>
#include <memory>
#include <IPluginSys.h>
#include <IHandleSys.h>
#include <IForwardSys.h>
@@ -267,8 +270,8 @@ private:
char m_errormsg[256];
// Internal properties that must by reset if the runtime is evicted.
ke::AutoPtr<IPluginRuntime> m_pRuntime;
ke::AutoPtr<CPhraseCollection> m_pPhrases;
std::unique_ptr<IPluginRuntime> m_pRuntime;
std::unique_ptr<CPhraseCollection> m_pPhrases;
IPluginContext *m_pContext;
sp_pubvar_t *m_MaxClientsVar;
StringHashMap<void *> m_Props;
+7 -4
View File
@@ -29,13 +29,16 @@
* Version: $Id$
*/
#include <assert.h>
#include <memory>
#include "ShareSys.h"
#include "ExtensionSys.h"
#include <ILibrarySys.h>
#include "common_logic.h"
#include "PluginSys.h"
#include "HandleSys.h"
#include <assert.h>
using namespace ke;
@@ -406,15 +409,15 @@ AlreadyRefed<Native> ShareSystem::AddFakeNative(IPluginFunction *pFunc, const ch
if (entry)
return nullptr;
AutoPtr<FakeNative> fake(new FakeNative(name, pFunc));
std::unique_ptr<FakeNative> fake(new FakeNative(name, pFunc));
fake->gate = g_pSourcePawn2->CreateFakeNative(func, fake);
fake->gate = g_pSourcePawn2->CreateFakeNative(func, fake.get());
if (!fake->gate)
return nullptr;
CNativeOwner *owner = g_PluginSys.GetPluginByCtx(fake->ctx->GetContext());
entry = new Native(owner, fake.take());
entry = new Native(owner, fake.release());
m_NtvCache.insert(name, entry);
return entry.forget();
+5 -3
View File
@@ -30,8 +30,10 @@
*/
#include <stdlib.h>
#include <memory>
#include "common_logic.h"
#include <am-autoptr.h>
#include <am-moveable.h>
#include <am-refcounting.h>
#include <sm_stringhashmap.h>
@@ -182,7 +184,7 @@ struct TrieSnapshot
}
size_t length;
ke::AutoPtr<int[]> keys;
std::unique_ptr<int[]> keys;
BaseStringTable strings;
};
@@ -557,7 +559,7 @@ static cell_t CreateTrieSnapshot(IPluginContext *pContext, const cell_t *params)
TrieSnapshot *snapshot = new TrieSnapshot;
snapshot->length = pTrie->map.elements();
snapshot->keys = ke::MakeUnique<int[]>(snapshot->length);
snapshot->keys = std::make_unique<int[]>(snapshot->length);
size_t i = 0;
for (StringHashMap<Entry>::iterator iter = pTrie->map.iter(); !iter.empty(); iter.next(), i++)
snapshot->keys[i] = snapshot->strings.AddString(iter->key.chars(), iter->key.length());
+5 -3
View File
@@ -29,6 +29,8 @@
* Version: $Id$
*/
#include <memory>
#include "common_logic.h"
#include "Database.h"
#include "ExtensionSys.h"
@@ -1667,8 +1669,8 @@ private:
assert(results_.length() == txn_->entries.length());
ke::AutoPtr<cell_t[]> data = ke::MakeUnique<cell_t[]>(results_.length());
ke::AutoPtr<cell_t[]> handles = ke::MakeUnique<cell_t[]>(results_.length());
std::unique_ptr<cell_t[]> data = std::make_unique<cell_t[]>(results_.length());
std::unique_ptr<cell_t[]> handles = std::make_unique<cell_t[]>(results_.length());
for (size_t i = 0; i < results_.length(); i++)
{
CombinedQuery *obj = new CombinedQuery(results_[i], db_);
@@ -1728,7 +1730,7 @@ public:
{
HandleSecurity sec(ident_, g_pCoreIdent);
ke::AutoPtr<cell_t[]> data = ke::MakeUnique<cell_t[]>(txn_->entries.length());
std::unique_ptr<cell_t[]> data = std::make_unique<cell_t[]>(txn_->entries.length());
for (size_t i = 0; i < txn_->entries.length(); i++)
data[i] = txn_->entries[i].data;
+3 -2
View File
@@ -29,12 +29,13 @@
* Version: $Id$
*/
#include <memory>
#include "common_logic.h"
#include <IPluginSys.h>
#include <IHandleSys.h>
#include <IForwardSys.h>
#include <ISourceMod.h>
#include <amtl/am-autoptr.h>
HandleType_t g_GlobalFwdType = 0;
HandleType_t g_PrivateFwdType = 0;
@@ -686,7 +687,7 @@ struct SMFrameActionData
static void PawnFrameAction(void *pData)
{
ke::AutoPtr<SMFrameActionData> frame(reinterpret_cast<SMFrameActionData *>(pData));
std::unique_ptr<SMFrameActionData> frame(reinterpret_cast<SMFrameActionData *>(pData));
IPlugin *pPlugin = pluginsys->PluginFromHandle(frame->ownerhandle, NULL);
if (!pPlugin)
{