cffi(3tcl)

๐Ÿ“ฆ version 2.0.3, in nixpkgs unstable

๐Ÿ’– cffi(3tcl) โ€” Tcl CFFI package, bestie edition ๐Ÿ’–

๐ŸŒธ NAME ๐ŸŒธ

cffi โ€” Commands in namespace cffi.

โœจ SYNOPSIS โœจ

okay bestie, hereโ€™s the whole command menu verbatim, no cap:

alias subcommand ...
alias body alias_name
alias clear
alias define name definition
alias define aliasdefs
alias delete pattern
alias list ?pattern?
alias load alias_set
arena subcommand ...
arena allocate sizespec ?tag?
arena new typespec initializer ?tag?
arena popframe
arena pushframe ?size?
arena pushframe size ?tag?
call fnptr ?args?
callback subcommand ...
callback free cb
callback new protoname cmdprefix error_value
enum subcommand ...
enum alias enumname enumdefs typedecl
enum clear
enum define enumname enumdefs
enum delete pattern
enum flags enumname membernames
enum list pattern
enum mask enumname membernames
enum members enumname
enum name enumname membervalue ?default?
enum names enumname
enum sequence enumname membernames ?start?
enum unmask enumname mask
enum value enumname membername ?default?
help subcommand ...
help alias NAME
help enum NAME
help function NAME
help functions ?PATTERN?
help struct NAME
help union NAME
limits type
memory subcommand ...
memory allocate sizespec ?tag?
memory fill pointer bytevalue count ?offset?
memory free pointer
memory frombinary bin_value ?tag?
memory fromstring value ?encoding?
memory fromunistring value
memory fromwinstring value
memory get pointer typespec ?index?
memory get! pointer typespec ?index?
memory new typespec initializer ?tag?
memory set pointer typespec value ?index?
memory set! pointer typespec value ?index?
memory tobinary pointer size ?offset?
memory tobinary! pointer size ?offset?
memory tostring pointer ?encoding? ?offset?
memory tostring! pointer ?encoding? ?offset?
memory tounistring pointer ?offset?
memory tounistring! pointer ?offset?
memory towinstring pointer ?offset?
memory towinstring! pointer ?offset?
pkgconfig subcommand ...
pkgconfig get key
pkgconfig list
pointer subcommand ...
pointer address pointer
pointer cast pointer ?TAG?
pointer castable subtags supertag
pointer castables
pointer check pointer
pointer compare ptr1 ptr2
pointer counted pointer
pointer dispose pointer
pointer info pointer
pointer invalidate pointer
pointer isnull pointer
pointer isvalid pointer
pointer list ?tag?
pointer make address ?tag?
pointer pin pointer
pointer safe pointer
pointer tag pointer
pointer uncastable tag
prototype subcommand ...
prototype delete pattern
prototype function name fntype parameters
prototype list ?pattern?
prototype stdcall name fntype parameters
savederrors
type subcommand ...
type count type
type frombinary typespec value
type info typedecl ?args?
type size type ?args?
type tobinary typespec value
Interface create OBJNAME ?args?
Interface new ?args?
INTERFACEOBJ id
INTERFACEOBJ methods methodlist ?args?
INTERFACEOBJ stdmethods methodlist ?args?
Struct create OBJNAME definition ?args?
Struct new definition ?args?
STRUCTOBJ allocate ?args?
STRUCTOBJ describe
STRUCTOBJ fieldpointer pointer fieldname ?tag? ?index?
STRUCTOBJ free pointer
STRUCTOBJ frombinary bin_value
STRUCTOBJ fromnative pointer ?index?
STRUCTOBJ fromnative! pointer ?index?
STRUCTOBJ getnative pointer fieldname ?index?
STRUCTOBJ getnative! pointer fieldname ?index?
STRUCTOBJ getnativefields pointer fieldnames ?index?
STRUCTOBJ getnativefields! pointer fieldnames ?index?
STRUCTOBJ info ?args?
STRUCTOBJ name
STRUCTOBJ new ?initval?
STRUCTOBJ setnative pointer fieldname value ?index?
STRUCTOBJ setnative! pointer fieldname value ?index?
STRUCTOBJ size ?args?
STRUCTOBJ tobinary dict_value
STRUCTOBJ tonative pointer initializer ?index?
STRUCTOBJ tonative! pointer initializer ?index?
Union create OBJNAME definition ?args?
Union new definition ?args?
UNIONOBJ decode field uvalue
UNIONOBJ describe
UNIONOBJ encode field value
UNIONOBJ info
UNIONOBJ name
UNIONOBJ size
Wrapper create OBJNAME path
Wrapper new path
WRAPPEROBJ destroy
WRAPPEROBJ addressof symbol
WRAPPEROBJ function fnname fntype parameters
WRAPPEROBJ functions fnlist ?args?
WRAPPEROBJ path
WRAPPEROBJ stdcall fnname fntype parameters
WRAPPEROBJ stdcalls fnlist ?args?

๐Ÿฆ‹ ::CFFI ๐Ÿฆ‹

This is the reference for commands in the cffi namespace. See the Start page [URL: cffi.html] for an introductory usage guide. See Concepts for a mapping of C types and program elements to the script level.

The package is loaded in standard fashion with package require:

package require cffi

๐Ÿ› ๏ธ COMMANDS ๐Ÿ› ๏ธ

๐ŸŽ€ alias (::cffi) ๐ŸŽ€

A command ensemble.

alias subcommand ...

Description

The ensemble supports the following subcommands:

  • body โ€” Returns the resolved body of an alias.
  • clear โ€” Deletes all aliases from the interpreter.
  • define โ€” Defines one or more type aliases.
  • delete โ€” Deletes aliases matching a pattern.
  • list โ€” Returns a list of aliases that match the specified pattern.
  • load โ€” Loads predefined type aliases.

Refer to the documentation of each subcommand for details.

๐Ÿ’… alias body (::cffi) ๐Ÿ’…

Returns the resolved body of an alias.

alias body alias_name

Parameters

  • alias_name โ€” Name of alias to be retrieved.

Description

The alias must be one defined in the current scope.

Return value

Returns the resolved body of an alias.

๐Ÿงน alias clear (::cffi) ๐Ÿงน

Deletes all aliases from the interpreter.

alias clear

๐Ÿช„ alias define (::cffi) ๐Ÿช„

Defines one or more type aliases.

alias define name definition
alias define aliasdefs

Parameters

  • aliasdefs โ€” Dictionary mapping alias names to their definition.
  • definition โ€” Definition for the alias.
  • name โ€” Name for type alias. Must begin with an alphabetic character and may contain alphanumerics and underscore.

Description

Given two arguments, creates an alias of the given name for passed definition. If a single argument is provided, it must be a dictionary mapping alias names to their definitions.

An error will be raised if an alias name matches a built-in type or if an alias of that name already exists with a different definition in the same scope.

The definition may itself be based on an existing alias. In this case the existing alias is immediately resolved and expanded as part of the definition so further changes to it are not reflected in the alias being defined.

See Type aliases for more on type aliases.

๐Ÿ—‘๏ธ alias delete (::cffi) ๐Ÿ—‘๏ธ

Deletes aliases matching a pattern.

alias delete pattern

Parameters

  • pattern โ€” Pattern to match against aliases.

Description

The command deletes all aliases whose name matches the specified pattern. The conditions for matching the pattern are:

  • the tail of the pattern must match the tail of the alias name using Tcl's glob pattern matching rules.
  • the scope component of the alias name must match exactly.

๐Ÿ“‹ alias list (::cffi) ๐Ÿ“‹

Returns a list of aliases that match the specified pattern.

alias list ?pattern?

Parameters

  • pattern โ€” Pattern to match against aliases. Optional, default *.

Description

The command returns the alias names that match the specified pattern. The conditions for matching the pattern are:

  • the tail of the pattern must match the tail of the alias name using Tcl's glob pattern matching rules.
  • the scope component of the alias name must match the pattern's scope exactly. If the pattern does not include a scope, the caller's scope is assumed.

Return value

Returns a list of aliases that match the specified pattern.

๐Ÿ“ฆ alias load (::cffi) ๐Ÿ“ฆ

Loads predefined type aliases.

alias load alias_set

Parameters

  • alias_set โ€” The alias set to load.

Description

The aliases are loaded into the ::cffi::c scope. Since this scope is also searched when looking up aliases, the aliases defined by this command are available in all namespaces without explicit qualification.

The possible values of $alias_set are C, win32 (Windows only), or posix (platform dependent).

The C predefined alias set includes _Bool, bool, int8_t, uint8_t, int16_t, uint16_t, int32_t, uint32_t, int64_t, uint64_t, size_t, ssize_t.

The win32 predefined alias set includes BOOL, BOOLEAN, BYTE, CHAR, DWORD, DWORDLONG, DWORD_PTR, HALF_PTR, HANDLE, INT, INT_PTR, LONG, LONGLONG, LONG_PTR, LPARAM, LPVOID, LRESULT, SHORT, SIZE_T, SSIZE_T, UCHAR, UINT, UINT_PTR, ULONG, ULONGLONG, ULONG_PTR, USHORT, WORD, WPARAM.

The posix alias set is platform dependent. In POSIX compliant environments, it includes blkcnt_t, blksize_t, clock_t, dev_t, fsblkcnt_t, fsfilcnt_t, gid_t, id_t, ino_t, key_t, mode_t, nlink_t, off_t, pid_t, size_t, ssize_t, suseconds_t, time_t, uid_t. On Windows, it only includes dev_t, ino_t, off_t, time_t.

๐ŸŸ๏ธ arena (::cffi) ๐ŸŸ๏ธ

A command ensemble.

arena subcommand ...

Description

The ensemble supports the following subcommands:

  • allocate โ€” Allocates memory in the current arena frame in the memory arena.
  • new โ€” Allocates memory in the current arena for a type and initializes it.
  • popframe โ€” Pops the current frame from the memory arena.
  • pushframe โ€” Pushes a new stack frame on the memory arena.

Refer to the documentation of each subcommand for details.

๐Ÿงฑ arena allocate (::cffi) ๐Ÿงฑ

Allocates memory in the current arena frame in the memory arena.

arena allocate sizespec ?tag?

Parameters

  • sizespec โ€” Requested size of memory block. This may be specified either as an integer value or a type specification (optional).
  • tag โ€” Tag for returned pointer. Optional, default "".

Description

The allocated memory will stay allocated until the frame is destroyed with arena popframe. The size $sizespec may be specified as a positive integer or a CFFI type declaration in which case the memory allocated is that of the type's size.

Return value

Returns a safe pointer to the allocation.

See also

arena new

๐ŸŒฑ arena new (::cffi) ๐ŸŒฑ

Allocates memory in the current arena for a type and initializes it.

arena new typespec initializer ?tag?

Parameters

  • typespec โ€” A type declaration.
  • initializer โ€” The type-specific value to use to initialize allocated memory.
  • tag โ€” the optional tag for the returned pointer. Optional, default "". ๐Ÿ’…

โœจ Description โœจ

The $typespec argument can be, like, any type specification, bestie. And if an array is specified with a larger size than the number of elements in $initializer, the leftover elements are zeroed out. No cap. ๐Ÿซถ

