{"id":7080,"date":"2022-12-20T19:35:12","date_gmt":"2022-12-20T22:35:12","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/tcl_objtype-man3-3\/"},"modified":"2022-12-20T19:35:12","modified_gmt":"2022-12-20T22:35:12","slug":"tcl_objtype-man3-3","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/tcl_objtype-man3-3\/","title":{"rendered":"Tcl_ObjType (man3)"},"content":{"rendered":"<h1 align=\"center\">Tcl_ObjType<\/h1>\n<p> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#SYNOPSIS\">SYNOPSIS<\/a><br \/> <a href=\"#ARGUMENTS\">ARGUMENTS<\/a><br \/> <a href=\"#DESCRIPTION\">DESCRIPTION<\/a><br \/> <a href=\"#THE TCL_OBJTYPE STRUCTURE\">THE TCL_OBJTYPE STRUCTURE<\/a><br \/> <a href=\"#SEE ALSO\">SEE ALSO<\/a><br \/> <a href=\"#KEYWORDS\">KEYWORDS<\/a> <\/p>\n<hr>\n<p>______________________________________________________________________________<\/p>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Tcl_RegisterObjType, Tcl_GetObjType, Tcl_AppendAllObjTypes, Tcl_ConvertToType \u2212 manipulate Tcl value types<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>#include <tcl.h><\/b><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>Tcl_RegisterObjType<\/b>(<i>typePtr<\/i>)<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">const Tcl_ObjType bodies manpages.csv script_extrae_body.sh script.sh usr <b><br \/> Tcl_GetObjType<\/b>(<i>typeName<\/i>)<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">int <b><br \/> Tcl_AppendAllObjTypes<\/b>(<i>interp, objPtr<\/i>)<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">int <b><br \/> Tcl_ConvertToType<\/b>(<i>interp, objPtr, typePtr<\/i>)<\/p>\n<h2>ARGUMENTS <a name=\"ARGUMENTS\"><\/a> <\/h2>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"47%\">\n<p style=\"margin-top: 1em\">const Tcl_ObjType <i>*typePtr<\/i> (in)<\/p>\n<\/td>\n<td width=\"7%\"><\/td>\n<td width=\"35%\">\n<p style=\"margin-top: 1em\">Points to the structure containing information about the Tcl value type. This storage must live forever, typically by being statically allocated.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"47%\">\n<p>const char <i>*typeName<\/i> (in)<\/p>\n<\/td>\n<td width=\"7%\"><\/td>\n<td width=\"35%\">\n<p>The name of a Tcl value type that <b>Tcl_GetObjType<\/b> should look up.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"47%\">\n<p>Tcl_Interp <i>*interp<\/i> (in)<\/p>\n<\/td>\n<td width=\"7%\"><\/td>\n<td width=\"35%\">\n<p>Interpreter to use for error reporting.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"47%\">\n<p>Tcl_Obj <i>*objPtr<\/i> (in)<\/p>\n<\/td>\n<td width=\"7%\"><\/td>\n<td width=\"35%\">\n<p>For <b>Tcl_AppendAllObjTypes<\/b>, this points to the value onto which it appends the name of each value type as a list element. For <b>Tcl_ConvertToType<\/b>, this points to a value that must have been the result of a previous call to <b>Tcl_NewObj<\/b>.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:65%;\">______________________________________________________________________________<\/p>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The procedures in this man page manage Tcl value types (sometimes referred to as object types or <b>Tcl_ObjType<\/b>s for historical reasons). They are used to register new value types, look up types, and force conversions from one type to another.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>Tcl_RegisterObjType<\/b> registers a new Tcl value type in the table of all value types that <b>Tcl_GetObjType<\/b> can look up by name. There are other value types supported by Tcl as well, which Tcl chooses not to register. Extensions can likewise choose to register the value types they create or not. The argument <i>typePtr<\/i> points to a Tcl_ObjType structure that describes the new type by giving its name and by supplying pointers to four procedures that implement the type. If the type table already contains a type with the same name as in <i>typePtr<\/i>, it is replaced with the new type. The Tcl_ObjType structure is described in the section <b>THE TCL_OBJTYPE STRUCTURE<\/b> below.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>Tcl_GetObjType<\/b> returns a pointer to the registered Tcl_ObjType with name <i>typeName<\/i>. It returns NULL if no type with that name is registered.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>Tcl_AppendAllObjTypes<\/b> appends the name of each registered value type as a list element onto the Tcl value referenced by <i>objPtr<\/i>. The return value is <b>TCL_OK<\/b> unless there was an error converting <i>objPtr<\/i> to a list value; in that case <b>TCL_ERROR<\/b> is returned.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>Tcl_ConvertToType<\/b> converts a value from one type to another if possible. It creates a new internal representation for <i>objPtr<\/i> appropriate for the target type <i>typePtr<\/i> and sets its <i>typePtr<\/i> member as determined by calling the <i>typePtr->setFromAnyProc<\/i> routine. Any internal representation for <i>objPtr<\/i>\u2019s old type is freed. If an error occurs during conversion, it returns <b>TCL_ERROR<\/b> and leaves an error message in the result value for <i>interp<\/i> unless <i>interp<\/i> is NULL. Otherwise, it returns <b>TCL_OK<\/b>. Passing a NULL <i>interp<\/i> allows this procedure to be used as a test whether the conversion can be done (and in fact was done). <big>\u2502<\/big><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">In many cases, the <i>typePtr->setFromAnyProc<\/i> routine will set <big>\u2502<\/big> <i>objPtr->typePtr<\/i> to the argument value <i>typePtr<\/i>, but that is no longer <big>\u2502<\/big> guaranteed. The <i>setFromAnyProc<\/i> is free to set the internal <big>\u2502<\/big> representation for <i>objPtr<\/i> to make use of another related Tcl_ObjType, <big>\u2502<\/big> if it sees fit.<\/p>\n<h2>THE TCL_OBJTYPE STRUCTURE <a name=\"THE TCL_OBJTYPE STRUCTURE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Extension writers can define new value types by defining four procedures and initializing a Tcl_ObjType structure to describe the type. Extension writers may also pass a pointer to their Tcl_ObjType structure to <b>Tcl_RegisterObjType<\/b> if they wish to permit other extensions to look up their Tcl_ObjType by name with the <b>Tcl_GetObjType<\/b> routine. The <b>Tcl_ObjType<\/b> structure is defined as follows:<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\">typedef struct Tcl_ObjType { <br \/> const char *<i>name<\/i>; <br \/> Tcl_FreeInternalRepProc *<i>freeIntRepProc<\/i>; <br \/> Tcl_DupInternalRepProc *<i>dupIntRepProc<\/i>; <br \/> Tcl_UpdateStringProc *<i>updateStringProc<\/i>; <br \/> Tcl_SetFromAnyProc *<i>setFromAnyProc<\/i>; <br \/> } <b>Tcl_ObjType<\/b>;<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>THE NAME FIELD<\/b> <br \/> The <i>name<\/i> member describes the name of the type, e.g. <b>int<\/b>. When a type is registered, this is the name used by callers of <b>Tcl_GetObjType<\/b> to lookup the type. For unregistered types, the <i>name<\/i> field is primarily of value for debugging. The remaining four members are pointers to procedures called by the generic Tcl value code:<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>THE SETFROMANYPROC FIELD<\/b> <br \/> The <i>setFromAnyProc<\/i> member contains the address of a function called to create a valid internal representation from a value\u2019s string representation.<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\">typedef int <b>Tcl_SetFromAnyProc<\/b>( <br \/> Tcl_Interp *<i>interp<\/i>, <br \/> Tcl_Obj *<i>objPtr<\/i>);<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">If an internal representation cannot be created from the string, it returns <b>TCL_ERROR<\/b> and puts a message describing the error in the result value for <i>interp<\/i> unless <i>interp<\/i> is NULL. If <i>setFromAnyProc<\/i> is successful, it stores the new internal representation, sets <i>objPtr<\/i>\u2019s <i>typePtr<\/i> member to point to the <b>Tcl_ObjType<\/b> struct corresponding to the new internal representation, and returns <b>TCL_OK<\/b>. Before setting the new internal representation, the <i>setFromAnyProc<\/i> must free any internal representation of <i>objPtr<\/i>\u2019s old type; it does this by calling the old type\u2019s <i>freeIntRepProc<\/i> if it is not NULL.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">As an example, the <i>setFromAnyProc<\/i> for the built-in Tcl list type gets an up-to-date string representation for <i>objPtr<\/i> by calling <b>Tcl_GetStringFromObj<\/b>. It parses the string to verify it is in a valid list format and to obtain each element value in the list, and, if this succeeds, stores the list elements in <i>objPtr<\/i>\u2019s internal representation and sets <i>objPtr<\/i>\u2019s <i>typePtr<\/i> member to point to the list type\u2019s Tcl_ObjType structure.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Do not release <i>objPtr<\/i>\u2019s old internal representation unless you replace it with a new one or reset the <i>typePtr<\/i> member to NULL.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>setFromAnyProc<\/i> member may be set to NULL, if the routines making use of the internal representation have no need to derive that internal representation from an arbitrary string value. However, in this case, passing a pointer to the type to <b>Tcl_ConvertToType<\/b> will lead to a panic, so to avoid this possibility, the type should <i>not<\/i> be registered.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>THE UPDATESTRINGPROC FIELD<\/b> <br \/> The <i>updateStringProc<\/i> member contains the address of a function called to create a valid string representation from a value\u2019s internal representation.<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\">typedef void <b>Tcl_UpdateStringProc<\/b>( <br \/> Tcl_Obj *<i>objPtr<\/i>);<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><i>objPtr<\/i>\u2019s <i>bytes<\/i> member is always NULL when it is called. It must always set <i>bytes<\/i> non-NULL before returning. We require the string representation\u2019s byte array to have a null after the last byte, at offset <i>length<\/i>, and to have no null bytes before that; this allows string representations to be treated as conventional null character-terminated C strings. These restrictions are easily met by using Tcl\u2019s internal UTF encoding for the string representation, same as one would do for other Tcl routines accepting string values as arguments. Storage for the byte array must be allocated in the heap by <b>Tcl_Alloc<\/b> or <b>ckalloc<\/b>. Note that <i>updateStringProc<\/i>s must allocate enough storage for the string\u2019s bytes and the terminating null byte.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>updateStringProc<\/i> for Tcl\u2019s built-in double type, for example, calls Tcl_PrintDouble to write to a buffer of size TCL_DOUBLE_SPACE, then allocates and copies the string representation to just enough space to hold it. A pointer to the allocated space is stored in the <i>bytes<\/i> member.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>updateStringProc<\/i> member may be set to NULL, if the routines making use of the internal representation are written so that the string representation is never invalidated. Failure to meet this obligation will lead to panics or crashes when <b>Tcl_GetStringFromObj<\/b> or other similar routines ask for the string representation.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>THE DUPINTREPPROC FIELD<\/b> <br \/> The <i>dupIntRepProc<\/i> member contains the address of a function called to copy an internal representation from one value to another.<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\">typedef void <b>Tcl_DupInternalRepProc<\/b>( <br \/> Tcl_Obj *<i>srcPtr<\/i>, <br \/> Tcl_Obj *<i>dupPtr<\/i>);<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><i>dupPtr<\/i>\u2019s internal representation is made a copy of <i>srcPtr<\/i>\u2019s internal representation. Before the call, <i>srcPtr<\/i>\u2019s internal representation is valid and <i>dupPtr<\/i>\u2019s is not. <i>srcPtr<\/i>\u2019s value type determines what copying its internal representation means.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">For example, the <i>dupIntRepProc<\/i> for the Tcl integer type simply copies an integer. The built-in list type\u2019s <i>dupIntRepProc<\/i> uses a far more sophisticated scheme to continue sharing storage as much as it reasonably can.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>THE FREEINTREPPROC FIELD<\/b> <br \/> The <i>freeIntRepProc<\/i> member contains the address of a function that is called when a value is freed.<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\">typedef void <b>Tcl_FreeInternalRepProc<\/b>( <br \/> Tcl_Obj *<i>objPtr<\/i>);<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>freeIntRepProc<\/i> function can deallocate the storage for the value\u2019s internal representation and do other type-specific processing necessary when a value is freed.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">For example, the list type\u2019s <i>freeIntRepProc<\/i> respects the storage sharing scheme established by the <i>dupIntRepProc<\/i> so that it only frees storage when the last value sharing it is being freed.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>freeIntRepProc<\/i> member can be set to NULL to indicate that the internal representation does not require freeing. The <i>freeIntRepProc<\/i> implementation must not access the <i>bytes<\/i> member of the value, since Tcl makes its own internal uses of that field during value deletion. The defined tasks for the <i>freeIntRepProc<\/i> have no need to consult the <i>bytes<\/i> member.<\/p>\n<h2>SEE ALSO <a name=\"SEE ALSO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Tcl_NewObj(3), Tcl_DecrRefCount(3), Tcl_IncrRefCount(3)<\/p>\n<h2>KEYWORDS <a name=\"KEYWORDS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">internal representation, value, value type, string representation, type conversion<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  Tcl_RegisterObjType, Tcl_GetObjType, Tcl_AppendAllObjTypes, Tcl_ConvertToType \u2212 manipulate Tcl value types <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2536],"tags":[2538,3007,3424],"class_list":["post-7080","post","type-post","status-publish","format-standard","hentry","category-3-llamadas-de-bibliotecas","tag-2538","tag-man3","tag-tcl_registerobjtype"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/7080","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=7080"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/7080\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=7080"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=7080"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=7080"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}