Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Harfbuzz
提交
fc6c9400
T
Third Party Harfbuzz
项目概览
OpenHarmony
/
Third Party Harfbuzz
大约 1 年 前同步成功
通知
0
Star
18
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
Third Party Harfbuzz
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
fc6c9400
编写于
8月 03, 2009
作者:
B
Behdad Esfahbod
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[HB] Simplify sub-blob support
上级
a2644243
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
74 addition
and
112 deletion
+74
-112
src/hb-blob.c
src/hb-blob.c
+65
-107
src/hb-blob.h
src/hb-blob.h
+9
-5
未找到文件。
src/hb-blob.c
浏览文件 @
fc6c9400
...
...
@@ -31,13 +31,14 @@
#include <unistd.h>
#include <sys/mman.h>
/* XXX Not thread-safe */
struct
_hb_blob_t
{
hb_reference_count_t
ref_count
;
hb_
blob_t
*
parent
;
hb_
reference_count_t
lock
;
const
char
*
data
;
unsigned
int
offset
;
unsigned
int
length
;
hb_memory_mode_t
mode
;
...
...
@@ -47,12 +48,11 @@ struct _hb_blob_t {
static
hb_blob_t
_hb_blob_nil
=
{
HB_REFERENCE_COUNT_INVALID
,
/* ref_count */
NULL
,
/* parent
*/
HB_REFERENCE_COUNT_INVALID
,
/* lock
*/
NULL
,
/* data */
0
,
/* offset */
0
,
/* length */
HB_MEMORY_MODE_READONLY
,
/* mode */
HB_MEMORY_MODE_READONLY
_NEVER_DUPLICATE
,
/* mode */
NULL
,
/* destroy */
NULL
/* user_data */
...
...
@@ -62,8 +62,6 @@ static void
_hb_blob_destroy_user_data
(
hb_blob_t
*
blob
)
{
if
(
blob
->
destroy
)
{
if
(
blob
->
parent
==
blob
->
user_data
)
blob
->
parent
=
NULL
;
blob
->
destroy
(
blob
->
user_data
);
blob
->
destroy
=
NULL
;
blob
->
user_data
=
NULL
;
...
...
@@ -71,42 +69,10 @@ _hb_blob_destroy_user_data (hb_blob_t *blob)
}
static
void
_hb_blob_nullify
(
hb_blob_t
*
blob
)
{
_hb_blob_destroy_user_data
(
blob
);
blob
->
data
=
NULL
;
blob
->
offset
=
0
;
blob
->
length
=
0
;
}
static
void
_hb_blob_sync_parent_mode
(
hb_blob_t
*
blob
)
_hb_blob_unlock_and_destroy
(
hb_blob_t
*
blob
)
{
if
(
blob
->
parent
)
{
if
(
blob
->
mode
!=
HB_MEMORY_MODE_WRITEABLE
&&
hb_blob_is_writeable
(
blob
->
parent
))
blob
->
mode
=
HB_MEMORY_MODE_WRITEABLE
;
}
}
static
void
_hb_blob_sync_parent_data
(
hb_blob_t
*
blob
)
{
if
(
blob
->
parent
)
{
const
char
*
pdata
;
unsigned
int
plength
;
pdata
=
hb_blob_get_data
(
blob
->
parent
,
&
plength
);
if
(
pdata
!=
blob
->
data
)
{
if
(
blob
->
offset
>=
plength
)
{
/* nothing left */
_hb_blob_nullify
(
blob
);
}
else
{
blob
->
data
=
pdata
;
blob
->
length
=
MIN
(
blob
->
length
,
plength
-
blob
->
offset
);
}
}
}
hb_blob_unlock
(
blob
);
hb_blob_destroy
(
blob
);
}
hb_blob_t
*
...
...
@@ -124,8 +90,9 @@ hb_blob_create (const char *data,
return
&
_hb_blob_nil
;
}
HB_REFERENCE_COUNT_INIT
(
blob
->
lock
,
0
);
blob
->
data
=
data
;
blob
->
offset
=
0
;
blob
->
length
=
length
;
blob
->
mode
=
mode
;
...
...
@@ -134,7 +101,10 @@ hb_blob_create (const char *data,
if
(
blob
->
mode
==
HB_MEMORY_MODE_DUPLICATE
)
{
blob
->
mode
=
HB_MEMORY_MODE_READONLY
;
hb_blob_make_writeable
(
blob
);
if
(
!
hb_blob_try_writeable
(
blob
))
{
hb_blob_destroy
(
blob
);
return
&
_hb_blob_nil
;
}
}
return
blob
;
...
...
@@ -146,22 +116,20 @@ hb_blob_create_sub_blob (hb_blob_t *parent,
unsigned
int
length
)
{
hb_blob_t
*
blob
;
const
char
*
pdata
;
if
(
!
length
||
!
HB_OBJECT_DO_CREATE
(
blob
))
if
(
!
length
||
offset
>=
parent
->
length
||
!
HB_OBJECT_DO_CREATE
(
blob
))
return
&
_hb_blob_nil
;
blob
->
parent
=
parent
;
/* we keep the ref in user_data */
pdata
=
hb_blob_lock
(
parent
);
blob
->
data
=
parent
->
data
+
1
;
/* make sure they're not equal */
blob
->
offset
=
offset
;
blob
->
length
=
length
;
blob
->
data
=
pdata
+
offset
;
blob
->
length
=
MIN
(
length
,
parent
->
length
-
offset
);
blob
->
mode
=
parent
->
mode
;
blob
->
destroy
=
(
hb_destroy_func_t
)
hb_blob
_destroy
;
blob
->
destroy
=
(
hb_destroy_func_t
)
_hb_blob_unlock_and
_destroy
;
blob
->
user_data
=
hb_blob_reference
(
parent
);
_hb_blob_sync_parent_data
(
blob
);
return
blob
;
}
...
...
@@ -193,93 +161,83 @@ hb_blob_destroy (hb_blob_t *blob)
free
(
blob
);
}
unsigned
int
hb_blob_get_length
(
hb_blob_t
*
blob
)
{
return
blob
->
length
;
}
const
char
*
hb_blob_get_data
(
hb_blob_t
*
blob
,
unsigned
int
*
length
)
hb_blob_lock
(
hb_blob_t
*
blob
)
{
_hb_blob_sync_parent_data
(
blob
);
if
(
!
HB_OBJECT_IS_INERT
(
blob
))
(
void
)
_hb_reference_count_inc
(
blob
->
lock
);
if
(
length
)
*
length
=
blob
->
length
;
return
blob
->
data
;
}
return
blob
->
data
+
blob
->
offset
;
void
hb_blob_unlock
(
hb_blob_t
*
blob
)
{
if
(
!
HB_OBJECT_IS_INERT
(
blob
))
{
int
old_lock
=
_hb_reference_count_inc
(
blob
->
lock
);
assert
(
old_lock
>
0
);
}
}
hb_bool_t
hb_blob_is_writeable
(
hb_blob_t
*
blob
)
{
_hb_blob_sync_parent_mode
(
blob
);
return
blob
->
mode
==
HB_MEMORY_MODE_WRITEABLE
;
}
hb_bool_t
hb_blob_try_writeable_inplace
(
hb_blob_t
*
blob
)
{
if
(
HB_OBJECT_IS_INERT
(
blob
))
return
FALSE
;
_hb_blob_sync_parent_mode
(
blob
);
if
(
blob
->
mode
==
HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITEABLE
)
{
_hb_blob_sync_parent_data
(
blob
);
int
pagesize
;
unsigned
int
length
;
const
char
*
addr
;
if
(
blob
->
length
)
{
int
pagesize
;
unsigned
int
length
;
const
char
*
addr
;
pagesize
=
sysconf
(
_SC_PAGE_SIZE
);
if
(
-
1
==
pagesize
)
return
FALSE
;
pagesize
=
sysconf
(
_SC_PAGE_SIZE
);
if
(
-
1
==
pagesize
)
return
FALSE
;
addr
=
(
const
char
*
)
(((
size_t
)
blob
->
data
)
&
pagesize
);
length
=
(
const
char
*
)
(((
size_t
)
blob
->
data
+
blob
->
length
+
pagesize
-
1
)
&
pagesize
)
-
addr
;
if
(
-
1
==
mprotect
((
void
*
)
addr
,
length
,
PROT_READ
|
PROT_WRITE
))
return
FALSE
;
addr
=
(
const
char
*
)
(((
size_t
)
blob
->
data
+
blob
->
offset
)
&
pagesize
);
length
=
(
const
char
*
)
(((
size_t
)
blob
->
data
+
blob
->
offset
+
blob
->
length
+
pagesize
-
1
)
&
pagesize
)
-
addr
;
if
(
-
1
==
mprotect
((
void
*
)
addr
,
length
,
PROT_READ
|
PROT_WRITE
))
return
FALSE
;
}
blob
->
mode
=
HB_MEMORY_MODE_WRITEABLE
;
}
return
blob
->
mode
==
HB_MEMORY_MODE_WRITEABLE
;
}
/* DANGER: May rebase or nullify */
void
hb_blob_make_writeable
(
hb_blob_t
*
blob
)
hb_bool_t
hb_blob_try_writeable
(
hb_blob_t
*
blob
)
{
if
(
HB_OBJECT_IS_INERT
(
blob
))
return
;
_hb_blob_sync_parent_mode
(
blob
);
if
(
blob
->
mode
==
HB_MEMORY_MODE_READONLY_NEVER_DUPLICATE
)
{
_hb_blob_nullify
(
blob
);
}
else
if
(
blob
->
mode
==
HB_MEMORY_MODE_READONLY
)
return
FALSE
;
if
(
blob
->
mode
==
HB_MEMORY_MODE_READONLY
)
{
char
*
new_data
;
_hb_blob_sync_parent_data
(
blob
);
if
(
blob
->
length
)
{
new_data
=
malloc
(
blob
->
length
);
if
(
new_data
)
memcpy
(
new_data
,
blob
->
data
+
blob
->
offset
,
blob
->
length
);
if
(
HB_REFERENCE_COUNT_HAS_REFERENCE
(
blob
->
lock
))
return
FALSE
;
new_data
=
malloc
(
blob
->
length
);
if
(
new_data
)
{
memcpy
(
new_data
,
blob
->
data
,
blob
->
length
);
blob
->
data
=
new_data
;
blob
->
mode
=
HB_MEMORY_MODE_WRITEABLE
;
_hb_blob_destroy_user_data
(
blob
);
if
(
!
new_data
)
{
_hb_blob_nullify
(
blob
);
}
else
{
blob
->
data
=
new_data
;
blob
->
offset
=
0
;
}
}
blob
->
mode
=
HB_MEMORY_MODE_WRITEABLE
;
return
TRUE
;
}
else
return
FALSE
;
}
else
return
hb_blob_try_writeable_inplace
(
blob
);
}
src/hb-blob.h
浏览文件 @
fc6c9400
...
...
@@ -65,9 +65,14 @@ hb_blob_get_reference_count (hb_blob_t *blob);
void
hb_blob_destroy
(
hb_blob_t
*
blob
);
unsigned
int
hb_blob_get_length
(
hb_blob_t
*
blob
);
const
char
*
hb_blob_get_data
(
hb_blob_t
*
blob
,
unsigned
int
*
length
);
hb_blob_lock
(
hb_blob_t
*
blob
);
void
hb_blob_unlock
(
hb_blob_t
*
blob
);
hb_bool_t
hb_blob_is_writeable
(
hb_blob_t
*
blob
);
...
...
@@ -75,9 +80,8 @@ hb_blob_is_writeable (hb_blob_t *blob);
hb_bool_t
hb_blob_try_writeable_inplace
(
hb_blob_t
*
blob
);
/* DANGER: May rebase or nullify */
void
hb_blob_make_writeable
(
hb_blob_t
*
blob
);
hb_bool_t
hb_blob_try_writeable
(
hb_blob_t
*
blob
);
HB_END_DECLS
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录