refactor: remove unused tr_ptrArray class (#3262)

* refactor: remove unused tr_ptrArray class

* fixup! build: add sanitizer CI runs when libtransmission-test changes (#3260)
This commit is contained in:
Charles Kerr 2022-06-11 21:45:00 -05:00 committed by GitHub
parent d34bd0b4d6
commit 34cb56b2af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 4 additions and 312 deletions

View File

@ -1,22 +1,12 @@
name: sanitizer-test-clang
on:
on:
push:
paths:
- CMakeLists.txt
- libtransmission/**
- tests/**
- utils/**
pull_request:
types: [opened, reopened]
paths:
- CMakeLists.txt
- libtransmission/**
- tests/**
- utils/**
env:
GTEST_OUTPUT: xml:./
jobs:
sanitizer-test-clang
sanitizer-test-clang:
runs-on: ubuntu-22.04
steps:
- name: Prepare

View File

@ -1,22 +1,12 @@
name: sanitizer-test-gcc
on:
on:
push:
paths:
- CMakeLists.txt
- libtransmission/**
- tests/**
- utils/**
pull_request:
types: [opened, reopened]
paths:
- CMakeLists.txt
- libtransmission/**
- tests/**
- utils/**
env:
GTEST_OUTPUT: xml:./
jobs:
sanitizer-test-gcc
sanitizer-test-gcc:
runs-on: ubuntu-22.04
steps:
- name: Prepare

View File

@ -21,7 +21,6 @@
3C7A11980D0B2EE300B5701F /* getgateway.h in Headers */ = {isa = PBXBuildFile; fileRef = 3C7A11920D0B2EE300B5701F /* getgateway.h */; };
3C7A11990D0B2EE300B5701F /* natpmp.c in Sources */ = {isa = PBXBuildFile; fileRef = 3C7A11930D0B2EE300B5701F /* natpmp.c */; };
3C7A119A0D0B2EE300B5701F /* natpmp.h in Headers */ = {isa = PBXBuildFile; fileRef = 3C7A11940D0B2EE300B5701F /* natpmp.h */; };
4394AC670C74FB6000F367E8 /* ptrarray.cc in Sources */ = {isa = PBXBuildFile; fileRef = 4394AC640C74FB6000F367E8 /* ptrarray.cc */; };
45A6DE80284D1F2A0088D134 /* MainWindow.mm in Sources */ = {isa = PBXBuildFile; fileRef = 45A6DE7F284D1F2A0088D134 /* MainWindow.mm */; };
45A7D3292843B54D00F0C32A /* GroupPopUpButtonCell.mm in Sources */ = {isa = PBXBuildFile; fileRef = 45A7D3282843B54D00F0C32A /* GroupPopUpButtonCell.mm */; };
45A7D32C2843B55F00F0C32A /* PriorityPopUpButtonCell.mm in Sources */ = {isa = PBXBuildFile; fileRef = 45A7D32B2843B55F00F0C32A /* PriorityPopUpButtonCell.mm */; };
@ -39,7 +38,6 @@
4D36BA780CA2F00800A63CA5 /* peer-mgr.h in Headers */ = {isa = PBXBuildFile; fileRef = 4D36BA690CA2F00800A63CA5 /* peer-mgr.h */; };
4D36BA790CA2F00800A63CA5 /* peer-msgs.cc in Sources */ = {isa = PBXBuildFile; fileRef = 4D36BA6A0CA2F00800A63CA5 /* peer-msgs.cc */; };
4D36BA7A0CA2F00800A63CA5 /* peer-msgs.h in Headers */ = {isa = PBXBuildFile; fileRef = 4D36BA6B0CA2F00800A63CA5 /* peer-msgs.h */; };
4D36BA7B0CA2F00800A63CA5 /* ptrarray.h in Headers */ = {isa = PBXBuildFile; fileRef = 4D36BA6C0CA2F00800A63CA5 /* ptrarray.h */; };
4D3EA0AA08AE13C600EA10C2 /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4D3EA0A908AE13C600EA10C2 /* IOKit.framework */; };
4D4ADFC70DA1631500A68297 /* blocklist.cc in Sources */ = {isa = PBXBuildFile; fileRef = A2D3078E0D9EC45F0051FD27 /* blocklist.cc */; };
4D8017EA10BBC073008A4AF2 /* torrent-magnet.cc in Sources */ = {isa = PBXBuildFile; fileRef = 4D8017E810BBC073008A4AF2 /* torrent-magnet.cc */; };
@ -619,7 +617,6 @@
3C7A11920D0B2EE300B5701F /* getgateway.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = getgateway.h; sourceTree = "<group>"; };
3C7A11930D0B2EE300B5701F /* natpmp.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = natpmp.c; sourceTree = "<group>"; };
3C7A11940D0B2EE300B5701F /* natpmp.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = natpmp.h; sourceTree = "<group>"; };
4394AC640C74FB6000F367E8 /* ptrarray.cc */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ptrarray.cc; sourceTree = "<group>"; };
45A6DE7E284D1F2A0088D134 /* MainWindow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MainWindow.h; sourceTree = "<group>"; };
45A6DE7F284D1F2A0088D134 /* MainWindow.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MainWindow.mm; sourceTree = "<group>"; };
45A7D3272843B54D00F0C32A /* GroupPopUpButtonCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GroupPopUpButtonCell.h; sourceTree = "<group>"; };
@ -642,7 +639,6 @@
4D36BA690CA2F00800A63CA5 /* peer-mgr.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "peer-mgr.h"; sourceTree = "<group>"; };
4D36BA6A0CA2F00800A63CA5 /* peer-msgs.cc */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = "peer-msgs.cc"; sourceTree = "<group>"; };
4D36BA6B0CA2F00800A63CA5 /* peer-msgs.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "peer-msgs.h"; sourceTree = "<group>"; };
4D36BA6C0CA2F00800A63CA5 /* ptrarray.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ptrarray.h; sourceTree = "<group>"; };
4D3EA0A908AE13C600EA10C2 /* IOKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOKit.framework; path = System/Library/Frameworks/IOKit.framework; sourceTree = SDKROOT; };
4D8017E810BBC073008A4AF2 /* torrent-magnet.cc */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = "torrent-magnet.cc"; sourceTree = "<group>"; };
4D8017E910BBC073008A4AF2 /* torrent-magnet.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "torrent-magnet.h"; sourceTree = "<group>"; };
@ -1683,10 +1679,8 @@
A292A6E40DFB45E5004B9C0A /* peer-common.h */,
A292A6E50DFB45EC004B9C0A /* webseed.cc */,
A292A6E60DFB45EC004B9C0A /* webseed.h */,
4D36BA6C0CA2F00800A63CA5 /* ptrarray.h */,
A24621350C769CF400088E81 /* trevent.h */,
A24621360C769CF400088E81 /* trevent.cc */,
4394AC640C74FB6000F367E8 /* ptrarray.cc */,
A2BE9C4E0C1E4ADA002D16E6 /* makemeta.cc */,
A2BE9C4F0C1E4ADA002D16E6 /* makemeta.h */,
BEFC1DF00C07861A00B0BB3C /* version.h */,
@ -2203,7 +2197,6 @@
4D36BA750CA2F00800A63CA5 /* peer-io.h in Headers */,
4D36BA780CA2F00800A63CA5 /* peer-mgr.h in Headers */,
4D36BA7A0CA2F00800A63CA5 /* peer-msgs.h in Headers */,
4D36BA7B0CA2F00800A63CA5 /* ptrarray.h in Headers */,
C11DEA171FCD31C0009E22B9 /* subprocess.h in Headers */,
A25D2CBE0CF4C73E0096A262 /* stats.h in Headers */,
C1033E0A1A3279B800EF44D8 /* crypto-utils.h in Headers */,
@ -2954,7 +2947,6 @@
BEFC1E560C07861A00B0BB3C /* completion.cc in Sources */,
BEFC1E580C07861A00B0BB3C /* clients.cc in Sources */,
A2BE9C520C1E4AF5002D16E6 /* makemeta.cc in Sources */,
4394AC670C74FB6000F367E8 /* ptrarray.cc in Sources */,
A24621420C769D0900088E81 /* trevent.cc in Sources */,
C11DEA161FCD31C0009E22B9 /* subprocess-posix.cc in Sources */,
4D36BA6F0CA2F00800A63CA5 /* crypto.cc in Sources */,

