Databases Reference
In-Depth Information
~/X11-R6.9.0/x11perf/do_text.c
#include <X11/Xft/Xft.h>
1
2
3
4
5
6
7
...
static XftFont *aafont;
static XftDraw *aadraw;
static XftColor aacolor;
...
int
InitAAText
(XParms xp, Parms p, int reps){
7
8
9
10
11
12
13
int
InitAAText
(XParms xp, Parms p, int reps){
...
aafont =
XftFontOpenName
(...);
if (aafont == NULL) {
...
return 0;
}
13
14
15
16
17
18
19
}
aadraw =
XftDrawCreate
(...);
if (!
XftColorAllocValue
(..., &aacolor)){
...
XftFontClose
(xp->d, aafont);
XftDrawDestroy
(aadraw);
...
return 0;
}
19
20
21
22
23
24
...
}
...
25
26
27
28
29
30
void
EndAAText
(XParms xp, Parms p){
...
XftDrawDestroy
(aadraw);
XftFontClose
(xp->d, aafont);
XftColorFree
(..., &aacolor);
...
31
}
FIGURE 5.17: Code snippet from x11perf-R6.9.0.
if there were multiple
socket
calls in Figure 5.16, then each
socket
call, along
with its corresponding related APIs, forms a different scenario.
API error-handling specifications. We identify two types of API error-
handling specifications that dictate correct error handling along all paths in
a program: error-check specifications and multiple-API specifications. Error-
check specifications dictate that correct AEC(
a
)'s (API-Error Checks) exist
for each API
a
(which can fail), before the API's return value is used or
the
main
procedure returns. For a given API
a
, absence of AEC(
a
) causes
an error-check violation. Multiple-API specifications dictate that the right
clean up APIs are called along all paths. Clean up APIs are APIs called,
generally before a procedure return or program exit, to free resources such
as memory, sockets, pipes, and files or to rollback the state of a global
resource such as the system registry and databases. For example, in Fig-
ure 5.17,
XftFontColose
(Line 17) and
XftDrawDestroy
(Line 18) are the clean
up APIs in EB(
XftColorAllocValue
). In Figure 5.17, one error-check specifica-
tion (the return value of
XftColorAllocValue
should be checked against
NULL
)
and two multiple-API specifications (
XftFontOpenName
should be followed by
Search WWH ::
Custom Search