The returned memory gets freed when the arena frame is freed with arena popframe. Periodt.

๐ŸŽ Return value ๐ŸŽ

Returns a safe pointer to the allocated memory. Slay.

๐Ÿ‘€ See also ๐Ÿ‘€

arena allocate โ€” yes, it's pointing back at itself, iconic behavior honestly. ๐Ÿ’€


๐Ÿซง arena popframe (::cffi) ๐Ÿซง

Pops the current frame from the memory arena.

arena popframe

๐Ÿ’– Description ๐Ÿ’–

All allocations from the popped frame are freed, and pointers to these are unregistered. Clean sweep, no leftovers. โœจ


๐Ÿงš arena pushframe (::cffi) ๐Ÿงš

Pushes a new stack frame on the memory arena.

arena pushframe ?size?
arena pushframe size ?tag?

๐Ÿงพ Parameters ๐Ÿงพ

  • sizespec โ€” requested size of the memory block. This may be specified either as an integer value or a type specification (optional).
  • tag โ€” tag for the returned pointer if $size is specified (optional).

๐ŸŒธ Description ๐ŸŒธ

This command allocates a new frame in the memory arena stack. All allocations from this frame stay valid only until the corresponding call to arena popframe. Like, do not forget the pop, bestie. ๐Ÿ˜ญ

If no arguments are specified, the command initializes an empty frame. Otherwise it allocates storage of $sizespec bytes within the new frame and returns a pointer to it. The size $sizespec may be specified as a positive integer, or as a CFFI type declaration โ€” in which case the memory allocated is that of the type's size. ๐ŸŽ€

๐ŸŽ Return value ๐ŸŽ

Returns an empty string if no arguments were specified, or a safe pointer. ๐Ÿ’–

๐Ÿ‘€ See also ๐Ÿ‘€

arena allocate, arena popframe.


๐Ÿ“ž call (::cffi) ๐Ÿ“ž

Invokes a C function through a function pointer.

call fnptr ?args?

๐Ÿงพ Parameters ๐Ÿงพ

  • fnptr โ€” a pointer value tagged with a prototype.
  • args โ€” additional arguments to pass to the C function.

๐Ÿ’œ Description ๐Ÿ’œ

The passed pointer $fnptr tag must correspond to a function prototype defined through the prototype function or prototype stdcall commands. That's the vibe check it has to pass. โœจ

๐ŸŽ Return value ๐ŸŽ

Returns the value returned by the invoked C function. Main character return value energy. ๐Ÿ‘‘


๐Ÿฆ‹ callback (::cffi) ๐Ÿฆ‹

A command ensemble.

callback subcommand ...

๐ŸŒˆ Description ๐ŸŒˆ

The ensemble supports these subcommands:

  • free โ€” frees a callback pointer.
  • new โ€” wraps a script level command into a C function.

Refer to the documentation of each subcommand for details. ๐Ÿ’…


๐Ÿงฝ callback free (::cffi) ๐Ÿงฝ

Frees a callback pointer.

callback free cb

๐Ÿงพ Parameters ๐Ÿงพ

  • cb โ€” a function pointer allocated with callback new.

๐Ÿช„ callback new (::cffi) ๐Ÿช„

Wraps a script level command into a C function.

callback new protoname cmdprefix error_value

๐Ÿงพ Parameters ๐Ÿงพ

  • protoname โ€” the name of a prototype created through the prototype function or prototype stdcall commands.
  • cmdprefix โ€” the command prefix that should be invoked when the created C function is called.
  • error_value โ€” the value that should be returned if the command prefix raises an exception. This is optional if the function prototype specifies the void return type.

๐Ÿ’ซ Description ๐Ÿ’ซ

The returned function pointer can be invoked through the call command, but the common usage is for it to be passed to a C function that takes a callback function as an argument. Very "pass the aux" of it all. ๐ŸŽง

Invoking the function pointer will result in $cmdprefix being called with the additional arguments passed in the invocation. These must match the parameter types of the prototype specified in the callback definition. No improvising, bestie. ๐Ÿ™ˆ

The type declarations in prototypes used for callbacks have certain restrictions. These arise because the "data flow" is now from script to the C shared library. It's giving reverse directions. ๐ŸŒ€

The parameter and return type are restricted to be scalar values and strings.

  • The out, inout and retval annotations are not permitted. This means any values to be returned to the shared library must be through explicit raw pointers.
  • All pointer type declarations must have the unsafe annotation. Other pointer safety annotations counted, dispose, disposeonsuccess cannot be specified.
  • The value checking annotations zero, nonzero, positive and nonnegative cannot be specified for the prototype return type.
  • The error handling annotations errno, winerror, lasterror and onerror cannot be specified.
  • The storeonerror and storealways annotations cannot be specified.

When $cmdprefix is called from a C function as a callback, it is executed in the Tcl context from which the C function was called and thus has access to the script level local variables etc. So yeah, it can see the group chat. ๐Ÿ’ฌ

When no longer needed, the callback should be freed with the callback free command. Do not leave it lying around like a read receipt. ๐Ÿ˜ญ

๐ŸŽ Return value ๐ŸŽ

Returns a callback function pointer that can be called from C native code. ๐Ÿ’…


๐Ÿ”ฎ enum (::cffi) ๐Ÿ”ฎ

A command ensemble.

enum subcommand ...

๐ŸŒŸ Description ๐ŸŒŸ

The ensemble supports these subcommands:

  • alias โ€” defines a new enumeration and alias of the same name.
  • clear โ€” deletes all enumerations from the interpreter.
  • define โ€” defines a new enumeration.
  • delete โ€” deletes enumerations.
  • flags โ€” defines an enumeration as bit flags.
  • list โ€” lists enumerations.
  • mask โ€” returns an integer mask formed by bitwise OR-ing the passed enumeration members.
  • members โ€” returns a dictionary containing the members in an enumeration.
  • name โ€” returns the symbolic name of a value in an enumeration.
  • names โ€” returns a list containing the names of members in an enumeration.
  • sequence โ€” defines an enumeration with consecutive member values.
  • unmask โ€” returns a list of enumeration member names corresponding to the bits set in $mask.
  • value โ€” returns the value of an enumeration member.

Refer to the documentation of each subcommand for details. ๐Ÿซถ


๐Ÿท๏ธ enum alias (::cffi) ๐Ÿท๏ธ

Defines a new enumeration and alias of the same name.

enum alias enumname enumdefs typedecl

๐Ÿงพ Parameters ๐Ÿงพ

  • enumname โ€” name of the enumeration.
  • enumdefs โ€” dictionary of enumeration member names to their values.
  • typedecl โ€” the type to be used for the alias. Should have an integer base type and may contain other attributes except enum.

๐Ÿ’– Description ๐Ÿ’–

The created alias has the same qualified name as the enum and has the corresponding enum attribute. Matching set, cute. ๐ŸŽ€

๐ŸŽ Return value ๐ŸŽ

Returns the fully qualified enumeration name. โœจ


๐Ÿงน enum clear (::cffi) ๐Ÿงน

Deletes all enumerations from the interpreter.

enum clear

๐Ÿงฑ enum define (::cffi) ๐Ÿงฑ

Defines a new enumeration.

enum define enumname enumdefs

๐Ÿงพ Parameters ๐Ÿงพ

  • enumname โ€” name of the enumeration.
  • enumdefs โ€” dictionary of enumeration member names to their values.

๐ŸŒธ Description ๐ŸŒธ

Parameter declarations can reference the enumeration to indicate that the corresponding symbol names are acceptable as arguments and will be replaced by the corresponding value in the function call. Enumeration member values must be integers. No fanciness, just numbers. ๐Ÿ”ข

๐ŸŽ Return value ๐ŸŽ

Returns the fully qualified enumeration name. ๐Ÿ’œ


๐Ÿ—‘๏ธ enum delete (::cffi) ๐Ÿ—‘๏ธ

Deletes enumerations.

enum delete pattern

๐Ÿงพ Parameters ๐Ÿงพ

  • pattern โ€” pattern to match.

๐Ÿ’ซ Description ๐Ÿ’ซ

The command deletes all enumerations whose name matches the specified pattern. The conditions for matching the pattern are:

  • the tail of the pattern must match the tail of the enumeration name using Tcl's glob pattern matching rules.
  • the scope component of the enumeration name must match exactly.

So it's globby at the end, exact at the front. Respect the structure, bestie. ๐Ÿงš


๐Ÿšฉ enum flags (::cffi) ๐Ÿšฉ

Defines an enumeration as bit flags.

enum flags enumname membernames

๐Ÿงพ Parameters ๐Ÿงพ

  • enumname โ€” name of the enumeration.
  • membernames โ€” list of names of the enumeration members.

๐ŸŒˆ Description ๐ŸŒˆ

For example,

enum flags E {A B C}

would define an enumeration with A, B, C values being 1, 2 and 4. Bit math, but make it fashion. ๐Ÿ’…

๐ŸŽ Return value ๐ŸŽ

Returns the fully qualified enumeration name. โญ


๐Ÿ“‹ enum list (::cffi) ๐Ÿ“‹

Lists enumerations.

enum list pattern

๐Ÿงพ Parameters ๐Ÿงพ

  • pattern โ€” pattern to match.

๐ŸŒŸ Description ๐ŸŒŸ

The command returns the names of all enumerations whose name matches the specified pattern. The conditions for matching the pattern are:

  • the tail of the pattern must match the tail of the enumeration name using Tcl's glob pattern matching rules.
  • the scope component of the enumeration name must match exactly.

Same matching rules as delete. Consistency ate. ๐Ÿ“


๐ŸŽญ enum mask (::cffi) ๐ŸŽญ

Returns an integer mask formed by bitwise OR-ing the passed enumeration members.

enum mask enumname membernames

๐Ÿงพ Parameters ๐Ÿงพ

  • enumname โ€” name of the enumeration in the current scope.
  • membernames โ€” list of member names and integer values.

๐ŸŽ Return value ๐ŸŽ

Returns an integer mask formed by bitwise OR-ing the passed enumeration members. Bitwise OR is literally the moment. ๐Ÿ”ฅ

๐Ÿ‘€ See also ๐Ÿ‘€

enum unmask.


๐Ÿงบ enum members (::cffi) ๐Ÿงบ

Returns a dictionary containing the members in an enumeration.

enum members enumname

๐Ÿงพ Parameters ๐Ÿงพ

  • enumname โ€” name of the enumeration whose elements are to be returned.

๐ŸŽ Return value ๐ŸŽ

Returns a dictionary containing the members in an enumeration. Dictionary delivery service. ๐ŸŽ


๐Ÿท๏ธ enum name (::cffi) ๐Ÿท๏ธ

Returns the symbolic name of a value in an enumeration.

enum name enumname membervalue ?default?

๐Ÿงพ Parameters ๐Ÿงพ

  • enumname โ€” name of the enumeration.
  • membervalue โ€” value of an enumeration member.
  • default โ€” value to be returned if the member value is not found.

๐Ÿ’– Description ๐Ÿ’–

