Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
785d8580
L
libvirt
项目概览
openeuler
/
libvirt
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
L
libvirt
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
785d8580
编写于
3月 08, 2010
作者:
D
David Allan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update hacking.html.in
* Added section on use of goto * Added missing content from HACKING document
上级
aa2f6f96
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
124 addition
and
1 deletion
+124
-1
docs/hacking.html.in
docs/hacking.html.in
+124
-1
未找到文件。
docs/hacking.html.in
浏览文件 @
785d8580
...
...
@@ -43,6 +43,23 @@
The latter test checks for memory leaks.
</p>
<p>
If you encounter any failing tests, the VIR_TEST_DEBUG
environment variable may provide extra information to debug
the failures. Larger values of VIR_TEST_DEBUG may provide
larger amounts of information:
</p>
<pre>
VIR_TEST_DEBUG=1 make check (or)
VIR_TEST_DEBUG=2 make check
</pre>
<p>
Also, individual tests can be run from inside the 'tests/'
directory, like:
</p>
<pre>
./qemuxml2xmltest
</pre>
<li>
Update tests and/or documentation, particularly if you are adding
a new feature or changing the output of a program.
</li>
</ol>
...
...
@@ -241,7 +258,7 @@
<h2><a
name=
"string"
>
String comparisons
</a></h2>
<h2><a
name=
"string
_comparision
"
>
String comparisons
</a></h2>
<p>
Do not use the strcmp, strncmp, etc functions directly. Instead use
...
...
@@ -288,6 +305,46 @@
</ul>
<h2><a
name=
"string_copying"
>
String copying
</a></h2>
<p>
Do not use the strncpy function. According to the man page, it
does
<b>
not
</b>
guarantee a NULL-terminated buffer, which makes
it extremely dangerous to use. Instead, use one of the
functionally equivalent functions:
</p>
<pre>
virStrncpy(char *dest, const char *src, size_t n, size_t destbytes)
</pre>
<p>
The first three arguments have the same meaning as for strncpy;
namely the destination, source, and number of bytes to copy,
respectively. The last argument is the number of bytes
available in the destination string; if a copy of the source
string (including a \0) will not fit into the destination, no
bytes are copied and the routine returns NULL. Otherwise, n
bytes from the source are copied into the destination and a
trailing \0 is appended.
</p>
<pre>
virStrcpy(char *dest, const char *src, size_t destbytes)
</pre>
<p>
Use this variant if you know you want to copy the entire src
string into dest. Note that this is a macro, so arguments could
be evaluated more than once. This is equivalent to
virStrncpy(dest, src, strlen(src), destbytes)
</p>
<pre>
virStrcpyStatic(char *dest, const char *src)
</pre>
<p>
Use this variant if you know you want to copy the entire src
string into dest *and* you know that your destination string is
a static string (i.e. that sizeof(dest) returns something
meaningful). Note that this is a macro, so arguments could be
evaluated more than once. This is equivalent to
virStrncpy(dest, src, strlen(src), sizeof(dest)).
</p>
<h2><a
name=
"strbuf"
>
Variable length string buffer
</a></h2>
<p>
...
...
@@ -389,6 +446,72 @@
of arguments.
</p>
<h2><a
name=
"goto"
>
Use of goto
</a></h2>
<p>
The use of goto is not forbidden, and goto is widely used
throughout libvirt. While the uncontrolled use of goto will
quickly lead to unmaintainable code, there is a place for it in
well structured code where its use increases readability and
maintainability. In general, if goto is used for error
recovery, it's likely to be ok, otherwise, be cautious or avoid
it all together.
</p>
<p>
The typical use of goto is to jump to cleanup code in the case
of a long list of actions, any of which may fail and cause the
entire operation to fail. In this case, a function will have a
single label at the end of the function. It's almost always ok
to use this style. In particular, if the cleanup code only
involves free'ing memory, then having multiple labels is
overkill. VIR_FREE() and every function named XXXFree() in
libvirt is required to handle NULL as its arg. Thus you can
safely call free on all the variables even if they were not yet
allocated (yes they have to have been initialized to NULL).
This is much simpler and clearer than having multiple labels.
</p>
<p>
There are a couple of signs that a particular use of goto is not
ok:
</p>
<ul>
<li>
You're using multiple labels. If you find yourself using
multiple labels, you're strongly encouraged to rework your code
to eliminate all but one of them.
</li>
<li>
The goto jumps back up to a point above the current line of
code being executed. Please use some combination of looping
constructs to re-execute code instead; it's almost certainly
going to be more understandable by others. One well-known
exception to this rule is restarting an i/o operation following
EINTR.
</li>
<li>
The goto jumps down to an arbitrary place in the middle of a
function followed by further potentially failing calls. You
should almost certainly be using a conditional and a block
instead of a goto. Perhaps some of your function's logic would
be better pulled out into a helper function.
</li>
</ul>
<p>
Although libvirt does not encourage the Linux kernel wind/unwind
style of multiple labels, there's a good general discussion of
the issue archived at
<a
href=
http://kerneltrap.org/node/553/2131
>
KernelTrap
</a>
</p>
<p>
When using goto, please use one of these standard labels if it
makes sense:
</p>
<pre>
error: A path only taken upon return with an error code
cleanup: A path taken upon return with success code + optional error
no_memory: A path only taken upon return with an OOM error code
retry: If needing to jump upwards (eg retry on EINTR)
</pre>
<h2><a
name=
"committers"
>
Libvirt commiters guidelines
</a></h2>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录