Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
e1d596d0
提交
e1d596d0
authored
3月 27, 2017
作者:
Anthony Minessale
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
FS-10167 encore
上级
ac3d6851
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
13 行增加
和
8 行删除
+13
-8
ks_pool.c
libs/libks/src/ks_pool.c
+9
-5
testpools.c
libs/libks/test/testpools.c
+4
-3
没有找到文件。
libs/libks/src/ks_pool.c
浏览文件 @
e1d596d0
...
...
@@ -53,6 +53,7 @@ typedef struct alloc_prefix_s {
unsigned
long
size
;
unsigned
char
m2
;
unsigned
int
refs
;
unsigned
int
padding
;
}
alloc_prefix_t
;
#define PREFIX_SIZE sizeof(struct alloc_prefix_s)
...
...
@@ -780,8 +781,6 @@ static void *get_space(ks_pool_t *mp_p, const unsigned long byte_size, unsigned
void
*
free_addr
=
NULL
,
*
free_end
;
size
=
byte_size
;
*
padding
=
0
;
while
((
size
&
(
sizeof
(
void
*
)
-
1
))
>
0
)
{
size
++
;
}
...
...
@@ -950,18 +949,22 @@ static void *alloc_mem(ks_pool_t *mp_p, const unsigned long byte_size, ks_status
/* get our free space + the space for the fence post */
addr
=
get_space
(
mp_p
,
size
+
fence
+
PREFIX_SIZE
,
&
padding
,
error_p
);
if
(
addr
==
NULL
)
{
/* error_p set in get_space */
return
NULL
;
}
write_magic
((
char
*
)
addr
+
size
+
PREFIX_SIZE
);
prefix
=
(
alloc_prefix_t
*
)
addr
;
prefix
->
m1
=
PRE_MAGIC1
;
prefix
->
m2
=
PRE_MAGIC2
;
prefix
->
size
=
size
+
fence
+
PREFIX_SIZE
+
padding
;
prefix
->
refs
=
1
;
prefix
->
padding
=
padding
;
write_magic
((
char
*
)
prefix
+
prefix
->
size
-
padding
-
fence
);
if
(
mp_p
->
mp_log_func
!=
NULL
)
{
mp_p
->
mp_log_func
(
mp_p
,
KS_POOL_FUNC_INCREF
,
prefix
->
size
,
prefix
->
refs
,
NULL
,
addr
,
0
);
}
...
...
@@ -1039,7 +1042,7 @@ static int free_mem(ks_pool_t *mp_p, void *addr)
}
/* find the user's magic numbers */
ret
=
check_magic
(
addr
,
size
-
FENCE_SIZE
-
PREFIX_SIZE
);
ret
=
check_magic
(
prefix
,
prefix
->
size
-
FENCE_SIZE
-
prefix
->
padding
);
perform_pool_cleanup_on_free
(
mp_p
,
addr
);
...
...
@@ -1882,7 +1885,8 @@ KS_DECLARE(void *) ks_pool_resize_ex(ks_pool_t *mp_p, void *old_addr, const unsi
}
if
(
old_byte_size
>
0
)
{
ret
=
check_magic
(
old_addr
,
old_byte_size
-
FENCE_SIZE
-
PREFIX_SIZE
);
ret
=
check_magic
(
prefix
,
prefix
->
size
-
FENCE_SIZE
-
prefix
->
padding
);
if
(
ret
!=
KS_STATUS_SUCCESS
)
{
if
(
!
(
mp_p
->
mp_flags
&
KS_POOL_FLAG_NO_ASSERT
))
{
abort
();
...
...
libs/libks/test/testpools.c
浏览文件 @
e1d596d0
...
...
@@ -64,7 +64,7 @@ int main(int argc, char **argv)
status
=
ks_pool_open
(
&
pool
);
printf
(
"OPEN:
\n
"
);
printf
(
"OPEN:
%p
\n
"
,
(
void
*
)
pool
);
ok
(
status
==
KS_STATUS_SUCCESS
);
if
(
status
!=
KS_STATUS_SUCCESS
)
{
fprintf
(
stderr
,
"OPEN ERR: %d [%s]
\n
"
,
err
,
ks_pool_strerror
(
status
));
...
...
@@ -176,7 +176,7 @@ int main(int argc, char **argv)
ks_pool_set_cleanup
(
pool
,
foo
,
NULL
,
0
,
cleanup
);
printf
(
"ALLOC OBJ3:
\n
"
);
printf
(
"ALLOC OBJ3:
%p
\n
"
,
(
void
*
)
pool
);
foo
=
ks_pool_alloc
(
pool
,
sizeof
(
struct
foo
));
...
...
@@ -188,13 +188,14 @@ int main(int argc, char **argv)
printf
(
"ALLOC OBJ3 [%p]:
\n
"
,
(
void
*
)
foo
);
}
printf
(
"CLEANUP: %p
\n
"
,
(
void
*
)
pool
);
foo
->
x
=
12
;
foo
->
str
=
strdup
(
"This is a third test 1234 abcd; This will be called on pool clear/destroy
\n
"
);
ks_pool_set_cleanup
(
pool
,
foo
,
NULL
,
0
,
cleanup
);
printf
(
"RESIZE:
\n
"
);
printf
(
"RESIZE:
%p
\n
"
,
(
void
*
)
pool
);
ks_snprintf
(
str
,
bytes
,
"%s"
,
STR
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论