The command will raise an error if $membervalue is not present in the enumeration and no default is provided, or if $enumname is itself undefined. So like, have a backup plan or catch the error. ๐Ÿ˜ญ

๐ŸŽ Return value ๐ŸŽ

Returns the symbolic name of a value in an enumeration. ๐ŸŒธ


๐Ÿ“› enum names (::cffi) ๐Ÿ“›

Returns a list containing the names of members in an enumeration.

enum names enumname

๐Ÿงพ Parameters ๐Ÿงพ

  • enumname โ€” name of the enumeration whose element names are to be returned.

๐ŸŽ Return value ๐ŸŽ

Returns a list containing the names of members in an enumeration. Name drop, but organized. โœจ


๐Ÿ”ข enum sequence (::cffi) ๐Ÿ”ข

Defines an enumeration with consecutive member values.

enum sequence enumname membernames ?start?

๐Ÿงพ Parameters ๐Ÿงพ

  • enumname โ€” name of the enumeration.
  • membernames โ€” list of names of the enumeration members.
  • start โ€” the value of the first enumeration member. Optional, default 0. ๐ŸŒธ

Description

Every element of $membernames should hold one or two things: the first is the member's name, and the second โ€” if it's even there โ€” is its value. If that second element is missing, the member just gets a value one greater than whatever the previous member got. And the very first member gets assigned 0 if you never gave it an explicit value. Cute and predictable, honestly. โœจ

$start is only hanging around for backward compatibility, bestie โ€” it's how you say which value the sequence starts at. But for future compatibility, if you want a starting value that isn't the default zero, use the two-element form for the first enum member instead. iykyk. ๐Ÿ’…

Return value

Returns the fully qualified enumeration name. ๐ŸŽ€


โœจ enum unmask โœจ

Gives you back a list of enumeration member names matching whichever bits are set in $mask. It's giving reverse-engineering but make it fashion. ๐Ÿ”

enum unmask enumname mask

Parameters

  • enumname โ€” name of the enumeration.
  • mask โ€” integer bit mask value.

Description

Heads up: the last element of the returned list is $mask itself. ๐Ÿซถ Generally your enumeration should be made of values that don't have overlapping bits set (the usual vibe is a single bit set per member value). This isn't enforced โ€” nothing's gonna stop you โ€” but the results might not be what you expected if that condition isn't met. You've been warned, babe. ๐Ÿ’€

Return value

Returns a list of enumeration member names corresponding to the bits set in $mask.

See also

enum mask


โœจ enum value โœจ

Hands you the value of a single enumeration member. Simple, iconic, does exactly what it says. โญ

enum value enumname membername ?default?

Parameters

  • enumname โ€” name of the enumeration.
  • membername โ€” name of the enumeration member to retrieve.
  • default โ€” default value to be returned if the membername is not found.

Description

This one raises an error ๐Ÿ˜ญ if $membername isn't present in the enumeration and you didn't provide a default โ€” or if $enumname itself is undefined. No default, no vibes.

Return value

Returns the value of an enumeration member.


โœจ help โœจ

A command ensemble, bestie. A whole little family of helpers. ๐ŸŽ€

help subcommand ...

Description

The ensemble supports these subcommands:

  • alias โ€” returns a string describing an alias definition.
  • enum โ€” returns a string describing an enum definition.
  • function โ€” returns a string describing the syntax and parameter definitions for a CFFI wrapped function.
  • functions โ€” returns a list of CFFI-wrapped functions matching the pattern PATTERN.
  • struct โ€” returns a string describing field types in a Struct.
  • union โ€” returns a string describing field types in a Union.

Refer to the documentation of each subcommand for the details. ๐Ÿ’–


โœจ help alias โœจ

Returns a string describing an alias definition.

help alias NAME

Parameters

  • NAME โ€” name of a alias.

Return value

Returns a string describing an alias definition.


โœจ help enum โœจ

Returns a string describing an enum definition.

help enum NAME

Parameters

  • NAME โ€” name of a enum.

Return value

Returns a string describing an enum definition.


โœจ help function โœจ

Returns a string describing the syntax and parameter definitions for a CFFI wrapped function.

help function NAME

Parameters

  • NAME โ€” name of a wrapped function.

Return value

Returns a string describing the syntax and parameter definitions for a CFFI wrapped function.


โœจ help functions โœจ

Returns a list of CFFI-wrapped functions matching the pattern PATTERN. It's basically a roster of your wrapped functions. ๐Ÿ“‹

help functions ?PATTERN?

Parameters

  • PATTERN โ€” glob pattern to match. Optional, default *.

Description

Important lil note: just like Tcl's info commands, the pattern is interpreted relative to the current namespace. So if you want the list of commands inside a namespace, you gotta include the namespace in the pattern too. Like this:

cffi::help functions ::libzip::*

That's the move. ๐Ÿซถ

Return value

Returns a list of CFFI-wrapped functions matching the pattern PATTERN.


โœจ help struct โœจ

Returns a string describing field types in a Struct.

help struct NAME

Parameters

  • NAME โ€” name of a Struct.

Return value

Returns a string describing field types in a Struct.


โœจ help union โœจ

Returns a string describing field types in a Union.

help union NAME

Parameters

  • NAME โ€” name of a Union.

Return value

Returns a string describing field types in a Union.


โœจ limits โœจ

Gets you the lower and upper limits for an integral base type. No more guessing, no more vibes-based arithmetic. ๐Ÿ”ข

limits type

Parameters

  • type โ€” the base type.

Return value

Returns a pair containing the minimum and maximum values for the specified type.


โœจ memory โœจ

Another command ensemble โ€” and honestly this one is the whole memory-management main character. ๐Ÿ‘‘

memory subcommand ...

Description

The ensemble supports these subcommands:

  • allocate โ€” allocates memory of the specified size.
  • fill โ€” fills memory with a specified value.
  • free โ€” frees the memory referenced by the passed pointer.
  • frombinary โ€” allocates memory and copied the passed Tcl binary string into it.
  • fromstring โ€” allocates memory and stores a Tcl string in it in the specified encoding.
  • fromunistring โ€” allocates memory and stores a Tcl string as a sequence of Tcl_UniChars.
  • fromwinstring โ€” allocates memory and stores a Tcl string as a sequence of winchars.
  • get โ€” converts a native value in memory into a Tcl script level value.
  • get! โ€” converts a native value in memory into a Tcl script level value.
  • new โ€” allocates memory for a type and initializes it.
  • set โ€” converts a value as per a type specification and stores it in memory in native form.
  • set! โ€” converts a value as per a type specification and stores it in memory in native form.
  • tobinary โ€” returns the content of a memory block as a Tcl binary string.
  • tobinary! โ€” returns the content of a memory block as a Tcl binary string.
  • tostring โ€” returns the content of a memory block as a Tcl string.
  • tostring! โ€” returns the content of a memory block as a Tcl string.
  • tounistring โ€” returns the content of a memory block containing a nul-terminated sequence of Tcl_UniChars as a Tcl string.
  • tounistring! โ€” returns the content of a memory block containing a nul-terminated sequence of Tcl_UniChars as a Tcl string.
  • towinstring โ€” returns the content of a memory block containing a nul-terminated sequence of winchars as a Tcl string.
  • towinstring! โ€” returns the content of a memory block containing a nul-terminated sequence of winchars as a Tcl string.

Refer to the documentation of each subcommand for details. ๐Ÿ’œ


โœจ memory allocate โœจ

Allocates memory of the specified size. Fresh block, who dis. ๐Ÿงš

memory allocate sizespec ?tag?

Parameters

  • sizespec โ€” requested size of memory block. This may be specified either as an integer value or a type specification.
  • tag โ€” tag for the returned pointer. Optional, default "".

Description

The returned memory must be eventually freed by calling memory free. Don't forget, or that's a leak, bestie. ๐Ÿ˜ญ

Return value

Returns a safe pointer to the allocated memory.

See also

memory new, memory free


โœจ memory fill โœจ

Fills memory with a specified value.

memory fill pointer bytevalue count ?offset?

Parameters

  • pointer โ€” safe pointer to memory.
  • bytevalue โ€” a value in the range 0-255.
  • count โ€” number of bytes to be fill.
  • offset โ€” offset from $pointer of area to fill. May be negative for unsafe pointers. Optional, default 0.

โœจ memory free โœจ

Frees the memory referenced by the passed pointer. The cleanup era. ๐Ÿงน

memory free pointer

Parameters

  • pointer โ€” safe pointer to memory to free.

Description

That memory must have been allocated using memory allocate, memory frombinary, memory fromstring, or one of the methods of a Struct object. Null pointers are silently ignored โ€” no drama, no error, just vibes. ๐Ÿฆ‹

See also

memory allocate


โœจ memory frombinary โœจ

Allocates memory and copied the passed Tcl binary string into it.

memory frombinary bin_value ?tag?

Parameters

  • bin_value โ€” a Tcl binary value.
  • tag โ€” tag for the returned pointer. Optional, default "".

Description

The returned memory must be eventually freed by calling memory free. ๐Ÿซถ

Return value

Returns a safe pointer to the allocated memory.

See also

memory tobinary, memory tobinary!


โœจ memory fromstring โœจ

Allocates memory and stores a Tcl string in it, using the encoding you specify.

memory fromstring value ?encoding?

Parameters

  • value โ€” Tcl string value.
  • encoding โ€” the encoding to use for conversion. If unspecified or the empty string, the system encoding is used. Optional, default "".

Description

The returned memory must be eventually freed by calling memory free. ๐ŸŒธ

Return value

Returns a safe pointer to the allocated memory.

See also

memory tostring, memory tostring!


โœจ memory fromunistring โœจ

Allocates memory and stores a Tcl string as a sequence of Tcl_UniChars.

memory fromunistring value

Parameters

  • value โ€” Tcl string value.

Description

The returned memory must be eventually freed by calling memory free. ๐ŸŽ€

Return value

Returns a safe pointer to the allocated memory.

See also

memory tounistring, memory tounistring!


โœจ memory fromwinstring โœจ

Allocates memory and stores a Tcl string as a sequence of winchars.

memory fromwinstring value

Parameters

  • value โ€” Tcl string value.

Description

The returned memory must be eventually freed by calling memory free. โœจ

Return value

Returns a safe pointer to the allocated memory.

See also

memory towinstring, memory towinstring!


โœจ memory get โœจ

Converts a native value sitting in memory into a Tcl script level value. Glow-up: native edition. ๐Ÿฆ‹

memory get pointer typespec ?index?

Parameters

  • pointer โ€” base address of memory location. The pointer must be a safe pointer, but the tag is immaterial.
  • typespec โ€” type specification to use for conversion.
  • index โ€” where in memory you're reading from, bestie. Care must be taken this is within bounds of the allocated space. Optional, default 0.

โœ๏ธ Description

This command converts the data at a memory location into a Tcl script object as per the type specification $typespec. The memory address of the data is given by $pointer if $index is unspecified or 0. Otherwise $index is treated as an index into an array based at $pointer whose elements are of the type defined by $typespec, and the memory address used is that of the slot given by $index.

