Up: Procedural Temporaries   [Index]


6.12.1 e4ll Temporaries Disposal Usage Example

Define an integral to be set by the temporaries tracking mechanism when temporaries need be disposed off:

    int dispose;

Make a record of the defined flag:

    struct x1f4_e2line_type e2line;

See struct x1f4_e2line_type.

    e2line.bits = X1f4_E2LIST_FLATLINE;
    e2line.e2list.flatline_set.class = &dispose;

The record merely registers the dispose existence. Both the dispose flag and the e2line record need exist for as long as tracking temporaries applies.

Declare a routine freeing resources reserved by temporaries:

    int (*dispose_temporaries)(void **);

and a context in which it operates:

    void *disposal_context;

Create the temporaries tracker:

See struct x1f4_e4less_type.

    struct x1f4_e4less_type e4line;
    void *e4less;
    e4line.misslink_set.data = e2line_data;
    x1f4_type_e2list(&e4line.misslink_set);

See x1f4_type_e2list.

    status = x1f4_init_e4ll(&e4less, X1f4_E4LL_MISSLINK, &e4line);
    if (status) {
	/*
	 * no luck, the temporaries disposal mechanism was not created for
	 * there was no memory available
	 */
    } else {
	x1f4_deck_e4ll(e4less, &disposal_context, &dispose_temporaries);
    }

See x1f4_init_e4ll.

See x1f4_deck_e4ll.

The libaime text library needs a temporaries allocator. If using it, link the temporaries allocator/tracker/disposer into the library generation context.

See Text Library.

    struct x1f4_lxtext_type lxnone;

See struct x1f4_lxtext_type.

    struct x1f4_trans_type trans;

See struct x1f4_trans_type.

    x1f4_line_e4ll(e4less, &trans);

See x1f4_line_e4ll.

    lxnone.autolink_set.free = trans.free;
    lxnone.autolink_set.link = trans.link;
    lxnone.autolink_set.mode = trans.mode;
    lxnone.autolink_set.data = trans.context;

Create the text library:

    status = x1f4_init_lxtext(..., ..., &lxnone);

See x1f4_init_lxtext.

Enroll the temporaries tracker into the function call observing schema:

    status = x1f4_pipe_e4ll(e4less, program);
    if (status) {
	/*
	 * no luck, the temporaries disposal mechanism was not recorded with
	 * the function call observing schema
	 */
    }

See x1f4_pipe_e4ll.

program is the executable representation of the procedural program, the one created by x1f4_init_shuffle or one of its peers.

See x1f4_init_shuffle.

Execute the program instructions, one by one, disposing temporaries as needed:

See Procedural Language Interpreter Usage Outline.

context is the program execution context, an application pointer not interpreted by libaime code.

    x1f4_head_shuffle(subtext);
    while (!x1f4_tail_shuffle(subtext)) {
	status = x1f4_slip_shuffle(subtext);

	if (dispose) {
	    int excess;

	    dispose = 0;
	    excess = dispose_temporaries(&disposal_context);
	    if (excess) {
		if (status) {
		} else {
		    status = excess;
		}
	    }
	}

	if (status) {
	    break;
	}
    }

Dispose of the temporaries disposer when done:

    status = x1f4_fini_e4ll(&e4less);

Up: Procedural Temporaries   [Index]