View File

@ -45,7 +45,6 @@ set(PROJECT_FILES
platform-quota.cc
platform.cc
port-forwarding.cc
ptrarray.cc
quark.cc
resume.cc
rpc-server.cc
@ -187,7 +186,6 @@ set(${PROJECT_NAME}_PRIVATE_HEADERS
platform-quota.h
platform.h
port-forwarding.h
ptrarray.h
resume.h
rpc-server.h
session.h

View File

@ -1,205 +0,0 @@
// This file Copyright 2008-2022 Mnemosyne LLC.
// It may be used under GPLv2 (SPDX: GPL-2.0-only), GPLv3 (SPDX: GPL-3.0-only),
// or any future license endorsed by Mnemosyne LLC.
// License text can be found in the licenses/ folder.
#include <algorithm>
#include <cstring> /* memmove */
#include "ptrarray.h"
#include "tr-assert.h"
#include "tr-macros.h"
#include "utils.h"
static auto constexpr Floor = int{ 32 };
static void tr_ptrArrayForeach(tr_ptrArray* t, PtrArrayForeachFunc func)
{
TR_ASSERT(t != nullptr);
TR_ASSERT(t->items != nullptr || t->n_items == 0);
TR_ASSERT(func != nullptr);
for (int i = 0; i < t->n_items; ++i)
{
func(t->items[i]);
}
}
void tr_ptrArrayDestruct(tr_ptrArray* p, PtrArrayForeachFunc func)
{
TR_ASSERT(p != nullptr);
TR_ASSERT(p->items != nullptr || p->n_items == 0);
if (func != nullptr)
{
tr_ptrArrayForeach(p, func);
}
tr_free(p->items);
}
int tr_ptrArrayInsert(tr_ptrArray* t, void* ptr, int pos)
{
if (t->n_items >= t->n_alloc)
{
t->n_alloc = std::max(Floor, t->n_alloc * 2);
t->items = tr_renew(void*, t->items, t->n_alloc);
}
if (pos < 0 || pos > t->n_items)
{
pos = t->n_items;
}
else
{
memmove(t->items + pos + 1, t->items + pos, sizeof(void*) * (t->n_items - pos));
}
t->items[pos] = ptr;
t->n_items++;
return pos;
}
void tr_ptrArrayErase(tr_ptrArray* t, int begin, int end)
{
if (end < 0)
{
end = t->n_items;
}
TR_ASSERT(begin >= 0);
TR_ASSERT(begin < end);
TR_ASSERT(end <= t->n_items);
memmove(t->items + begin, t->items + end, sizeof(void*) * (t->n_items - end));
t->n_items -= end - begin;
}
/**
***
**/
int tr_ptrArrayLowerBound(tr_ptrArray const* t, void const* ptr, tr_voidptr_compare_func compare, bool* exact_match)
{
int pos = -1;
bool match = false;
if (t->n_items == 0)
{
pos = 0;
}
else
{
int first = 0;
int last = t->n_items - 1;
for (;;)
{
int const half = (last - first) / 2;
int const c = compare(t->items[first + half], ptr);
if (c < 0)
{
int const new_first = first + half + 1;
if (new_first > last)
{
pos = new_first;
break;
}
first = new_first;
}
else if (c > 0)
{
int const new_last = first + half - 1;
if (new_last < first)
{
pos = first;
break;
}
last = new_last;
}
else
{
match = true;
pos = first + half;
break;
}
}
}
if (exact_match != nullptr)
{
*exact_match = match;
}
return pos;
}
#ifndef TR_ENABLE_ASSERTS
#define assertArrayIsSortedAndUnique(array, compare) /* no-op */
#define assertIndexIsSortedAndUnique(array, pos, compare) /* no-op */
#else
static void assertArrayIsSortedAndUnique(tr_ptrArray const* t, tr_voidptr_compare_func compare)
{
if (t->items == nullptr)
{
TR_ASSERT(t->n_items == 0);
}
else
{
for (int i = 0; i < t->n_items - 2; ++i)
{
TR_ASSERT(compare(t->items[i], t->items[i + 1]) < 0);
}
}
}
static void assertIndexIsSortedAndUnique(tr_ptrArray const* t, int pos, tr_voidptr_compare_func compare)
{
if (pos > 0)
{
TR_ASSERT(compare(t->items[pos - 1], t->items[pos]) < 0);
}
if (pos + 1 < t->n_items)
{
TR_ASSERT(compare(t->items[pos], t->items[pos + 1]) < 0);
}
}
#endif
int tr_ptrArrayInsertSorted(tr_ptrArray* t, void* ptr, tr_voidptr_compare_func compare)
{
assertArrayIsSortedAndUnique(t, compare);
int const pos = tr_ptrArrayLowerBound(t, ptr, compare, nullptr);
int const ret = tr_ptrArrayInsert(t, ptr, pos);
assertIndexIsSortedAndUnique(t, ret, compare);
return ret;
}
void* tr_ptrArrayFindSorted(tr_ptrArray* t, void const* ptr, tr_voidptr_compare_func compare)
{
bool match = false;
int const pos = tr_ptrArrayLowerBound(t, ptr, compare, &match);
return match ? t->items[pos] : nullptr;
}
void* tr_ptrArrayNth(tr_ptrArray* array, int i)
{
TR_ASSERT(array != nullptr);
TR_ASSERT(i >= 0);
TR_ASSERT(i < array->n_items);
return array->items[i];
}

View File

@ -1,72 +0,0 @@
// This file Copyright © 2008-2022 Mnemosyne LLC.
// It may be used under GPLv2 (SPDX: GPL-2.0), GPLv3 (SPDX: GPL-3.0),
// or any future license endorsed by Mnemosyne LLC.
// License text can be found in the licenses/ folder.
#pragma once
#ifndef __TRANSMISSION__
#error only libtransmission should #include this header.
#endif
#include "transmission.h"
#include "tr-macros.h"
/**
* @addtogroup utils Utilities
* @{
*/
/**
* @brief simple pointer array that resizes itself dynamically.
*/
struct tr_ptrArray
{
void** items;
int n_items;
int n_alloc;
};
using tr_voidptr_compare_func = int (*)(void const* lhs, void const* rhs);
using PtrArrayCompareFunc = tr_voidptr_compare_func;
using PtrArrayForeachFunc = void (*)(void*);
/** @brief Destructor to free a tr_ptrArray's internal memory */
void tr_ptrArrayDestruct(tr_ptrArray*, PtrArrayForeachFunc func);
/** @brief Return the nth item in a tr_ptrArray
@return the nth item in a tr_ptrArray */
void* tr_ptrArrayNth(tr_ptrArray* array, int i);
void tr_ptrArrayErase(tr_ptrArray* t, int begin, int end);
/** @brief Insert a pointer into the array at the specified position
@return the index of the stored pointer */
int tr_ptrArrayInsert(tr_ptrArray* array, void* insertMe, int pos);
constexpr void** tr_ptrArrayBase(tr_ptrArray const* a)
{
return a->items;
}
/** @brief Return the number of items in the array
@return the number of items in the array */
constexpr int tr_ptrArraySize(tr_ptrArray const* a)
{
return a->n_items;
}
int tr_ptrArrayLowerBound(tr_ptrArray const* array, void const* key, tr_voidptr_compare_func compare, bool* exact_match);
/** @brief Insert a pointer into the array at the position determined by the sort function
@return the index of the stored pointer */
int tr_ptrArrayInsertSorted(tr_ptrArray* array, void* value, tr_voidptr_compare_func compare);
/** @brief Find a pointer from an array sorted by the specified sort function
@return the matching pointer, or nullptr if no match was found */
void* tr_ptrArrayFindSorted(tr_ptrArray* array, void const* key, tr_voidptr_compare_func compare);
/* @} */

View File

@ -23,7 +23,6 @@
#include "crypto-utils.h" // tr_rand_int_weak()
#include "platform.h"
#include "ptrarray.h"
#include "tr-strbuf.h"
#include "utils.h"