Okay so the offset math, because this is the part where people get humbled ๐Ÿ˜ญ โ€” if $typespec is int and $index is 2, the memory address from which the value is read is at byte offset 8, assuming ints occupy 4 bytes. But โœจcarefulโœจ: if $typespec is int[3], then the size of the type specification is 12, and an index of 2 will correspond to a byte offset of 24, not 8. Be aware of these semantics when reading arrays using non-0 indices.

๐Ÿ‘€ See also

memory get!, memory set


๐Ÿซถ memory get! (::cffi)

Converts a native value in memory into a Tcl script level value

memory get! pointer typespec ?index?

Parameters

  • pointer โ€” base address of the memory location. The pointer is not checked for validity. ๐Ÿ’€
  • typespec โ€” the type specification to use for conversion.
  • index โ€” the index in memory from which the value is to be retrieved. Care must be taken this is within bounds of the allocated space. Optional, default 0.

โœ๏ธ Description

This command is literally identical to the memory get command except that it does not require $pointer to be a safe pointer. See the documentation of that command for the details, bestie ๐Ÿงš

๐Ÿ‘€ See also

memory get, memory set


๐ŸŒธ memory new (::cffi)

Allocates memory for a type and initializes it. It's giving "birth of an object" energy ๐ŸŽ€

memory new typespec initializer ?tag?

Parameters

  • typespec โ€” a type declaration.
  • initializer โ€” the type-specific value to use to initialize the allocated memory.
  • tag โ€” the optional tag for the returned pointer. Optional, default "".

โœ๏ธ Description

The $typespec argument may be any type specification. If an array is specified of a larger size than the number of elements in $initializer, the remaining elements are zeroed out. ๐ŸŒˆ

The returned memory must be eventually freed by calling memory free. Yes bestie, you have to clean up after yourself, no cap ๐Ÿซถ

๐Ÿ“ฆ Return value

Returns a safe pointer to the allocated memory. โœจ

๐Ÿ‘€ See also

memory allocate, memory free


๐Ÿ’œ memory set (::cffi)

Converts a value as per a type specification and stores it in memory in native form

memory set pointer typespec value ?index?

Parameters

  • pointer โ€” base address of the memory location. The pointer must be a safe pointer but the tag is immaterial.
  • typespec โ€” the type specification.
  • value โ€” the script level value to be stored.
  • index โ€” the index in memory at which the value is to be stored. Care must be taken this is within bounds of the allocated space. Optional, default 0.

โœ๏ธ Description

The command converts $value into the native form corresponding to the type specification $typespec. If $index is unspecified or 0, the native value is stored at the memory address given by $pointer. Otherwise $index is treated as an index into an array whose elements are of the type defined by $typespec, and the value is stored in the slot given by $index.

The math, again, because it do be like that ๐Ÿ˜ญ โ€” if $typespec is int and $index is 2, the memory address at which the value is written is at byte offset 8, assuming ints occupy 4 bytes. But if $typespec is int[3], then the size of the type specification is 12, and an index of 2 will correspond to a byte offset of 24, not 8. Be aware of these semantics when writing arrays to non-0 indices to avoid memory corruption. ๐Ÿ’€ No fr, that one's serious.

๐Ÿ‘€ See also

memory get, memory set!


๐Ÿฆ‹ memory set! (::cffi)

Converts a value as per a type specification and stores it in memory in native form

memory set! pointer typespec value ?index?

Parameters

  • pointer โ€” base address of the memory location. The pointer is not checked for validity.
  • typespec โ€” the type specification.
  • value โ€” the script level value to be stored.
  • index โ€” the index in memory at which the value is to be stored. Care must be taken this is within bounds of the allocated space. Optional, default 0.

โœ๏ธ Description

This command is identical to the memory set command except that it does not require $pointer to be a safe pointer. See the documentation of that command for details ๐Ÿงš

๐Ÿ‘€ See also

memory get, memory set


๐Ÿ“ memory tobinary (::cffi)

Returns the content of a memory block as a Tcl binary string.

memory tobinary pointer size ?offset?

Parameters

  • pointer โ€” safe pointer to memory.
  • size โ€” number of bytes to copy from the memory block.
  • offset โ€” offset from $pointer of the area to value. <italian>May be negative for unsafe pointers.</italian> Optional, default 0.

๐Ÿ“ฆ Return value

Returns the content of a memory block as a Tcl binary string. โœจ

๐Ÿ‘€ See also

memory tobinary!, memory frombinary


๐Ÿ”ฅ memory tobinary! (::cffi)

Returns the content of a memory block as a Tcl binary string.

memory tobinary! pointer size ?offset?

Parameters

  • pointer โ€” pointer to memory.
  • size โ€” number of bytes to copy from the memory block.
  • offset โ€” offset from $pointer of the area to value. May be negative for unsafe pointers. Optional, default 0.

โœ๏ธ Description

Unlike the memory tobinary method, this does not check the validity of $pointer and should be used with care. ๐Ÿ™ˆ You've been warned, bestie.

๐Ÿ“ฆ Return value

Returns the content of a memory block as a Tcl binary string. โœจ

๐Ÿ‘€ See also

memory tobinary, memory frombinary


๐ŸŽ€ memory tostring (::cffi)

Returns the content of a memory block as a Tcl string.

memory tostring pointer ?encoding? ?offset?

Parameters

  • pointer โ€” safe pointer to memory.
  • encoding โ€” the encoding to use for conversion. If unspecified or the empty string, the system encoding is used. Optional, default "".
  • offset โ€” offset from $pointer of the area to value. May be negative for unsafe pointers. Optional, default 0.

๐Ÿ“ฆ Return value

Returns the content of a memory block as a Tcl string. โœจ

๐Ÿ‘€ See also

memory tostring!, memory fromstring


๐Ÿงš memory tostring! (::cffi)

Returns the content of a memory block as a Tcl string.

memory tostring! pointer ?encoding? ?offset?

Parameters

  • pointer โ€” pointer to memory. Need not be a safe pointer.
  • encoding โ€” the encoding to use for conversion. If unspecified or the empty string, the system encoding is used. Optional, default "".
  • offset โ€” offset from $pointer of the area to value. May be negative. Optional, default 0.

โœ๏ธ Description

Unlike the memory tostring method, this does not check the validity of $pointer and should be used with care. ๐Ÿ™ˆ

๐Ÿ“ฆ Return value

Returns the content of a memory block as a Tcl string. โœจ

๐Ÿ‘€ See also

memory tostring!, memory fromstring


๐Ÿ’– memory tounistring (::cffi)

Returns the content of a memory block containing a nul-terminated sequence of Tcl_UniChars as a Tcl string. Unicode girlie era ๐Ÿฆ‹

memory tounistring pointer ?offset?

Parameters

  • pointer โ€” safe pointer to memory.
  • offset โ€” offset in Tcl_UniChar units from $pointer of the area to value. May be negative for unsafe pointers. Optional, default 0.

๐Ÿ“ฆ Return value

Returns the content of a memory block containing a nul-terminated sequence of Tcl_UniChars as a Tcl string. โœจ

๐Ÿ‘€ See also

memory tounistring!, memory fromunistring


โญ memory tounistring! (::cffi)

Returns the content of a memory block containing a nul-terminated sequence of Tcl_UniChars as a Tcl string.

memory tounistring! pointer ?offset?

Parameters

  • pointer โ€” pointer to memory. Need not be a safe pointer.
  • offset โ€” offset in Tcl_UniChar units from $pointer of the area to value. May be negative. Optional, default 0.

๐Ÿ“ฆ Return value

Returns the content of a memory block containing a nul-terminated sequence of Tcl_UniChars as a Tcl string. โœจ

๐Ÿ‘€ See also

memory tounistring, memory fromunistring


๐ŸชŸ memory towinstring (::cffi)

Returns the content of a memory block containing a nul-terminated sequence of winchars as a Tcl string.

memory towinstring pointer ?offset?

Parameters

  • pointer โ€” safe pointer to memory.
  • offset โ€” offset in WCHAR units from $pointer of the area to value. May be negative for unsafe pointers. Optional, default 0.

๐Ÿ“ฆ Return value

Returns the content of a memory block containing a nul-terminated sequence of winchars as a Tcl string. โœจ

๐Ÿ‘€ See also

memory towinstring!, memory fromwinstring


๐Ÿซง memory towinstring! (::cffi)

Returns the content of a memory block containing a nul-terminated sequence of winchars as a Tcl string.

memory towinstring! pointer ?offset?

Parameters

  • pointer โ€” pointer to memory. Need not be a safe pointer.
  • offset โ€” offset in WCHAR units from $pointer of the area to value. May be negative. Optional, default 0.

๐Ÿ“ฆ Return value

Returns the content of a memory block containing a nul-terminated sequence of winchars as a Tcl string. โœจ

๐Ÿ‘€ See also

memory towinstring!, memory fromwinstring


๐Ÿ‘‘ pkgconfig (::cffi)

A command ensemble. Like, a little command family reunion ๐ŸŽ€

pkgconfig subcommand ...

โœ๏ธ Description

The ensemble supports the following subcommands:

  • get โ€” gets the value of a configuration key.
  • list โ€” returns the list of keys containing information about the package configuration.

Refer to the documentation of each subcommand for details ๐Ÿซถ


๐Ÿ” pkgconfig get (::cffi)

Gets the value of a configuration key.

pkgconfig get key

Parameters

  • key โ€” one of the keys returned by the pkgconfig list command.

โœ๏ธ Description

The following keys are supported. Iconic lineup honestly โœจ

  • backend โ€” returns libffi or dyncall, indicating the backend FFI library in use.
  • version โ€” the package version.
  • compiler โ€” identifies the compiler used to build the extension.

๐Ÿ“‹ pkgconfig list (::cffi)

Returns the list of keys containing information about the package configuration.

pkgconfig list

๐Ÿ“ฆ Return value

Returns the list of keys containing information about the package configuration. โœจ


๐ŸŒˆ pointer (::cffi)

A command ensemble.

pointer subcommand ...

โœ๏ธ Description

okay so the ensemble supports these subcommands, bestie โ€” here's the whole lineup โœจ

  • address โ€” gives you back the address component of the pointer.
  • cast โ€” casts a pointer to a new tag.
  • castable โ€” says that pointers tagged $subtag are acceptable in declarations that require $supertag.
  • castables โ€” returns a list of tags that have been marked as castable with the pointer castable command..
  • check โ€” validates a pointer and raises an exception if it's invalid.
  • compare โ€” compares if two pointers are the same.
  • counted โ€” registers a pointer as a counted pointer.
  • dispose โ€” unregisters a safe or counted pointer.
  • info โ€” returns a dictionary containing registration information about a pointer.
  • invalidate โ€” unregisters a safe, counted or pinned pointer irrespective its reference count.
  • isnull โ€” returns true if the pointer is a NULL pointer, false otherwise.
  • isvalid โ€” validates a pointer.
  • list โ€” returns a list of registered pointers optionally filtered by a tag.
  • make โ€” return a pointer for a memory address.
  • pin โ€” pins a pointer as permanently safe.
  • safe โ€” registers a pointer as a safe uncounted pointer.
  • tag โ€” returns the pointer tag.
  • uncastable โ€” makes pointers with the specified tag uncastable to another type.

