Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/lib/libast/cdt/dtclose.c
1810 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 1985-2011 AT&T Intellectual Property *
5
* and is licensed under the *
6
* Eclipse Public License, Version 1.0 *
7
* by AT&T Intellectual Property *
8
* *
9
* A copy of the License is available at *
10
* http://www.eclipse.org/org/documents/epl-v10.html *
11
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12
* *
13
* Information and Software Systems Research *
14
* AT&T Research *
15
* Florham Park NJ *
16
* *
17
* Glenn Fowler <[email protected]> *
18
* David Korn <[email protected]> *
19
* Phong Vo <[email protected]> *
20
* *
21
***********************************************************************/
22
#include "dthdr.h"
23
24
/* Close a dictionary
25
**
26
** Written by Kiem-Phong Vo (11/15/2010)
27
*/
28
#if __STD_C
29
int dtclose(Dt_t* dt)
30
#else
31
int dtclose(dt)
32
Dt_t* dt;
33
#endif
34
{
35
int ev, type;
36
Dt_t pdt;
37
Dtdisc_t *disc = dt->disc;
38
39
if(!dt || dt->nview > 0 ) /* can't close if being viewed */
40
return -1;
41
42
if(disc && disc->eventf) /* announce closing event */
43
ev = (*disc->eventf)(dt, DT_CLOSE, (Void_t*)1, disc);
44
else ev = 0;
45
if(ev < 0) /* cannot close */
46
return -1;
47
48
if(dt->view) /* turn off viewing at this point */
49
dtview(dt,NIL(Dt_t*));
50
51
type = dt->data->type; /* save before memory is freed */
52
memcpy(&pdt, dt, sizeof(Dt_t));
53
54
if(ev == 0 ) /* release all allocated data */
55
{ (void)(*(dt->meth->searchf))(dt,NIL(Void_t*),DT_CLEAR);
56
(void)(*dt->meth->eventf)(dt, DT_CLOSE, (Void_t*)0);
57
/**/DEBUG_ASSERT(!dt->data);
58
}
59
if(!(type&DT_INDATA) )
60
(void)free(dt);
61
62
if(disc && disc->eventf) /* announce end of closing activities */
63
(void)(*disc->eventf)(&pdt, DT_ENDCLOSE, (Void_t*)0, disc);
64
65
return 0;
66
}
67
68