Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
241f7a22
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
241f7a22
编写于
4月 27, 2020
作者:
weixin_48148422
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
TD-153: fix bugs
上级
9fdf3455
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
97 addition
and
28 deletion
+97
-28
src/util/inc/exception.h
src/util/inc/exception.h
+28
-19
src/util/inc/tbuffer.h
src/util/inc/tbuffer.h
+53
-1
src/util/src/exception.c
src/util/src/exception.c
+12
-4
src/util/src/tbuffer.c
src/util/src/tbuffer.c
+4
-4
未找到文件。
src/util/inc/exception.h
浏览文件 @
241f7a22
...
@@ -52,6 +52,22 @@ typedef struct SCleanupAction {
...
@@ -52,6 +52,22 @@ typedef struct SCleanupAction {
}
arg1
,
arg2
;
}
arg1
,
arg2
;
}
SCleanupAction
;
}
SCleanupAction
;
/*
* exception hander registration
*/
typedef
struct
SExceptionNode
{
struct
SExceptionNode
*
prev
;
jmp_buf
jb
;
int32_t
code
;
int32_t
maxCleanupAction
;
int32_t
numCleanupAction
;
SCleanupAction
*
cleanupActions
;
}
SExceptionNode
;
////////////////////////////////////////////////////////////////////////////////
// functions & macros for auto-cleanup
void
cleanupPush_void_ptr_ptr
(
bool
failOnly
,
void
*
func
,
void
*
arg1
,
void
*
arg2
);
void
cleanupPush_void_ptr_ptr
(
bool
failOnly
,
void
*
func
,
void
*
arg1
,
void
*
arg2
);
void
cleanupPush_void_ptr_bool
(
bool
failOnly
,
void
*
func
,
void
*
arg1
,
bool
arg2
);
void
cleanupPush_void_ptr_bool
(
bool
failOnly
,
void
*
func
,
void
*
arg1
,
bool
arg2
);
void
cleanupPush_void_ptr
(
bool
failOnly
,
void
*
func
,
void
*
arg
);
void
cleanupPush_void_ptr
(
bool
failOnly
,
void
*
func
,
void
*
arg
);
...
@@ -59,7 +75,8 @@ void cleanupPush_int_int ( bool failOnly, void* func, int arg );
...
@@ -59,7 +75,8 @@ void cleanupPush_int_int ( bool failOnly, void* func, int arg );
void
cleanupPush_void
(
bool
failOnly
,
void
*
func
);
void
cleanupPush_void
(
bool
failOnly
,
void
*
func
);
int32_t
cleanupGetActionCount
();
int32_t
cleanupGetActionCount
();
void
cleanupExecute
(
int32_t
anchor
,
bool
failed
);
void
cleanupExecuteTo
(
int32_t
anchor
,
bool
failed
);
void
cleanupExecute
(
SExceptionNode
*
node
,
bool
failed
);
#define CLEANUP_PUSH_VOID_PTR_PTR( failOnly, func, arg1, arg2 ) cleanupPush_void_ptr_ptr( (failOnly), (void*)(func), (void*)(arg1), (void*)(arg2) )
#define CLEANUP_PUSH_VOID_PTR_PTR( failOnly, func, arg1, arg2 ) cleanupPush_void_ptr_ptr( (failOnly), (void*)(func), (void*)(arg1), (void*)(arg2) )
#define CLEANUP_PUSH_VOID_PTR_BOOL( failOnly, func, arg1, arg2 ) cleanupPush_void_ptr_bool( (failOnly), (void*)(func), (void*)(arg1), (bool)(arg2) )
#define CLEANUP_PUSH_VOID_PTR_BOOL( failOnly, func, arg1, arg2 ) cleanupPush_void_ptr_bool( (failOnly), (void*)(func), (void*)(arg1), (bool)(arg2) )
...
@@ -69,20 +86,12 @@ void cleanupExecute( int32_t anchor, bool failed );
...
@@ -69,20 +86,12 @@ void cleanupExecute( int32_t anchor, bool failed );
#define CLEANUP_PUSH_FREE( failOnly, arg ) cleanupPush_void_ptr( (failOnly), free, (void*)(arg) )
#define CLEANUP_PUSH_FREE( failOnly, arg ) cleanupPush_void_ptr( (failOnly), free, (void*)(arg) )
#define CLEANUP_PUSH_CLOSE( failOnly, arg ) cleanupPush_int_int( (failOnly), close, (int)(arg) )
#define CLEANUP_PUSH_CLOSE( failOnly, arg ) cleanupPush_int_int( (failOnly), close, (int)(arg) )
#define CLEANUP_
CREATE_ANCHOR() int32_t cleanupAnchor =
cleanupGetActionCount()
#define CLEANUP_
GET_ANCHOR()
cleanupGetActionCount()
#define CLEANUP_EXECUTE
( failed ) cleanupExecute( cleanupAnchor
, (failed) )
#define CLEANUP_EXECUTE
_TO( anchor, failed ) cleanupExecuteTo( (anchor)
, (failed) )
/*
* exception hander registration
////////////////////////////////////////////////////////////////////////////////
*/
// functions & macros for exception handling
typedef
struct
SExceptionNode
{
struct
SExceptionNode
*
prev
;
jmp_buf
jb
;
int32_t
code
;
int32_t
maxCleanupAction
;
int32_t
numCleanupAction
;
SCleanupAction
*
cleanupActions
;
}
SExceptionNode
;
void
exceptionPushNode
(
SExceptionNode
*
node
);
void
exceptionPushNode
(
SExceptionNode
*
node
);
int32_t
exceptionPopNode
();
int32_t
exceptionPopNode
();
...
@@ -90,23 +99,23 @@ void exceptionThrow( int code );
...
@@ -90,23 +99,23 @@ void exceptionThrow( int code );
#define TRY(maxCleanupActions) do { \
#define TRY(maxCleanupActions) do { \
SExceptionNode exceptionNode = { 0 }; \
SExceptionNode exceptionNode = { 0 }; \
S
DeferedOperation cleanupActions[maxCleanupActions > 0 ? maxCleanupActions
: 1]; \
S
CleanupAction cleanupActions[(maxCleanupActions) > 0 ? (maxCleanupActions)
: 1]; \
exceptionNode.maxCleanupAction =
maxCleanupActions > 0 ? maxDefered
: 1; \
exceptionNode.maxCleanupAction =
(maxCleanupActions) > 0 ? (maxCleanupActions)
: 1; \
exceptionNode.cleanupActions = cleanupActions; \
exceptionNode.cleanupActions = cleanupActions; \
int32_t cleanupAnchor = 0; \
exceptionPushNode( &exceptionNode ); \
exceptionPushNode( &exceptionNode ); \
int caughtException = setjmp( exceptionNode.jb ); \
int caughtException = setjmp( exceptionNode.jb ); \
if( caughtException == 0 )
if( caughtException == 0 )
#define CATCH( code ) int code = exceptionPopNode(); \
#define CATCH( code ) int code = exceptionPopNode(); \
if( caughtE
e
xception == 1 )
if( caughtException == 1 )
#define FINALLY( code ) int code = exceptionPopNode();
#define FINALLY( code ) int code = exceptionPopNode();
#define END_TRY } while( 0 );
#define END_TRY } while( 0 );
#define THROW( x ) exceptionThrow( (x) )
#define THROW( x ) exceptionThrow( (x) )
#define CAUGHT_EXCEPTION() ((bool)(caughtEexception == 1))
#define CAUGHT_EXCEPTION() ((bool)(caughtException == 1))
#define CLEANUP_EXECUTE() cleanupExecute( &exceptionNode, CAUGHT_EXCEPTION() )
#ifdef __cplusplus
#ifdef __cplusplus
}
}
...
...
src/util/inc/tbuffer.h
浏览文件 @
241f7a22
...
@@ -23,6 +23,58 @@
...
@@ -23,6 +23,58 @@
extern
"C"
{
extern
"C"
{
#endif
#endif
////////////////////////////////////////////////////////////////////////////////
// usage example
/*
#include <stdio.h>
#include "exception.h"
int main( int argc, char** argv ) {
SBufferWriter bw = tbufInitWriter( NULL, false );
TRY( 1 ) {
//--------------------- write ------------------------
// reserve 1024 bytes for the buffer to improve performance
tbufEnsureCapacity( &bw, 1024 );
// reserve space for the interger count
size_t pos = tbufReserve( &bw, sizeof(int32_t) );
// write 5 integers to the buffer
for( int i = 0; i < 5; i++) {
tbufWriteInt32( &bw, i );
}
// write the integer count to buffer at reserved position
tbufWriteInt32At( &bw, pos, 5 );
// write a string to the buffer
tbufWriteString( &bw, "this is a string.\n" );
// acquire the result and close the write buffer
size_t size = tbufTell( &bw );
char* data = tbufGetData( &bw, false );
//------------------------ read -----------------------
SBufferReader br = tbufInitReader( data, size, false );
// read & print out all integers
int32_t count = tbufReadInt32( &br );
for( int i = 0; i < count; i++ ) {
printf( "%d\n", tbufReadInt32(&br) );
}
// read & print out a string
puts( tbufReadString(&br, NULL) );
// try read another integer, this result in an error as there no this integer
tbufReadInt32( &br );
printf( "you should not see this message.\n" );
} CATCH( code ) {
printf( "exception code is: %d, you will see this message after print out 5 integers and a string.\n", code );
// throw it again and the exception will be caught in main
THROW( code );
} END_TRY
tbufCloseWriter( &bw );
return 0;
}
*/
typedef
struct
{
typedef
struct
{
bool
endian
;
bool
endian
;
const
char
*
data
;
const
char
*
data
;
...
@@ -51,7 +103,7 @@ typedef struct {
...
@@ -51,7 +103,7 @@ typedef struct {
size_t
tbufSkip
(
SBufferReader
*
buf
,
size_t
size
);
size_t
tbufSkip
(
SBufferReader
*
buf
,
size_t
size
);
c
har
*
tbufRead
(
SBufferReader
*
buf
,
size_t
size
);
c
onst
char
*
tbufRead
(
SBufferReader
*
buf
,
size_t
size
);
void
tbufReadToBuffer
(
SBufferReader
*
buf
,
void
*
dst
,
size_t
size
);
void
tbufReadToBuffer
(
SBufferReader
*
buf
,
void
*
dst
,
size_t
size
);
const
char
*
tbufReadString
(
SBufferReader
*
buf
,
size_t
*
len
);
const
char
*
tbufReadString
(
SBufferReader
*
buf
,
size_t
*
len
);
size_t
tbufReadToString
(
SBufferReader
*
buf
,
char
*
dst
,
size_t
size
);
size_t
tbufReadToString
(
SBufferReader
*
buf
,
char
*
dst
,
size_t
size
);
...
...
src/util/src/exception.c
浏览文件 @
241f7a22
...
@@ -114,11 +114,19 @@ int32_t cleanupGetActionCount() {
...
@@ -114,11 +114,19 @@ int32_t cleanupGetActionCount() {
}
}
void
cleanupExecute
(
int32_t
anchor
,
bool
failed
)
{
static
void
doExecuteCleanup
(
SExceptionNode
*
node
,
int32_t
anchor
,
bool
failed
)
{
while
(
expList
->
numCleanupAction
>
anchor
)
{
while
(
node
->
numCleanupAction
>
anchor
)
{
--
expList
->
numCleanupAction
;
--
node
->
numCleanupAction
;
SCleanupAction
*
ca
=
expList
->
cleanupActions
+
expList
->
numCleanupAction
;
SCleanupAction
*
ca
=
node
->
cleanupActions
+
node
->
numCleanupAction
;
if
(
failed
||
!
(
ca
->
failOnly
)
)
if
(
failed
||
!
(
ca
->
failOnly
)
)
wrappers
[
ca
->
wrapper
](
ca
);
wrappers
[
ca
->
wrapper
](
ca
);
}
}
}
}
void
cleanupExecuteTo
(
int32_t
anchor
,
bool
failed
)
{
doExecuteCleanup
(
expList
,
anchor
,
failed
);
}
void
cleanupExecute
(
SExceptionNode
*
node
,
bool
failed
)
{
doExecuteCleanup
(
node
,
0
,
failed
);
}
\ No newline at end of file
src/util/src/tbuffer.c
浏览文件 @
241f7a22
...
@@ -33,8 +33,8 @@ size_t tbufSkip(SBufferReader* buf, size_t size) {
...
@@ -33,8 +33,8 @@ size_t tbufSkip(SBufferReader* buf, size_t size) {
return
old
;
return
old
;
}
}
char
*
tbufRead
(
SBufferReader
*
buf
,
size_t
size
)
{
c
onst
c
har
*
tbufRead
(
SBufferReader
*
buf
,
size_t
size
)
{
char
*
ret
=
buf
->
data
+
buf
->
pos
;
c
onst
c
har
*
ret
=
buf
->
data
+
buf
->
pos
;
tbufSkip
(
buf
,
size
);
tbufSkip
(
buf
,
size
);
return
ret
;
return
ret
;
}
}
...
@@ -55,7 +55,7 @@ static size_t tbufReadLength( SBufferReader* buf ) {
...
@@ -55,7 +55,7 @@ static size_t tbufReadLength( SBufferReader* buf ) {
const
char
*
tbufReadString
(
SBufferReader
*
buf
,
size_t
*
len
)
{
const
char
*
tbufReadString
(
SBufferReader
*
buf
,
size_t
*
len
)
{
size_t
l
=
tbufReadLength
(
buf
);
size_t
l
=
tbufReadLength
(
buf
);
char
*
ret
=
buf
->
data
+
buf
->
pos
;
c
onst
c
har
*
ret
=
buf
->
data
+
buf
->
pos
;
tbufSkip
(
buf
,
l
+
1
);
tbufSkip
(
buf
,
l
+
1
);
if
(
ret
[
l
]
!=
0
)
{
if
(
ret
[
l
]
!=
0
)
{
THROW
(
TSDB_CODE_MEMORY_CORRUPTED
);
THROW
(
TSDB_CODE_MEMORY_CORRUPTED
);
...
@@ -80,7 +80,7 @@ size_t tbufReadToString( SBufferReader* buf, char* dst, size_t size ) {
...
@@ -80,7 +80,7 @@ size_t tbufReadToString( SBufferReader* buf, char* dst, size_t size ) {
const
char
*
tbufReadBinary
(
SBufferReader
*
buf
,
size_t
*
len
)
{
const
char
*
tbufReadBinary
(
SBufferReader
*
buf
,
size_t
*
len
)
{
size_t
l
=
tbufReadLength
(
buf
);
size_t
l
=
tbufReadLength
(
buf
);
char
*
ret
=
buf
->
data
+
buf
->
pos
;
c
onst
c
har
*
ret
=
buf
->
data
+
buf
->
pos
;
tbufSkip
(
buf
,
l
);
tbufSkip
(
buf
,
l
);
if
(
len
!=
NULL
)
{
if
(
len
!=
NULL
)
{
*
len
=
l
;
*
len
=
l
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录