Refer to the documentation of each subcommand for details ๐Ÿ’–


pointer address (::cffi)

Returns the address component of the pointer.

pointer address pointer

Parameters

  • pointer โ€” Pointer whose address component is to be returned.

Return value

Returns the address component of the pointer. that's it, that's the whole vibe ๐ŸŽ€


pointer cast (::cffi)

Casts a pointer to a new tag.

pointer cast pointer ?TAG?

Parameters

  • pointer โ€” Pointer to be cast.
  • tag โ€” New tag to apply. This will be qualified with the current scope if not fully qualified.

Description

heads up bestie โ€” the cast will fail if the TAG is not castable to or from the pointer's tag. See Casting pointers. In addition, the cast will fail if the pointer is registered as a safe pointer and the pointer's tag is not castable to the tag in the registration.

If TAG is not specified, any existing tag is removed from the pointer (effectively marking it as a void* pointer). lowkey a glow-down but ok ๐Ÿซถ

Return value

Returns a pointer with the same address and new tag


pointer castable (::cffi)

Specifies that pointers with tag $subtag are acceptable in declarations that require $supertag.

pointer castable subtags supertag

Parameters

  • subtags โ€” List of tags which are acceptable wherever $supertag is expected. Will be qualified with current scope if necessary.
  • supertag โ€” Tag which should accept $subtag tagged pointers. Will be qualified with current scope if necessary.

Description

See Casting pointers for more information. iykyk ๐Ÿ’…


pointer castables (::cffi)

Returns a list of tags that have been marked as castable with the pointer castable command..

pointer castables

Return value

Returns a list of tags that have been marked as castable with the pointer castable command.. (yes, same sentence twice, she said what she said ๐Ÿ’€)


pointer check (::cffi)

Validates a pointer and raise an exception if invalid.

pointer check pointer

Parameters

  • pointer โ€” Pointer to be validated.

Description

for a pointer to be treated as valid, all three of these have to hit:

  • it must not be NULL
  • it must be registered
  • if it is tagged, the tag must be the same as that of the registration or implicitly castable to it.

If any of the above conditions is not met, an error exception is raised. Note that if $pointer is untagged, the tag of the registration is not checked.

See Pointers for more on pointer safety and registration. ๐ŸŒธ


pointer compare (::cffi)

Compares if two pointers are the same

pointer compare ptr1 ptr2

Parameters

  • ptr1 โ€” The first pointer to compare.
  • ptr2 โ€” The second pointer to compare.

Return value

Returns 1 if both address and tag components match, -1 if address matches but tags are different and 0 otherwise. three whole moods fr fr ๐Ÿ˜ญ


pointer counted (::cffi)

Registers a pointer as a counted pointer

pointer counted pointer

Parameters

  • pointer โ€” Pointer to be registered.

Description

In the case that the pointer is already registered, behavior depends on the existing registration:

  • If the pointer is already registered as a pinned pointer, the command has no effect.
  • If the pointer is already registered as a counted pointer, the command has no effect if the tag is the same as the registered tag or can be implicitly cast to it. Otherwise the registered tag is replaced.
  • If the pointer is registered as an uncounted pointer, the registration, including tag, is overwritten as a counted pointer with a reference count of 1.

In the case that the pointer is registered with a different tag, if the pointer tag cannot be implicitly cast to the registered tag, the registered tag is replaced by the pointer tag.

See Pointers for more on counted pointers and registration. ๐Ÿ”ฅ

Return value

Returns the registered pointer.


pointer dispose (::cffi)

Unregisters a safe or counted pointer

pointer dispose pointer

Parameters

  • pointer โ€” Pointer to be unregistered.

Description

Note that the command only unregisters the pointer. It does not do anything in terms of releases any resources associated with the pointer. like, it's uninviting them from the group chat, not deleting their whole existence, ok? ๐Ÿ’…

An error is raised if the pointer is not registered unless it is a null pointer in which case it is ignored without error.

See Pointers for more on pointer safety and registration.


pointer info (::cffi)

Returns a dictionary containing registration information about a pointer.

pointer info pointer

Parameters

  • pointer โ€” Pointer for which registration information is required.

Description

The returned dictionary always contains the keys Tag containing the pointer tag and Registration containing one of the values none, safe, pinned or counted. If the Registration value is not unregistered, the dictionary contains the additional keys RegisteredTag, holding the tag of the pointer in the registry, and Match which may have one of the values exact, derived or mismatch.

Return value

Returns a dictionary containing registration information about a pointer. ๐Ÿฆ‹


pointer invalidate (::cffi)

Unregisters a safe, counted or pinned pointer irrespective its reference count.

pointer invalidate pointer

Parameters

  • pointer โ€” Pointer to be unregistered.

Description

Note that the command only unregisters the pointer. It does not do anything in terms of releases any resources associated with the pointer.

The command differs from pointer dispose in that

  • it unregisters a counted pointer even if its reference count was greater than 1.
  • it unregisters pinned pointers
  • it does not raise an error for null pointers

See Pointers for more on pointer safety and registration. ๐Ÿ’œ


pointer isnull (::cffi)

Returns true if the pointer is a NULL pointer, false otherwise.

pointer isnull pointer

Parameters

  • pointer โ€” Pointer to be checked.

Return value

Returns true if the pointer is a NULL pointer, false otherwise. simple. iconic. no notes ๐ŸŽ€


pointer isvalid (::cffi)

Validates a pointer.

pointer isvalid pointer

Parameters

  • pointer โ€” Pointer to be validated.

Description

For a pointer to be treated as valid,

  • it must not be NULL
  • it must be registered
  • if it is tagged, the tag must be the same as that of the registration or implicitly castable to it.

Return a boolean true value if all the above conditions are met, otherwise false.

See Pointers for more on pointer safety and registration. โœจ


pointer list (::cffi)

Returns a list of registered pointers optionally filtered by a tag.

pointer list ?tag?

Parameters

  • tag โ€” If specified, only pointers matching the tag are returned. If tag is the empty string, only pointers without a tag are returned.

Return value

Returns a list of registered pointers optionally filtered by a tag. ๐ŸŒˆ


pointer make (::cffi)

Return a pointer for a memory address.

pointer make address ?tag?

Parameters

  • address โ€” Memory address as a positive integer.
  • tag โ€” If not fully qualified, this will be qualified with the current namespace name. An empty tag is treated as if it was unspecified.

Description

The returned pointer is not registered as safe. The caller can use the pointer safe command to mark it as such if so desired. ngl that's your job, not hers ๐Ÿซถ


pointer pin (::cffi)

Pins a pointer as permanently safe.

pointer pin pointer

Parameters

  • pointer โ€” Pointer to be pinned. This may or may not be already registered.

Description

Once a pointer is pinned, it is unaffected by any pointer safe, pointer counted or pointer dispose calls. It can however be invalidated by pointer invalidate.

A pinned pointer has no associated tag even if the passed pointer has one. It will thus match any pointer with the same address component irrespective of the tag. The primary use of pinned pointers is to deal with "pseudo handles" in the Windows API. ๐Ÿ’€

Return value

Returns $pointer itself.


pointer safe (::cffi)

Registers a pointer as a safe uncounted pointer.

pointer safe pointer

Parameters

  • pointer โ€” Pointer to be registered.

Description

In the case that the pointer is already registered, behavior depends on the existing registration:

  • If the pointer is already registered as a pinned pointer, the command has no effect.
  • If the pointer is already registered as a safe (uncounted) pointer the command has no effect if the tag is the same as the registered tag or can be implicitly cast to it. Otherwise the registered tag is replaced.
  • If the pointer is registered as a counted pointer, the registration, including tag, is overwritten.

See Pointers for more on pointer safety and registration. ๐ŸŒธ

Return value

Returns the registered pointer.


pointer tag (::cffi)

Returns the pointer tag

pointer tag pointer

โœจ Parameters โœจ

  • pointer โ€” the pointer whose tag you wanna get back, bestie.

๐Ÿ’– Description ๐Ÿ’–

If that pointer isn't tagged? You just get an empty string. No drama, no error, just "". ๐Ÿ’…

Peep Pointers for the full tea on pointer tags.

๐ŸŽ€ Return value ๐ŸŽ€

Returns the pointer tag. That's it, that's the whole vibe.


๐Ÿšซ pointer uncastable (::cffi)

Makes pointers rockin' a specific tag uncastable to any other type.

pointer uncastable tag

Parameters

  • tag โ€” a pointer tag. Any pointer tagged with $tag will no longer be castable to other tags that were set up with the pointer castables command. Locked in. ๐Ÿ”’

๐Ÿงฌ prototype (::cffi)

It's a command ensemble, babes.

prototype subcommand ...

Description

This ensemble comes with the following subcommands:

  • delete โ€” nukes prototypes matching a pattern.
  • function โ€” defines a function prototype for calling a function using the default C calling convention.
  • list โ€” hands back a list of prototypes matching the pattern you gave.
  • stdcall โ€” defines a function prototype for calling a function using the stdcall calling convention.

Go read each subcommand's own docs for the deets. ๐Ÿ“–


๐Ÿ—‘๏ธ prototype delete (::cffi)

Deletes prototypes matching a pattern. Bye bestie ๐Ÿ‘‹

prototype delete pattern

Parameters

  • pattern โ€” the pattern to match.

Description

The pattern matching algorithm is the exact same one Tcl's string match command uses. And no cap: it is not an error if the pattern doesn't match any prototypes. Zero matches? Zero problems. ๐Ÿซถ


๐ŸŽฏ prototype function (::cffi)

Defines a function prototype for calling a function using the default C calling convention.

prototype function name fntype parameters

Parameters

  • name โ€” the name for the prototype. It must begin with an alphabetic character, and it may contain alphanumerics and underscore.
  • fntype โ€” the type definition for the return value from the function.
  • parameters โ€” a list of alternating parameter name and type definitions.

Description

The $fntype and $parameters take the same form and have the same semantics as described for the ::cffi::Wrapper.function method for defining functions. But here's the plot twist ๐Ÿ‘€ โ€” unlike that method, this command does not create a command for invoking a C function. It only defines a prototype that you can then use together with a C function address to invoke that function. Prototype now, call later. โœจ

See Prototypes and function pointers for more details.

See also

::cffi::Wrapper.function


๐Ÿ“‹ prototype list (::cffi)

Returns a list of prototypes matching the specified pattern.

prototype list ?pattern?

Parameters

  • pattern โ€” the pattern to match. Optional, defaults to *.

Description

Same pattern matching algorithm as Tcl's string match command. Consistent queen. ๐Ÿ‘‘

Return value

Returns a list of prototypes matching the specified pattern.


๐ŸชŸ prototype stdcall (::cffi)

Defines a function prototype for calling a function using the stdcall calling convention.

prototype stdcall name fntype parameters

Parameters

  • name โ€” the name for the prototype. Must begin with an alphabetic character and may contain alphanumerics and underscore.
  • fntype โ€” the type definition for the return value from the function.
  • parameters โ€” a list of alternating parameter name and type definitions.

Description

The $fntype and $parameters take the same form and have the same semantics as described for the ::cffi::Wrapper.stdcall method for defining functions. But again โ€” unlike that method, this command does not create a command for invoking a C function. It just defines a prototype, which you then pair up with a C function address to invoke that function. ๐Ÿ’…

