Skip to content

Commit cf87966

Browse files
committed
fix warning, optimize tests
1 parent 630536d commit cf87966

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

core-tests/src/memory/global_memory.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,23 @@ TEST(global_memory, alloc) {
2727
pool->free(ptr1);
2828
strcpy(ptr1, "hello, world, #1");
2929

30-
char *ptr2 = (char *) pool->alloc(12);
30+
char *ptr2 = (char *) pool->alloc(17);
3131
strcpy(ptr2, "hello, world, #2");
32-
char *ptr3 = (char *) pool->alloc(198);
32+
pool->free(ptr2);
33+
34+
char *ptr3 = (char *) pool->alloc(113);
3335
strcpy(ptr3, "hello, world, #3");
3436

3537
ASSERT_TRUE(ptr1);
3638
ASSERT_TRUE(ptr2);
3739
ASSERT_TRUE(ptr3);
3840

39-
delete pool;
41+
ASSERT_GT(pool->capacity(), 2 * 1024 * 1024 - 512);
4042

4143
ASSERT_STREQ(ptr1, "hello, world, #1");
4244
ASSERT_STREQ(ptr2, "hello, world, #2");
4345
ASSERT_STREQ(ptr3, "hello, world, #3");
46+
47+
pool->destroy();
48+
delete pool;
4449
}

ext-src/swoole_redis_server.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ zend_object_handlers swoole_redis_server_handlers;
3535
static std::unordered_map<std::string, zend_fcall_info_cache> redis_handlers;
3636

3737
SW_EXTERN_C_BEGIN
38-
static PHP_METHOD(swoole_redis_server, start);
3938
static PHP_METHOD(swoole_redis_server, setHandler);
4039
static PHP_METHOD(swoole_redis_server, getHandler);
4140
static PHP_METHOD(swoole_redis_server, format);

include/swoole_memory.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class GlobalMemory : public MemoryPool {
7676
void *alloc(uint32_t size);
7777
void free(void *ptr);
7878
void destroy();
79+
size_t capacity();
7980
};
8081
} // namespace swoole
8182

src/memory/global_memory.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ void GlobalMemory::destroy() {
121121
}
122122
}
123123

124+
size_t GlobalMemory::capacity() {
125+
return impl->pagesize - impl->alloc_offset;
126+
}
127+
124128
GlobalMemory::~GlobalMemory() {
125129
delete impl;
126130
}

0 commit comments

Comments
 (0)