static char *rcsid
= "$Header: /f/osi/pepsy/RCS/fre.c,v 7.10 91/03/09 11:55:08 mrose Exp $";
* $Header: /f/osi/pepsy/RCS/fre.c,v 7.10 91/03/09 11:55:08 mrose Exp $
* Revision 7.10 91/03/09 11:55:08 mrose
* Revision 7.9 91/02/22 09:48:58 mrose
* Revision 7.8 91/01/07 12:41:20 mrose
* Revision 7.7 90/12/23 17:24:30 mrose
* Revision 7.6 90/11/11 10:53:52 mrose
* Revision 7.5 90/11/04 19:17:06 mrose
* Revision 7.4 90/10/23 20:43:01 mrose
* Revision 7.3 90/08/18 00:44:26 mrose
* Revision 7.2 90/07/27 08:48:48 mrose
* Revision 7.1 90/07/09 14:52:38 mrose
* Revision 7.0 90/07/01 19:54:20 mrose
* *** empty log message ***
* Acquisition, use, and distribution of this module and related
* materials are subject to the restrictions of a license agreement.
* Consult the Preface in the User's Manual for the full terms of
* These routines are the driving routines for freeing of the data
#include "pepsy-driver.h" /* for PEPSY_VERSION defn */
#define NEXT_TPE(p) p = next_tpe(p)
#define CHKTAG(mod, p, pe) ismatch(p, mod, pe->pe_class, pe->pe_id)
* free an objects data. Basic algorithm is to walk through it twice
* first time freeing all the "children" of the data structure - then
* the second time free the structure itself
fre_obj(parm
, p
, mod
, dofree
)
char *malptr
= NULL
; /* Have we seen a malloc */
int ndofree
= dofree
; /* Does the function below deallocate space */
if (p
->pe_type
!= PE_START
) {
(void) pepsylose (mod
, p
, NULLPE
, "fre_obj: missing PE_START\n");
for (p
++; p
->pe_type
!= PE_END
; NEXT_TPE(p
)) {
* we have to have all these cases here because it is different to the
* situation when the entry is not the main entry of the typereference.
ndofree
= 0; /* we are deallocating space on this level */
if (fre_type(parm
, p
, mod
, ndofree
) != OK
)
if (malptr
&& dofree
) { /* If we saw a malloc free item */
* Handle freeing of single type field. All the more general routines
* fall back to this so we can put the code to free something just
* here once and it will handle all the cases else where
fre_type(parm
, p
, mod
, dofree
)
modtyp
*mod
; /* Module it is from */
case FREE_ONLY
: /* this next entry is for us */
if (fre_type(parm
, p
, mod
, dofree
) != OK
)
if (fre_seq(*(char **) (parm
+ p
->pe_ucode
), p
, mod
, 1) != OK
)
if (fre_seqof(*(char **) (parm
+ p
->pe_ucode
), p
, mod
, 1) != OK
)
if (fre_seq((char *) parm
+ p
->pe_ucode
, p
, mod
, dofree
) != OK
)
if (fre_seqof((char *) parm
+ p
->pe_ucode
, p
, mod
, dofree
) != OK
)
if (p
->pe_type
== EXTOBJ
) {
if (fre_obj(*(char **) (parm
+ p
->pe_ucode
),
(EXT2MOD(mod
, (p
+ 1)))->md_dtab
[p
->pe_tag
],
EXT2MOD(mod
, (p
+ 1)), 1) != OK
)
} else if (p
->pe_type
== SEXTOBJ
) {
if (fre_obj((parm
+ p
->pe_ucode
),
(EXT2MOD(mod
, (p
+ 1)))->md_dtab
[p
->pe_tag
],
EXT2MOD(mod
, (p
+ 1)), dofree
) != OK
)
} else if (p
->pe_type
== SOBJECT
) {
if (fre_obj((char *) parm
+ p
->pe_ucode
, mod
->md_dtab
[p
->pe_tag
], mod
, dofree
) != OK
)
if (fre_obj(*(char **) (parm
+ p
->pe_ucode
),
mod
->md_dtab
[p
->pe_tag
], mod
, 1) != OK
)
if (fre_obj((char *) parm
+ p
->pe_ucode
, mod
->md_dtab
[p
->pe_tag
], mod
, dofree
) != OK
)
if (fre_obj(*(char **) (parm
+ p
->pe_ucode
), mod
->md_dtab
[p
->pe_tag
],
if (fre_choice((char *) parm
+ p
->pe_ucode
, p
, mod
, dofree
) != OK
)
if (fre_choice(*(char **) (parm
+ p
->pe_ucode
), p
, mod
, 1) != OK
)
if (p
[1].pe_type
!= EXTMOD
) {
(void) pepsylose (mod
, p
, NULLPE
, "fre_type:missing EXTMOD");
if (fre_obj(parm
+ p
->pe_ucode
, (EXT2MOD(mod
, (p
+ 1)))->md_dtab
[p
->pe_tag
],
EXT2MOD(mod
, (p
+ 1)), dofree
) != OK
)
if (p
[1].pe_type
!= EXTMOD
) {
(void) pepsylose (mod
, p
, NULLPE
, "fre_type:missing EXTMOD");
if (fre_obj(*(char **) (parm
+ p
->pe_ucode
),
(EXT2MOD(mod
, (p
+ 1)))->md_dtab
[p
->pe_tag
],
EXT2MOD(mod
, (p
+ 1)), 1) != OK
)
* These tests of the pointer don't appear necessary from the
* definition of encoding and decoding but ISODE generates
* freeing code that does these checks and ISODE's ps layer
if (*(char **) (parm
+ p
->pe_ucode
) != NULL
) {
pe_free(*(PE
*) (parm
+ p
->pe_ucode
));
*((PE
*) (parm
+ p
->pe_ucode
)) = NULLPE
;
qb_free((struct qbuf
*) parm
);
if (*(char **) (parm
+ p
->pe_ucode
) != NULL
) {
free(*(char **) (parm
+ p
->pe_ucode
));
*(char **) (parm
+ p
->pe_ucode
) = NULLCP
;
if (*(char **) (parm
+ p
->pe_ucode
) != NULL
) {
qb_free(*(struct qbuf
**) (parm
+ p
->pe_ucode
));
*(struct qbuf
**) (parm
+ p
->pe_ucode
) = (struct qbuf
*)0;
if (*(char **) (parm
+ p
->pe_ucode
) != NULL
) {
pe_free(*(PE
*) (parm
+ p
->pe_ucode
));
*(PE
*) (parm
+ p
->pe_ucode
) = NULLPE
;
if (*(char **) (parm
+ p
->pe_ucode
) != NULL
) {
oid_free(*(OID
*) (parm
+ p
->pe_ucode
));
*(OID
*) (parm
+ p
->pe_ucode
) = NULLOID
;
break; /* can't do anything with this */
if ((FN_PTR(mod
, p
))(parm
) == NOTOK
)
return pepsylose (mod
, p
, NULLPE
,
"fre_type:FN_CALL:call failed");
(void) pepsylose (mod
, p
, NULLPE
, "fre_type: %d not implemented\n",
* free elements of a sequential type. e.g. sequence or set
static fre_seq(parm
, p
, mod
, dofree
)
modtyp
*mod
; /* Module it is from */
int *popt
= NULL
; /* Pointer to optional field */
int optcnt
= 0; /* Number of optionals bits so far */
char *malptr
= NULL
; /* Have we seen a malloc */
int ndofree
= dofree
; /* Does the function below deallocate space */
if (p
->pe_type
!= SEQ_START
&& p
->pe_type
!= SET_START
&& p
->pe_type
!= SSEQ_START
&& p
->pe_type
!= SSET_START
) {
(void) pepsylose (mod
, p
, NULLPE
, "fre_seq: bad starting item %d\n",
if (p
->pe_type
== DFLT_B
)
while (p
->pe_type
!= PE_END
) {
ndofree
= 0; /* we are deallocating space on this level */
popt
= (int *) (parm
+ p
->pe_ucode
);
if (fre_seq(*(char **) (parm
+ p
->pe_ucode
), p
, mod
, 1) != OK
)
if (fre_seqof(*(char **) (parm
+ p
->pe_ucode
), p
, mod
, 1) != OK
)
if (fre_seq((char *) parm
+ p
->pe_ucode
, p
, mod
, ndofree
) != OK
)
if (fre_seqof((char *) parm
+ p
->pe_ucode
, p
, mod
, ndofree
) != OK
)
if (fre_obj((char *) parm
+ p
->pe_ucode
,
mod
->md_dtab
[p
->pe_tag
], mod
, ndofree
) != OK
)
if (fre_obj(*(char **) (parm
+ p
->pe_ucode
),
mod
->md_dtab
[p
->pe_tag
], mod
, 1) != OK
)
if (fre_choice((char *) parm
+ p
->pe_ucode
, p
, mod
, ndofree
) != OK
)
if (fre_choice(*(char **) (parm
+ p
->pe_ucode
), p
, mod
, 1) != OK
)
if (p
[1].pe_type
!= EXTMOD
) {
(void) pepsylose (mod
, p
, NULLPE
, "fre_seq:missing EXTMOD");
if (fre_obj(parm
+ p
->pe_ucode
, (EXT2MOD(mod
, (p
+ 1)))->md_dtab
[p
->pe_tag
],
EXT2MOD(mod
, (p
+ 1)), ndofree
) != OK
)
if (p
[1].pe_type
!= EXTMOD
) {
(void) pepsylose (mod
, p
, NULLPE
, "fre_seq:missing EXTMOD");
if (fre_obj(*(char **) (parm
+ p
->pe_ucode
),
(EXT2MOD(mod
, (p
+ 1)))->md_dtab
[p
->pe_tag
],
EXT2MOD(mod
, (p
+ 1)), 1) != OK
)
if (fre_type(parm
, p
, mod
, ndofree
) != OK
)
if (malptr
&& dofree
) { /* If we saw a malloc free item */
* free all the fields in a SET OF/SEQUENCE OF type structure. We
* must follow the linked list until the end
static fre_seqof(parm
, p
, mod
, dofree
)
modtyp
*mod
; /* Module it is from */
tpe
*start
; /* first entry in list */
if (p
->pe_type
!= SEQOF_START
&& p
->pe_type
!= SETOF_START
&& p
->pe_type
!= SSEQOF_START
&& p
->pe_type
!= SSETOF_START
) {
(void) pepsylose (mod
, p
, NULLPE
, "fre_seqof: illegal field");
for (start
= p
; (char *) parm
!= NULL
; p
= start
) {
if (p
->pe_type
== DFLT_B
)
while (p
->pe_type
!= PE_END
) {
if (fre_seq(*(char **) (parm
+ p
->pe_ucode
), p
, mod
, 1) != OK
)
if (fre_seqof(*(char **) (parm
+ p
->pe_ucode
), p
, mod
, 1) != OK
)
if (fre_seq((char *) parm
+ p
->pe_ucode
, p
, mod
, dofree
) != OK
)
if (fre_seqof((char *) parm
+ p
->pe_ucode
, p
, mod
, dofree
) != OK
)
if (fre_obj(parm
+ p
->pe_ucode
, mod
->md_dtab
[p
->pe_tag
], mod
, 0) != OK
)
if (fre_obj(*(char **) (parm
+ p
->pe_ucode
),
mod
->md_dtab
[p
->pe_tag
], mod
, 1) != OK
)
if (fre_choice((char *) parm
+ p
->pe_ucode
, p
, mod
, 0) != OK
)
if (fre_choice(*(char **)(parm
+ p
->pe_ucode
), p
, mod
, 1) != OK
)
if (p
[1].pe_type
!= EXTMOD
) {
(void) pepsylose (mod
, p
, NULLPE
,
"fre_seqof: missing EXTMOD");
if (fre_obj(parm
+ p
->pe_ucode
, (EXT2MOD(mod
, (p
+ 1)))->md_dtab
[p
->pe_tag
],
EXT2MOD(mod
, (p
+ 1)), 0) != OK
)
if (p
[1].pe_type
!= EXTMOD
) {
(void) pepsylose (mod
, p
, NULLPE
,
"fre_seqof: missing EXTMOD");
if (fre_obj(*(char **) (parm
+ p
->pe_ucode
),
(EXT2MOD(mod
, (p
+ 1)))->md_dtab
[p
->pe_tag
],
EXT2MOD(mod
, (p
+ 1)), 1) != OK
)
if (fre_type(parm
, p
, mod
, 1) != OK
)
parm
= *(char **) (parm
+ p
->pe_ucode
); /* Any more ? */
* free the item of the choice. Use the SCTRL field to determine
* which item is present and then call the appropriate routine to
static fre_choice(parm
, p
, mod
, dofree
)
modtyp
*mod
; /* Module it is from */
char *malptr
= NULL
; /* Have we seen a malloc */
int ndofree
= dofree
; /* Does the function below deallocate space */
if (p
->pe_type
!= CHOICE_START
&& p
->pe_type
!= SCHOICE_START
) {
(void) pepsylose (mod
, p
, NULLPE
,
"fre_choice:CHOICE_START missing found %d\n", p
->pe_type
);
if (p
->pe_type
== DFLT_B
)
if (p
->pe_type
== MEMALLOC
) {
ndofree
= 0; /* we are deallocating space on this level */
if (p
->pe_type
!= SCTRL
) {
(void) pepsylose (mod
, p
, NULLPE
,
"fre_choice: missing SCTRL information\n");
cnt
= *(int *) (parm
+ p
->pe_ucode
);
(void) pepsylose (mod
, p
, NULLPE
,"fre_choice:offset negative %d", cnt
);
for (p
++; p
->pe_type
!= PE_END
; NEXT_TPE(p
)) {
if (fre_type(parm
, p
, mod
, ndofree
) != OK
)
if (malptr
&& dofree
) { /* If we saw a malloc free item */
(void) pepsylose (mod
, p
, NULLPE
, "fre_choice: no choice taken");
* look out for FN_CALL - if this entry is really a FN_CALL return non zero
* Basically we have to stop FN_CALL being tested by hasdata which will call
* the decoding function which is illegal and gives rubbish.
while (p
->pe_type
!= PE_END
) {
(void) pepsylose (mod
, p
, NULLPE
,"callsfn:Corrupted tables:PE_END found\n");
ferr(1, "callsfn:Mangled tables\n");