See Prototypes and function pointers for more details.

See also

::cffi::Wrapper.stdcall


๐Ÿ’พ savederrors (::cffi)

Returns the errno and GetLastError() values from the last CFFI call that was annotated with saveerrors.

savederrors

Description

For functions annotated with saveerrors, CFFI internally saves the errno and (on Windows) the GetLastError() values. This savederrors command retrieves them as a pair โ€” first element is the saved errno value, second is the GetLastError() result. Heads up: that second one is always 0 on non-Windows platforms. ๐ŸชŸโžก๏ธ๐Ÿšซ


๐Ÿ”ฎ type (::cffi)

Another command ensemble, because CFFI loves a good ensemble.

type subcommand ...

Description

The ensemble supports these subcommands:

  • count โ€” returns the count of elements in an array type.
  • frombinary โ€” converts the native binary value to its script level representation.
  • info โ€” returns a dictionary stuffed with various information about a type declaration.
  • size โ€” returns the size of a type in terms of the number of bytes of memory that type occupies.
  • tobinary โ€” converts a script level value to a native representation.

Check each subcommand's own docs for the details. ๐Ÿงš


๐Ÿ”ข type count (::cffi)

Returns the count of elements in an array type.

type count type

Parameters

  • type โ€” a type definition or alias.

Description

A return value of -1 means the type is not an array. So if you see -1, that's your sign, bestie. ๐Ÿ™ˆ

Return value

Returns the count of elements in an array type.


๐Ÿงช type frombinary (::cffi)

Converts the native binary value to its script level representation.

type frombinary typespec value

Parameters

  • typespec โ€” a type declaration.
  • value โ€” the native binary value.

Description

The $typespec argument may be any type specification. No restrictions, go off. ๐Ÿ”ฅ

Return value

Returns the script level representation of the value.

See also

type tobinary


๐Ÿ” type info (::cffi)

Returns a dictionary containing various information about a type declaration.

type info typedecl ?args?

Parameters

  • typedecl โ€” a type declaration.
  • -parsemode MODE โ€” one of param, return, field.
  • -vlacount VLACOUNT โ€” number of elements in variable size array.

Description

The type gets parsed as a parameter type declaration, a function return type declaration, or a structure field type declaration โ€” depends on the -parsemode option. If that's unspecified or an empty string, it's parsed in a generic fashion and no context-specific validation is done at all. Freestyle mode. ๐Ÿ’ƒ

The option -vlacount must be specified if the type is a variable length array, or a struct that contains a variable length array.

The returned dictionary has these keys:

  • Alignment โ€” the memory alignment needed for a value of that type.
  • BaseSize โ€” the number of bytes to store a single value of the type when the type is an array. For scalars, same as Size.
  • Count โ€” -1 for scalar values, otherwise it means the type is an array with that number of elements.
  • Size โ€” the number of bytes of memory needed to store a value of that type.
  • Definition โ€” the type declaration after applying any defaults. For type aliases, this is the resolved type definition.

Return value

Returns a dictionary containing various information about a type declaration.


๐Ÿ“ type size (::cffi)

Returns the size of a type in terms of the number of bytes of memory occupied by that type.

type size type ?args?

Parameters

  • type โ€” a type definition or alias.
  • -vlacount VLACOUNT โ€” number of elements in variable size array.

Description

For array types, the size includes the size of the entire array โ€” not just a single element. The whole thing, bestie. ๐Ÿซถ

The option -vlacount must be specified if the type is a variable length array or a struct that contains a variable length array.

Return value

Returns the size of a type in terms of the number of bytes of memory occupied by that type.


๐Ÿงฑ type tobinary (::cffi)

Converts a script level value to a native representation.

type tobinary typespec value

Parameters

  • typespec โ€” a type declaration.
  • value โ€” the script level value.

Description

The $typespec argument must not have a string or variable size component. And if an array is specified that's a larger size than the number of elements in $value, the remaining elements get zeroed out. Padding with zeros, iconic behaviour honestly. โœจ

Return value

Returns a Tcl binary containing the native representation.

See also

type frombinary


๐ŸŒˆ CLASSES ๐ŸŒˆ

๐Ÿ›๏ธ Interface (::cffi)

Method summary

  • constructor โ€” constructor for the class.
  • id โ€” returns the id for the interface as passed via the -id option in the interface definition.
  • methods โ€” creates Tcl commands wrapping the C functions comprising an interface.
  • stdmethods โ€” creates Tcl commands corresponding to the C functions comprising an interface.

๐Ÿงš constructor (::cffi::Interface)

Defines an interface consisting of method definitions.

Interface create OBJNAME ?args?
Interface new ?args?

Parameters

  • -id ID โ€” an id to be associated with the interface. This is for the caller's use and CFFI does not make any use of it. For COM, you can use this to associate the GUID or IID for the interface. Defaults to the empty string.
  • -inherit BASEINTERFACE โ€” if specified, the interface inherits methods from BASEINTERFACE. An empty value for BASEINTERFACE is treated as though the option was not specified at all.

Description

See Interfaces for more information. ๐Ÿ“š


๐Ÿ†” id (::cffi::Interface)

Returns the id for the interface as passed via the -id option in the interface definition.

INTERFACEOBJ id

Return value

Returns the id for the interface as passed via the -id option in the interface definition.


๐Ÿ› ๏ธ methods (::cffi::Interface)

Creates Tcl commands wrapping the C functions comprising an interface.

INTERFACEOBJ methods methodlist ?args?

Parameters

  • methodlist โ€” list of function definitions.
  • -disposemethod METHODNAMDE โ€” the name of the method, if any, whose implicit pointer parameter should be annotated with dispose.

Description

The C functions in the wrapper are presumed to be using the _cdecl calling convention. The created commands are of the form INTERFACENAME.METHODNAME. The first argument to each one is typed as pointer.INTERFACENAME. ๐Ÿ‘‘

The order of the methods in $methodlist must be the same as that in the corresponding C interface. And every function in the interface is expected to have a pointer to the interface as its first parameter. No skipping, no reordering, fr fr. ๐Ÿšจ

The $methodlist argument is a flat (not nested) list of function name, return type and parameter list โ€” same form as described for the ::cffi::Wrapper::function method, except the first parameter in the C function, the pointer to the object, should not be included. Like, don't double up on the pointer, bestie ๐Ÿซถ

See also

stdmethods


stdmethods (::cffi::Interface)

Makes Tcl commands for all the C functions that make up an interface. Basically a whole squad of commands, one per function โœจ

INTERFACEOBJ stdmethods methodlist ?args?

Parameters

  • methodlist โ€” list of function definitions.
  • -disposemethod METHODNAMDE โ€” the name of the method, if any, whose implicit pointer parameter should be annotated with dispose.

Description

These C functions are presumed to be using the _stdcall calling convention. The commands it creates look like INTERFACENAME.METHODNAME, and the first argument to each one is typed as pointer.INTERFACENAME.

Heads up: the order of the methods in $methodlist must be the same as that in the corresponding C interface. And all functions in the interface are expected to have a pointer to the interface as the first parameter โ€” no exceptions, it's giving rules ๐Ÿ“‹

The $methodlist argument is a flat (not nested) list of function name, return type and parameter list, in the same form as described for the ::cffi::Wrapper::function method, except that the first parameter in the C function โ€” the pointer to the object โ€” should not be included.

See also

methods


๐Ÿ‘‘ Struct (::cffi) ๐Ÿ‘‘

Method summary

  • constructor โ€” constructor for the class.
  • allocate โ€” allocates memory for one or more C structs.
  • describe โ€” returns a human-readable description of the C struct definition.
  • fieldpointer โ€” returns a pointer corresponding to the address of a field within a native structure.
  • free โ€” frees memory that was allocated for a native C struct.
  • frombinary โ€” decodes a Tcl binary string containing a native C struct into a Tcl dictionary.
  • fromnative โ€” decodes native C struct(s) in memory into a Tcl dictionary.
  • fromnative! โ€” decodes native C struct(s) in memory into a Tcl dictionary.
  • getnative โ€” returns the value of a field in a native structure in memory.
  • getnative! โ€” returns the value of a field in a native structure in memory.
  • getnativefields โ€” retrieve values of multiple fields from a native struct in memory.
  • getnativefields! โ€” retrieve values of multiple fields from a native struct in memory.
  • info โ€” returns a dictionary containing information about the struct layout.
  • name โ€” returns the name of the struct.
  • new โ€” allocates and initializes a native struct in memory.
  • setnative โ€” sets the value of a field in a native structure in memory.
  • setnative! โ€” sets the value of a field in a native structure in memory.
  • size โ€” returns the size of the struct.
  • tobinary โ€” encodes the Tcl representation of a C struct value into a Tcl binary string.
  • tonative โ€” writes the Tcl dictionary representation of a C struct value to memory in native form.
  • tonative! โ€” writes the Tcl dictionary representation of a C struct value to memory in native form.

๐ŸŒธ constructor (::cffi::Struct)

Builds a script-level object that maps to a C struct definition. Iconic behaviour, honestly ๐Ÿ’…

Struct create OBJNAME definition ?args?
Struct new definition ?args?

Parameters

  • definition โ€” defines the layout and type of the C struct fields.
  • -clear โ€” clears memory at initialization. See below ๐Ÿ‘‡
  • -pack PACKVALUE โ€” changes alignment and padding used for fields. See Structs.

Description

The object it makes can pass arguments to and from functions, allocate memory, encode and decode native C structs in memory, etc. A whole little multi-tool ๐Ÿงฐ

The $definition argument is a dictionary mapping field names to the corresponding types. See Packed structs for more info.

The name of the created struct is the same as the name of the returned object without the initial :: global namespace qualifier. You can grab that name with the name method, and it's what gets used to identify the struct when tagging pointers and for typing function parameters and nested struct fields.

If the -clear option is present, the memory of structures of this type is cleared before the field values are initialized. In that case, missing field values in a struct value will not raise an error, even if there's no default annotation on the field. It also effectively gives you a default zero value for all fields. Zeroes for days โœจ


๐ŸŒˆ allocate (::cffi::Struct)

Allocates memory for one or more C structs.

STRUCTOBJ allocate ?args?

Parameters

  • -count COUNT โ€” number of structs to allocate.
  • -vlacount VLACOUNT โ€” number of elements in variable size array.

Description

Unlike the new method, the allocated memory is not initialized. That's true even if the struct definition includes the -clear option. No hand-holding here ๐Ÿ˜Œ

You must specify the -vlacount option if the struct contains a field that is a variable length array (VLA), or a nested struct that contains a VLA. VLACOUNT is then the length of that array.

The allocated memory must be freed by calling the free method of the struct. Don't leave it hanging, bestie โ€” that's a leak ๐Ÿ˜ญ

Return value

Returns a safe pointer to the allocated memory, tagged with the struct name.


๐Ÿฆ‹ describe (::cffi::Struct)

Returns a human-readable description of the C struct definition.

STRUCTOBJ describe

Description

