Handles(3tcl)

πŸ“¦ version 8.6.3, in ubuntu stonking

✨ NAME ✨

Tcl_HandleAlloc, Tcl_HandleFree, Tcl_HandleTblInit, Tcl_HandleTblRelease, Tcl_HandleTblUseCount, Tcl_HandleWalk, Tcl_HandleXlate β€” Dynamic, handle addressable tables. πŸ’…

bestie this is the Handles(3tcl) manual page, and it's giving "let's manage table entries with textual handles" energy. 🫢

πŸ¦‹ SYNOPSIS πŸ¦‹

#include <tclExtend.h>

void_pt
Tcl_HandleTblInit (const char *handleBase,
                   int         entrySize,
                   int         initEntries);

int
Tcl_HandleTblUseCount (void_pt  headerPtr,
                       int      amount);

void
Tcl_HandleTblRelease (void_pt headerPtr);

void_pt
Tcl_HandleAlloc (void_pt   headerPtr,
                 char     *handlePtr);

void_pt
Tcl_HandleXlate (Tcl_Interp *interp,
                 void_pt     headerPtr,
                 const char *handle);

void_pt
Tcl_HandleWalk (void_pt   headerPtr,
                int      *walkKeyPtr);

void
Tcl_WalkKeyToHandle (void_pt   headerPtr,
                     int       walkKey,
                     char     *handlePtr);

void
Tcl_HandleFree (void_pt headerPtr,
                void_pt entryPtr);

πŸ’– DESCRIPTION πŸ’–

The Tcl handle facility is literally a way to manage table entries that can be referenced by a textual handle from Tcl code. It's for apps that need to create data structures in one command, return a reference (i.e. pointer) to that particular data structure, and then access that data structure in other commands. An example application is file handles. πŸ—‚οΈ

A handle is a base name β€” some unique, meaningful name like file β€” plus a numeric value appended to it (e.g. file3). The handle facility is designed to give you a standard mechanism for building Tcl commands that allocate and access table entries based on an entry index. The tables expand when needed, so do not keep pointers to entries, bestie β€” they become invalid when the table expands. 😭 If the table entries are large or you must keep pointers to the entries, then the entries should be allocated separately and pointers kept in the handle table. A use count is kept on the table. This use count is intended to determine when a table shared by multiple commands is to be released. πŸ‘‘


πŸŽ€ Tcl_HandleTblInit πŸŽ€

Create and initialize a Tcl dynamic handle table. The use count on the table is set to one. ✨

Parameters:

  • handleBase β€” the base name of the handle; the handle will be returned in the form "baseNN", where NN is the table entry number.
  • entrySize β€” the size of an entry, in bytes.
  • initEntries β€” initial size of the table, in entries.

Returns:

A pointer to the table header. πŸ‘‘


πŸ¦‹ Tcl_HandleTblUseCount πŸ¦‹

Alter the handle table use count by the specified amount, which can be positive or negative. Amount may be zero to retrieve the use count. πŸ”’

Parameters:

  • headerPtr β€” pointer to the table header.
  • amount β€” the amount to alter the use count by.

Returns:

The resulting use count.


🌸 Tcl_HandleTblRelease 🌸

Decrement the use count on a Tcl dynamic handle table. If the count goes to zero or negative, then release the table. 🫢

Parameters:

  • headerPtr β€” pointer to the table header.

πŸ’… Tcl_HandleAlloc πŸ’…

Allocate an entry and associate a handle with it.

Parameters:

  • headerPtr β€” a pointer to the table header.
  • handlePtr β€” buffer to return handle in. It must be big enough to hold the name.

Returns:

A pointer to the allocated entry (user part). πŸŽ€


πŸ”₯ Tcl_HandleXlate πŸ”₯

Translate a handle to an entry pointer.

Parameters:

  • interp β€” an error message may be returned in result.
  • headerPtr β€” a pointer to the table header.
  • handle β€” the handle assigned to the entry.

Returns:

A pointer to the entry, or NULL if an error occurred. 🚫


🧚 Tcl_HandleWalk 🧚

Walk through and find every allocated entry in a table. Entries may be deallocated during a walk, but should not be allocated. πŸšΆβ€β™€οΈ

Parameters:

  • headerPtr β€” a pointer to the table header.
  • walkKeyPtr β€” pointer to a variable to use to keep track of the place in the table. The variable should be initialized to -1 before the first call.

Returns:

A pointer to the next allocated entry, or NULL if there are not more.


πŸ“ Tcl_WalkKeyToHandle πŸ“

Convert a walk key, as returned from a call to Tcl_HandleWalk, into a handle. The Tcl_HandleWalk must have succeeded. πŸ”‘

Parameters:

  • headerPtr β€” a pointer to the table header.
  • walkKey β€” the walk key.
  • handlePtr β€” buffer to return handle in. It must be big enough to hold the name.

πŸ’œ Tcl_HandleFree πŸ’œ

Frees a handle table entry. πŸ—‘οΈ

Parameters:

  • headerPtr β€” a pointer to the table header.
  • entryPtr β€” entry to free.

source: Tcl β€” section: Handles(3tcl). that's the whole page, bestie. no cap, go build something iconic. πŸ’…βœ¨πŸ«Ά

πŸ“¦ where this page comes from