This is mainly for debugging and troubleshooting purposes. Note the returned info will not take into account the variable components of the struct, if any. So like, it's the vibe of the struct, not the whole truth ๐Ÿ™ˆ

Return value

Returns a human-readable description of the C struct definition.


๐ŸŽ€ fieldpointer (::cffi::Struct)

Returns a pointer corresponding to the address of a field within a native structure.

STRUCTOBJ fieldpointer pointer fieldname ?tag? ?index?

Parameters

  • pointer โ€” pointer to memory allocated for the C struct or array. Must be a safe pointer tagged with the struct name.
  • fieldname โ€” name of the field.
  • tag โ€” tag for the returned pointer. Optional, default "".
  • index โ€” if present, $pointer is interpreted as pointing to an array of structs and this is the index into that array. For variable sized structs index must be 0 or unspecified. Optional, default 0.

Description

Note: the returned pointer is not registered as a safe pointer. Lowkey important, ngl ๐Ÿ‘€

Return value

Returns a pointer corresponding to the address of a field within a native structure.


๐Ÿ’œ free (::cffi::Struct)

Frees memory that was allocated for a native C struct.

STRUCTOBJ free pointer

Parameters

  • pointer โ€” a pointer returned by allocate.

๐Ÿ“ frombinary (::cffi::Struct)

Decodes a Tcl binary string containing a native C struct into a Tcl dictionary.

STRUCTOBJ frombinary bin_value

Parameters

  • bin_value โ€” a Tcl binary value containing the C struct.

Return value

Returns the dictionary representation.


โญ fromnative (::cffi::Struct)

Decodes native C struct(s) in memory into a Tcl dictionary.

STRUCTOBJ fromnative pointer ?index?

Parameters

  • pointer โ€” safe pointer to the C struct or array of structs in memory.
  • index โ€” the index position at which the struct is to be written. Note this is interpreted as an index into an array of structs, not as a byte offset into memory. For variable sized structs index must be 0 or unspecified. Optional, default 0.

Description

The decoded dictionary (or dictionaries) are keyed by the field names of the struct. For fields containing variable length arrays, the field holding the length of the array must be explicitly specified and cannot be defaulted. No vibes-based guessing allowed ๐Ÿšซ

Return value

Returns a dictionary of the decoded struct.

See also

fromnative!, tonative, frombinary


๐Ÿ”ฅ fromnative! (::cffi::Struct)

Decodes native C struct(s) in memory into a Tcl dictionary.

STRUCTOBJ fromnative! pointer ?index?

Parameters

  • pointer โ€” safe or unsafe pointer to the C struct or array of structs in memory.
  • index โ€” the index position at which the struct is to be written. Note this is interpreted as an index into an array of structs, not as a byte offset into memory. For variable sized structs index must be 0 or unspecified. Optional, default 0.

Description

The decoded dictionary (or dictionaries) are keyed by the field names of the struct. For fields containing variable length arrays, the field holding the length of the array must be explicitly specified and cannot be defaulted.

Return value

Returns a dictionary of the decoded struct.

See also

fromnative, tonative, frombinary


๐Ÿ’– getnative (::cffi::Struct)

Returns the value of a field in a native structure in memory.

STRUCTOBJ getnative pointer fieldname ?index?

Parameters

  • pointer โ€” safe pointer to memory allocated for the C struct or array. Must be tagged with the struct name.
  • fieldname โ€” name of the field.
  • index โ€” if present, $pointer is interpreted as pointing to an array of structs and this is the index into that array. For variable sized structs index must be 0 or unspecified. Optional, default 0.

Description

In the case of fields of type pointer, the returned pointer is registered as a safe pointer โ€” unless the field was marked with the unsafe annotation. Safety first ๐Ÿ›ก๏ธ

Return value

Returns the value of a field in a native structure in memory.


๐Ÿงš getnative! (::cffi::Struct)

Returns the value of a field in a native structure in memory.

STRUCTOBJ getnative! pointer fieldname ?index?

Parameters

  • pointer โ€” safe or unsafe pointer to memory allocated for the C struct or array. Must be tagged with the struct name.
  • fieldname โ€” name of the field.
  • index โ€” if present, $pointer is interpreted as pointing to an array of structs and this is the index into that array. For variable sized structs index must be 0 or unspecified. Optional, default 0.

Description

In the case of fields of type pointer, the returned pointer is registered as a safe pointer โ€” unless the field was marked with the unsafe annotation.

๐ŸŒธ getnativefields (::cffi::Struct) ๐ŸŒธ

Bestie, this one's the bulk grab โ€” pull a whole handful of field values out of a native struct in memory all at once instead of doing them one by one. Iconic efficiency ๐Ÿ’…

STRUCTOBJ getnativefields pointer fieldnames ?index?

Parameters ๐ŸŽ€

  • pointer โ€” Pointer to memory allocated for the C struct or array. It must be tagged with the struct name, no cap.
  • fieldnames โ€” List of field names. Yep, a list. Give it a list.
  • index โ€” If present, $pointer is interpreted as pointing to an array of structs and this is the index into that array. For variable sized structs index must be 0 or unspecified. Optional, default 0.

Return value โœจ

Returns a list of field values in the same order as $fieldnames. Same order, always โ€” she's consistent ๐Ÿ’–


๐Ÿฆ‹ getnativefields! (::cffi::Struct) ๐Ÿฆ‹

Same group-chat energy as above but the unsafe version โ€” she does not check your pointer for you. Live dangerously, bestie ๐Ÿ˜ญ

STRUCTOBJ getnativefields! pointer fieldnames ?index?

Parameters ๐ŸŽ€

  • pointer โ€” Safe or unsafe pointer to memory allocated for the C struct. Must be tagged with the struct name.
  • fieldnames โ€” List of field names.
  • index โ€” If present, $pointer is interpreted as pointing to an array of structs and this is the index into that array. For variable sized structs index must be 0 or unspecified. Optional, default 0.

Return value โœจ

Returns a list of field values in the same order as $fieldnames.


๐Ÿ” info (::cffi::Struct) ๐Ÿ”

The gossip session about your struct's layout โ€” where every field actually sits in memory ๐Ÿ‘‘

STRUCTOBJ info ?args?

Parameters ๐ŸŽ€

  • -vlacount VLACOUNT โ€” Number of elements in variable size array.

Description ๐Ÿ’œ

The returned dictionary has the following fields:

  • Size โ€” Size of the struct.
  • Alignment โ€” Struct alignment.
  • Fields โ€” Dictionary of fields keyed by field name. The value is another nested dictionary with keys Size, Offset, and Definition containing the size, offset in struct, and type definition of the field.

The option -vlacount must be specified if the struct contains a field that is a variable length array (VLA) or a nested struct that contains a VLA. VLACOUNT is then length of that array.

Return value โœจ

Returns a dictionary containing information about the struct layout.


๐ŸŽ€ name (::cffi::Struct) ๐ŸŽ€

Just tells you the struct's name. Short and sweet, main character energy ๐Ÿซถ

STRUCTOBJ name

Description ๐Ÿ’œ

Note the name of the struct is different from the name of the object name. They're two different girlies, don't confuse them ๐Ÿ’…

Return value โœจ

Returns the name of the struct.


๐ŸŒˆ new (::cffi::Struct) ๐ŸŒˆ

Manifesting a brand new native struct in memory, fully allocated and initialized โœจ

STRUCTOBJ new ?initval?

Parameters ๐ŸŽ€

  • initval โ€” Initial value for the struct as a dictionary mapping field names to values. Optional, default "".

Description ๐Ÿ’œ

If no argument is supplied or fields are missing, defaults from the struct definition are used for initialization. An error is raised if any fields are not defaulted unless the -clear option was specified for the Struct. In that case missing fields without defaults are filled with zeroes.

For fields containing variable length arrays, the field holding the length of the array must be explicitly specified and cannot be defaulted.

โš ๏ธ The allocated memory must be freed by calling the free method for the struct. Don't ghost your malloc, bestie, that's a memory leak ๐Ÿ’€

Return value โœจ

Returns a safe pointer to the allocated memory tagged with the struct name.


๐Ÿ’œ setnative (::cffi::Struct) ๐Ÿ’œ

Write a single field value straight into a native struct in memory. One field. Very demure ๐ŸŽ€

STRUCTOBJ setnative pointer fieldname value ?index?

Parameters ๐ŸŽ€

  • pointer โ€” Safe pointer to memory allocated for the C struct or array. Must be tagged with the struct name.
  • fieldname โ€” Name of the field.
  • value โ€” Value to store in the field.
  • index โ€” If present, $pointer is interpreted as pointing to an array of structs and this is the index into that array. For variable sized structs index must be 0 or unspecified. Optional, default 0.

Description ๐Ÿ’œ

The field being set must not be a variable sized field, or field holding a count for a variable sized field; otherwise, an error is raised. She said what she said ๐Ÿšซ


๐Ÿ”ฅ setnative! (::cffi::Struct) ๐Ÿ”ฅ

The unsafe twin โ€” same set-a-field job, but with a safe or unsafe pointer. Chaos permitted ๐Ÿ™ˆ

STRUCTOBJ setnative! pointer fieldname value ?index?

Parameters ๐ŸŽ€

  • pointer โ€” Safe or unsafe pointer to memory allocated for the C struct or array. Must be tagged with the struct name.
  • fieldname โ€” Name of the field.
  • value โ€” Value to store in the field.
  • index โ€” If present, $pointer is interpreted as pointing to an array of structs and this is the index into that array. For variable sized structs index must be 0 or unspecified. Optional, default 0.

Description ๐Ÿ’œ

The field being set must not be a variable sized field, or field holding a count for a variable sized field; otherwise, an error is raised.


๐Ÿฆ‹ size (::cffi::Struct) ๐Ÿฆ‹

How big is she? Struct size, retrieved ๐ŸŒธ

STRUCTOBJ size ?args?

Parameters ๐ŸŽ€

  • -vlacount VLACOUNT โ€” Number of elements in variable size array.

Description ๐Ÿ’œ

The option -vlacount must be specified if the struct contains a field that is a variable length array (VLA) or a nested struct that contains a VLA. VLACOUNT is then length of that array.

Return value โœจ

Returns the size of the struct.


๐ŸŽ tobinary (::cffi::Struct) ๐ŸŽ

Takes your cute little Tcl dict of a struct value and squishes it into a raw Tcl binary string ๐Ÿงš

STRUCTOBJ tobinary dict_value

Parameters ๐ŸŽ€

  • dict_value โ€” A Tcl dictionary representation of a C struct value.

Return value โœจ

Returns the binary string containing the native C struct.


๐Ÿ’– tonative (::cffi::Struct) ๐Ÿ’–

Writes the Tcl dictionary representation of a C struct value to memory in native form. The write-to-memory glow-up โœจ

STRUCTOBJ tonative pointer initializer ?index?

Parameters ๐ŸŽ€

  • pointer โ€” Safe pointer to memory allocated for the C struct or array. Must be tagged with the struct name.
  • initializer โ€” The Tcl dictionary value.
  • index โ€” The index position at which the struct is to be written. Note this interpreted as an index into an array of structs, not as a byte offset into memory. Optional, default 0.

Description ๐Ÿ’œ

The method raises an error if the struct is variable size. Sorry babe, VLAs don't get this ๐Ÿ’€

See also ๐ŸŒˆ

tonative!, fromnative, tobinary


โญ tonative! (::cffi::Struct) โญ

Same as above but she's the unsafe one โ€” safe or unsafe pointer, your call, your responsibility ๐Ÿ˜Œ

STRUCTOBJ tonative! pointer initializer ?index?

Parameters ๐ŸŽ€

  • pointer โ€” Safe or unsafe pointer to memory allocated for the C struct or array. Must be tagged with the struct name.
  • initializer โ€” The Tcl dictionary value.
  • index โ€” The index position at which the struct is to be written. Note this interpreted as an index into an array of structs, not as a byte offset into memory. Optional, default 0.

Description ๐Ÿ’œ

The method raises an error if the struct is variable size.

See also ๐ŸŒˆ

tonative, fromnative, tobinary


๐Ÿ‘‘ Union (::cffi) ๐Ÿ‘‘

Method summary ๐Ÿ’…

  • constructor โ€” Constructor for the class.
  • decode โ€” Returns a field from a native union.
  • describe โ€” Returns a human-readable description of the C union definition.
  • encode โ€” Returns a union in native form with the specified field value.
  • info โ€” Returns a dictionary containing information about the info layout.
  • name โ€” Returns the name of the struct.
  • size โ€” Returns the size of the union.

๐Ÿงš constructor (::cffi::Union) ๐Ÿงš

Builds a script-level object that maps to a C union definition. Union era ๐Ÿ’

Union create OBJNAME definition ?args?
Union new definition ?args?

Parameters ๐ŸŽ€

  • definition โ€” Defines the layout and type of the C struct fields.
  • args โ€” Options. Currently the only option is -clear.

Description ๐Ÿ’œ

The created object can be used to manipulate native C unions.

The $definition argument is a dictionary mapping field names to the corresponding types. This has the same syntax as Structs.

The name of the created struct is the same as the name of the returned object without the initial :: global namespace qualifier. This name can be retrieved with the name method and is used to identify the struct when tagging pointers and for typing function parameters and nested struct fields.

If the -clear option is present, the memory of unions of this type is cleared before the field values are initialized.


๐ŸŒธ decode (::cffi::Union) ๐ŸŒธ

Pulls a field out of a native union. Reverse of encode, bestie ๐Ÿ’–

UNIONOBJ decode field uvalue

Parameters ๐ŸŽ€

  • field โ€” The field within the union that should be retrieved.
  • uvalue โ€” The opaque union in native form.

Return value โœจ

Returns a field from a native union.

See also ๐ŸŒˆ

encode


๐ŸŽ€ describe (::cffi::Union) ๐ŸŽ€

Gives you a human-readable description of the C union definition. She's explaining herself ๐Ÿ’…

UNIONOBJ describe

Description ๐Ÿ’œ

This is primarily for debugging and troubleshooting purposes.

Return value โœจ

Returns a human-readable description of the C union definition.


๐Ÿ”ฅ encode (::cffi::Union) ๐Ÿ”ฅ

Hands you back a union in native form with the field value you specified all set and slayed โœจ

UNIONOBJ encode field value

Parameters ๐ŸŽ€

  • field โ€” The field within the union that should be set.
  • value โ€” The value of the field.

Return value โœจ

Returns a union in native form with the specified field value.

See also ๐ŸŒˆ

decode


๐Ÿฆ‹ info (::cffi::Union) ๐Ÿฆ‹

Returns a dictionary containing information about the info layout. The union's whole vibe, documented ๐Ÿ“‹

UNIONOBJ info

Description ๐Ÿ’œ

The returned dictionary has the following fields:

  • Size โ€” Size of the struct.
  • Alignment โ€” Struct alignment.
  • Fields โ€” Dictionary of fields keyed by field name. The value is another nested dictionary with keys Size, Offset, and Definition containing the size, offset in struct, and type definition of the field.

Other fields may be present and should be ignored. Mind your business on those ones ๐Ÿ™ˆ

Return value โœจ

Returns a dictionary containing information about the info layout.


๐Ÿ’œ name (::cffi::Union) ๐Ÿ’œ

Returns the name of the struct. Yes, again. She's consistent ๐Ÿซถ

UNIONOBJ name

Description ๐Ÿ’œ

Note the name of the struct may be different from the name of the object command.

Return value โœจ

Returns the name of the struct.


๐ŸŒˆ size (::cffi::Union) ๐ŸŒˆ

Size of the union. That's it, that's the method ๐Ÿ’

UNIONOBJ size

Return value โœจ

Returns the size of the union.

๐Ÿฆ‹ Wrapper (::cffi) ๐Ÿฆ‹

okay bestie, this is the wrapper class itself โ€” the icon that wraps a shared library / DLL and loads it right into the process. ๐Ÿ’…

โœจ Method summary โœจ

  • constructor โ€” Constructor for the class.
  • destructor โ€” Destructor for the class.
  • addressof โ€” Returns the address of a symbol from the loaded library.
  • function โ€” Creates a Tcl command to invoke a C function in the loaded library.
  • functions โ€” Creates Tcl commands for multiple C functions within the loaded library.
  • path โ€” Returns the file system path for the wrapped library or image wrapped by the object.
  • stdcall โ€” Creates a Tcl command to invoke a C function that uses the __stdcall calling convention from the loaded library..
  • stdcalls โ€” Creates Tcl commands for multiple C functions within the loaded library that all use the __stdcall calling convention.

๐Ÿงธ constructor (::cffi::Wrapper) ๐Ÿงธ

Wraps a shared library / DLL, loading it in the process.

Wrapper create OBJNAME path
Wrapper new path

๐ŸŒธ Parameters

  • path โ€” Path to the shared library.

๐Ÿ’– Description

It is strongly recommended that the path to the shared library be specified as an absolute path. Bestie, do not play with this one. Otherwise, it is located in a system-specific manner involving operating system version, environment variables, registry settings (on Windows), phase of the moon etc.. This is not advisable for both reliability and security reasons.

When no longer needed, the object can be deleted in the usual manner (via rename to an empty string) or by invoking its destroy method.

โญ Return value

Returns the name of the created object.


๐Ÿ’€ destructor (::cffi::Wrapper) ๐Ÿ’€

Destroys the object and releases internal resources.

WRAPPEROBJ destroy

๐Ÿซถ Description

The managed library may be unloaded if there is nothing else holding a reference to it.


๐ŸŽ€ addressof (::cffi::Wrapper) ๐ŸŽ€

Returns the address of a symbol from the loaded library.

WRAPPEROBJ addressof symbol

๐ŸŒธ Parameters

  • symbol โ€” Name of the symbol.

๐Ÿ’– Description

The command will raise an error if the symbol is not found.

โญ Return value

Returns the address of a symbol from the loaded library.


๐Ÿ”ฅ function (::cffi::Wrapper) ๐Ÿ”ฅ

Creates a Tcl command to invoke a C function in the loaded library.

WRAPPEROBJ function fnname fntype parameters

๐ŸŒธ Parameters

  • fnname โ€” Name of the function and optionally, Tcl command.
  • fntype โ€” The type definition for the return value from the function.
  • parameters โ€” List of alternating parameter name and type definitions.

๐Ÿ’– Description

The command creates a Tcl command corresponding to a C function contained in the library. The function must be one that follows the default C calling convention (See Calling conventions).

The $fnname argument is a one or two element list, the first being the name of the C function and the second, if present, being the name of the corresponding Tcl command. The latter defaults to the former if unspecified. Unless fully qualified, the command is created in the namespace from which it is called.

The return type of the C function is specified through the $fntype argument which should be a type declaration. See syntax.

The $parameters argument is a list of alternating parameter names and type declarations that describe the parameters of the C function. The parameter name is only used to construct error messages while the latter determines how arguments are converted and passed to the C function. See syntax.

The return type as well as parameter type declarations may have annotations that control semantics and behavior with respect to how values are passed and converted between Tcl and C. See Functions for details of these.

The command will raise an error if the function identified by $cname is not found in the loaded DLL.

โญ Return value

Returns the name of the created Tcl command.


๐ŸŒˆ functions (::cffi::Wrapper) ๐ŸŒˆ

Creates Tcl commands for multiple C functions within the loaded library.

WRAPPEROBJ functions fnlist ?args?

๐ŸŒธ Parameters

  • fnlist โ€” List of function definitions.
  • -ignoremissing โ€” Do not raise an error if a function is not found.

๐Ÿ’– Description

This is a wrapper around the function method that provides some syntactic sugar for defining multiple functions. The $fnlist argument is a flat (not nested) list of function name, return type and parameter list in the same form as described for the function method.

If a function is not found, the command will raise an error but those functions that are found will be defined. The error can be completely suppressed with the -ignoremissing option.

If the function name element is #, the triple is ignored, effectively being considered a comment.


๐Ÿฆ‹ path (::cffi::Wrapper) ๐Ÿฆ‹

Returns the file system path for the wrapped library or image wrapped by the object.

WRAPPEROBJ path

๐Ÿ’– Description

The returned path may be or may not be normalized and may be in native form or Tcl's canonical form. If no path argument was provided to the constructor, an empty string may be returned on some platforms.

โญ Return value

Returns the file system path for the wrapped library or image wrapped by the object.


๐Ÿ’œ stdcall (::cffi::Wrapper) ๐Ÿ’œ

Creates a Tcl command to invoke a C function that uses the __stdcall calling convention from the loaded library..

WRAPPEROBJ stdcall fnname fntype parameters

๐ŸŒธ Parameters

  • fnname โ€” Name of the function and optionally, Tcl command.
  • fntype โ€” The type definition for the return value from the function.
  • parameters โ€” List of alternating parameter name and type definitions.

๐Ÿ’– Description

The command creates a Tcl command corresponding to a C function contained in the library. The function must be one that follows the __stdcall calling convention (See Calling conventions). The only platform where this differs from the C calling convention is 32-bit Windows. On other platforms, this method is a synonym for function.

See function for other details.

โญ Return value

Returns the name of the created Tcl command.


๐Ÿ“ stdcalls (::cffi::Wrapper) ๐Ÿ“

Creates Tcl commands for multiple C functions within the loaded library that all use the __stdcall calling convention.

WRAPPEROBJ stdcalls fnlist ?args?

๐ŸŒธ Parameters

  • fnlist โ€” List of function definitions.
  • -ignoremissing โ€” Do not raise an error if a function is not found.

๐Ÿ’– Description

This is a wrapper around the stdcall method that provides some syntactic sugar for defining multiple functions. The $fnlist argument is a flat (not nested) list of function name, return type and parameter list in the same form as described for the stdcall method.

If a function is not found, the command will raise an error but those functions that are found will be defined. The error can be completely suppressed with the -ignoremissing option.

If the function name element is #, the triple is ignored, effectively being considered a comment.


thatโ€™s the Wrapper class wrapped up, bestie ๐Ÿ’– signed off from cffi 2.0.3, the cffi(3tcl) source page, and its footer date doing its little timestamp thing ๐Ÿ’…โœจ

๐Ÿ“ฆ where this page comes from