Compare commits
15
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
62077a6bd1 | ||
|
|
2f3087ea8f | ||
|
|
ba25919a60 | ||
|
|
c7ea989512 | ||
|
|
3c61afae67 | ||
|
|
0a5df8ec7f | ||
|
|
9a97fdffa8 | ||
|
|
ee898100a1 | ||
|
|
29f4c762f2 | ||
|
|
9dd0e90048 | ||
|
|
3b7f710d06 | ||
|
|
44c5cd1753 | ||
|
|
3f933695ab | ||
|
|
7b847a62f0 | ||
|
|
f3896e5187 |
+27
-11
@@ -8,7 +8,7 @@
|
||||
.so man.macros
|
||||
.BS
|
||||
.SH NAME
|
||||
Tcl_NewIntObj, Tcl_NewLongObj, Tcl_NewWideIntObj, Tcl_SetIntObj, Tcl_SetLongObj, Tcl_SetWideIntObj, Tcl_GetIntFromObj, Tcl_GetIntForIndex, Tcl_GetLongFromObj, Tcl_GetWideIntFromObj, Tcl_GetWideUIntFromObj, Tcl_NewBignumObj, Tcl_SetBignumObj, Tcl_GetBignumFromObj, Tcl_TakeBignumFromObj \- manipulate Tcl values as integers
|
||||
Tcl_NewIntObj, Tcl_NewLongObj, Tcl_NewWideIntObj, Tcl_NewWideUIntObj, Tcl_NewIndexObj, Tcl_SetIntObj, Tcl_SetLongObj, Tcl_SetWideIntObj, Tcl_SetWideUIntObj, Tcl_SetIndexObj, Tcl_GetIntFromObj, Tcl_GetIntForIndex, Tcl_GetLongFromObj, Tcl_GetWideIntFromObj, Tcl_GetWideUIntFromObj, Tcl_NewBignumObj, Tcl_SetBignumObj, Tcl_GetBignumFromObj, Tcl_TakeBignumFromObj \- manipulate Tcl values as integers
|
||||
.SH SYNOPSIS
|
||||
.nf
|
||||
\fB#include <tcl.h>\fR
|
||||
@@ -22,12 +22,22 @@ Tcl_Obj *
|
||||
Tcl_Obj *
|
||||
\fBTcl_NewWideIntObj\fR(\fIwideValue\fR)
|
||||
.sp
|
||||
Tcl_Obj *
|
||||
\fBTcl_NewWideUIntObj\fR(\fIuwideValue\fR)
|
||||
.sp
|
||||
Tcl_Obj *
|
||||
\fBTcl_NewIndexObj\fR(\fIindexValue\fR)
|
||||
.sp
|
||||
\fBTcl_SetIntObj\fR(\fIobjPtr, intValue\fR)
|
||||
.sp
|
||||
\fBTcl_SetLongObj\fR(\fIobjPtr, longValue\fR)
|
||||
.sp
|
||||
\fBTcl_SetWideIntObj\fR(\fIobjPtr, wideValue\fR)
|
||||
.sp
|
||||
\fBTcl_SetWideUIntObj\fR(\fIobjPtr, uwideValue\fR)
|
||||
.sp
|
||||
\fBTcl_SetIndexObj\fR(\fIobjPtr, indexValue\fR)
|
||||
.sp
|
||||
int
|
||||
\fBTcl_GetIntFromObj\fR(\fIinterp, objPtr, intPtr\fR)
|
||||
.sp
|
||||
@@ -69,8 +79,14 @@ Integer value used to initialize or set a Tcl value.
|
||||
Long integer value used to initialize or set a Tcl value.
|
||||
.AP Tcl_WideInt wideValue in
|
||||
Wide integer value used to initialize or set a Tcl value.
|
||||
.AP Tcl_WideUInt uwideValue in
|
||||
Unsigned wide integer value used to initialize or set a Tcl value.
|
||||
.AP Tcl_Size indexValue in
|
||||
\fTcl_Size\f value used to initialize or set a Tcl value.
|
||||
In Tcl 8.x, \fTcl_Size\f is actually the same as int.
|
||||
.AP Tcl_Obj *objPtr in/out
|
||||
For \fBTcl_SetIntObj\fR, \fBTcl_SetLongObj\fR, \fBTcl_SetWideIntObj\fR,
|
||||
\fBTcl_SetWideUIntObj\fR, \fBTcl_SetIndexObj\fR,
|
||||
and \fBTcl_SetBignumObj\fR, this points to the value in which to store an
|
||||
integral value. For \fBTcl_GetIntFromObj\fR, \fBTcl_GetLongFromObj\fR,
|
||||
\fBTcl_GetWideIntFromObj\fR, \fBTcl_GetBignumFromObj\fR, and
|
||||
@@ -112,18 +128,18 @@ The \fBmp_int\fR type is a multiple-precision integer type defined
|
||||
by the LibTomMath multiple-precision integer library.
|
||||
.PP
|
||||
The \fBTcl_NewIntObj\fR, \fBTcl_NewLongObj\fR, \fBTcl_NewWideIntObj\fR,
|
||||
and \fBTcl_NewBignumObj\fR routines each create and return a new
|
||||
Tcl value initialized to the integral value of the argument. The
|
||||
returned Tcl value is unshared.
|
||||
\fBTcl_NewWideUIntObj\fR, \fBTcl_NewIndexObj\fR, and \fBTcl_NewBignumObj\fR
|
||||
routines each create and return a new Tcl value initialized to the
|
||||
integral value of the argument. The returned Tcl value is unshared.
|
||||
.PP
|
||||
The \fBTcl_SetIntObj\fR, \fBTcl_SetLongObj\fR, \fBTcl_SetWideIntObj\fR,
|
||||
and \fBTcl_SetBignumObj\fR routines each set the value of an existing
|
||||
Tcl value pointed to by \fIobjPtr\fR to the integral value provided
|
||||
by the other argument. The \fIobjPtr\fR argument must point to an
|
||||
unshared Tcl value. Any attempt to set the value of a shared Tcl value
|
||||
violates Tcl's copy-on-write policy. Any existing string representation
|
||||
or internal representation in the unshared Tcl value will be freed
|
||||
as a consequence of setting the new value.
|
||||
\fBTcl_SetWideUIntObj\fR, \fBTcl_SetIndexObj\fR, and \fBTcl_SetBignumObj\fR
|
||||
routines each set the value of an existing Tcl value pointed to by \fIobjPtr\fR
|
||||
to the integral value provided by the other argument. The \fIobjPtr\fR
|
||||
argument must point to an unshared Tcl value. Any attempt to set the
|
||||
value of a shared Tcl value violates Tcl's copy-on-write policy. Any
|
||||
existing string representation or internal representation in the unshared
|
||||
Tcl value will be freed as a consequence of setting the new value.
|
||||
.PP
|
||||
The \fBTcl_GetIntForIndex\fR routine attempts to retrieve an index
|
||||
value from the Tcl value \fIobjPtr\fR. If the attempt succeeds,
|
||||
|
||||
+7
-7
@@ -2552,13 +2552,13 @@ declare 683 {
|
||||
int Tcl_GetEncodingNulLength(Tcl_Encoding encoding)
|
||||
}
|
||||
|
||||
# TIP #648 (reserved)
|
||||
#declare 684 {
|
||||
# Tcl_Obj *Tcl_NewWideUIntObj(Tcl_WideUInt wideValue)
|
||||
#}
|
||||
#declare 685 {
|
||||
# void Tcl_SetWideUIntObj(Tcl_Obj *objPtr, Tcl_WideUInt uwideValue)
|
||||
#}
|
||||
# TIP #648
|
||||
declare 684 {
|
||||
Tcl_Obj *Tcl_NewWideUIntObj(Tcl_WideUInt wideValue)
|
||||
}
|
||||
declare 685 {
|
||||
void Tcl_SetWideUIntObj(Tcl_Obj *objPtr, Tcl_WideUInt uwideValue)
|
||||
}
|
||||
|
||||
# TIP #650
|
||||
declare 686 {
|
||||
|
||||
+2
-2
@@ -1810,7 +1810,7 @@ ClockMillisecondsObjCmd(
|
||||
return TCL_ERROR;
|
||||
}
|
||||
Tcl_GetTime(&now);
|
||||
Tcl_SetObjResult(interp, Tcl_NewWideIntObj((Tcl_WideInt)
|
||||
Tcl_SetObjResult(interp, Tcl_NewWideUIntObj((Tcl_WideUInt)
|
||||
now.sec * 1000 + now.usec / 1000));
|
||||
return TCL_OK;
|
||||
}
|
||||
@@ -1998,7 +1998,7 @@ ClockSecondsObjCmd(
|
||||
return TCL_ERROR;
|
||||
}
|
||||
Tcl_GetTime(&now);
|
||||
Tcl_SetObjResult(interp, Tcl_NewWideIntObj((Tcl_WideInt) now.sec));
|
||||
Tcl_SetObjResult(interp, Tcl_NewWideUIntObj(now.sec));
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -3775,7 +3775,7 @@ TclNRSwitchObjCmd(
|
||||
TclNewIndexObj(rangeObjAry[0], info.matches[j].start);
|
||||
TclNewIndexObj(rangeObjAry[1], info.matches[j].end-1);
|
||||
} else {
|
||||
TclNewIndexObj(rangeObjAry[1], TCL_INDEX_NONE);
|
||||
TclNewIntObj(rangeObjAry[1], -1);
|
||||
rangeObjAry[0] = rangeObjAry[1];
|
||||
}
|
||||
|
||||
@@ -4099,7 +4099,7 @@ Tcl_TimeObjCmd(
|
||||
* Use int obj since we know time is not fractional. [Bug 1202178]
|
||||
*/
|
||||
|
||||
objs[0] = Tcl_NewWideIntObj((count <= 0) ? 0 : (Tcl_WideInt)totalMicroSec);
|
||||
objs[0] = Tcl_NewWideUIntObj((count <= 0) ? 0 : (Tcl_WideUInt)totalMicroSec);
|
||||
} else {
|
||||
objs[0] = Tcl_NewDoubleObj(totalMicroSec/count);
|
||||
}
|
||||
|
||||
+19
-6
@@ -2040,8 +2040,11 @@ EXTERN int Tcl_RemoveChannelMode(Tcl_Interp *interp,
|
||||
Tcl_Channel chan, int mode);
|
||||
/* 683 */
|
||||
EXTERN int Tcl_GetEncodingNulLength(Tcl_Encoding encoding);
|
||||
/* Slot 684 is reserved */
|
||||
/* Slot 685 is reserved */
|
||||
/* 684 */
|
||||
EXTERN Tcl_Obj * Tcl_NewWideUIntObj(Tcl_WideUInt wideValue);
|
||||
/* 685 */
|
||||
EXTERN void Tcl_SetWideUIntObj(Tcl_Obj *objPtr,
|
||||
Tcl_WideUInt uwideValue);
|
||||
/* 686 */
|
||||
EXTERN int Tcl_GetWideUIntFromObj(Tcl_Interp *interp,
|
||||
Tcl_Obj *objPtr, Tcl_WideUInt *uwidePtr);
|
||||
@@ -2766,8 +2769,8 @@ typedef struct TclStubs {
|
||||
int (*tcl_GetNumber) (Tcl_Interp *interp, const char *bytes, size_t numBytes, void **clientDataPtr, int *typePtr); /* 681 */
|
||||
int (*tcl_RemoveChannelMode) (Tcl_Interp *interp, Tcl_Channel chan, int mode); /* 682 */
|
||||
int (*tcl_GetEncodingNulLength) (Tcl_Encoding encoding); /* 683 */
|
||||
void (*reserved684)(void);
|
||||
void (*reserved685)(void);
|
||||
Tcl_Obj * (*tcl_NewWideUIntObj) (Tcl_WideUInt wideValue); /* 684 */
|
||||
void (*tcl_SetWideUIntObj) (Tcl_Obj *objPtr, Tcl_WideUInt uwideValue); /* 685 */
|
||||
int (*tcl_GetWideUIntFromObj) (Tcl_Interp *interp, Tcl_Obj *objPtr, Tcl_WideUInt *uwidePtr); /* 686 */
|
||||
Tcl_Obj * (*tcl_DStringToObj) (Tcl_DString *dsPtr); /* 687 */
|
||||
} TclStubs;
|
||||
@@ -4168,8 +4171,10 @@ extern const TclStubs *tclStubsPtr;
|
||||
(tclStubsPtr->tcl_RemoveChannelMode) /* 682 */
|
||||
#define Tcl_GetEncodingNulLength \
|
||||
(tclStubsPtr->tcl_GetEncodingNulLength) /* 683 */
|
||||
/* Slot 684 is reserved */
|
||||
/* Slot 685 is reserved */
|
||||
#define Tcl_NewWideUIntObj \
|
||||
(tclStubsPtr->tcl_NewWideUIntObj) /* 684 */
|
||||
#define Tcl_SetWideUIntObj \
|
||||
(tclStubsPtr->tcl_SetWideUIntObj) /* 685 */
|
||||
#define Tcl_GetWideUIntFromObj \
|
||||
(tclStubsPtr->tcl_GetWideUIntFromObj) /* 686 */
|
||||
#define Tcl_DStringToObj \
|
||||
@@ -4437,6 +4442,14 @@ extern const TclStubs *tclStubsPtr;
|
||||
#undef Tcl_StringMatch
|
||||
#define Tcl_StringMatch(str, pattern) Tcl_StringCaseMatch((str), (pattern), 0)
|
||||
|
||||
#if TCL_MAJOR_VERSION > 8
|
||||
# define Tcl_NewIndexObj(value) (((value) >= TCL_INDEX_NONE) ? Tcl_NewWideIntObj(-1) : Tcl_NewWideUIntObj(value))
|
||||
# define Tcl_SetIndexObj(objPtr, value) (((value) >= TCL_INDEX_NONE) ? Tcl_SetWideIntObj(objPtr, -1) : Tcl_SetWideUIntObj(objPtr, value))
|
||||
#else
|
||||
# define Tcl_NewIndexObj Tcl_NewIntObj
|
||||
# define Tcl_SetIndexObj Tcl_SetIntObj
|
||||
#endif
|
||||
|
||||
#if TCL_UTF_MAX < 4
|
||||
# undef Tcl_UniCharToUtfDString
|
||||
# define Tcl_UniCharToUtfDString Tcl_Char16ToUtfDString
|
||||
|
||||
@@ -701,7 +701,7 @@ declare 258 {
|
||||
|
||||
# TIP 625: for unit testing - create list objects with span
|
||||
declare 260 {
|
||||
Tcl_Obj *TclListTestObj(int length, int leadingSpace, int endSpace)
|
||||
Tcl_Obj *TclListTestObj(Tcl_Size length, Tcl_Size leadingSpace, Tcl_Size endSpace)
|
||||
}
|
||||
|
||||
# TIP 625: for unit testing - check list invariants
|
||||
|
||||
@@ -660,8 +660,8 @@ EXTERN Tcl_Obj * TclpCreateTemporaryDirectory(Tcl_Obj *dirObj,
|
||||
Tcl_Obj *basenameObj);
|
||||
/* Slot 259 is reserved */
|
||||
/* 260 */
|
||||
EXTERN Tcl_Obj * TclListTestObj(int length, int leadingSpace,
|
||||
int endSpace);
|
||||
EXTERN Tcl_Obj * TclListTestObj(Tcl_Size length,
|
||||
Tcl_Size leadingSpace, Tcl_Size endSpace);
|
||||
/* 261 */
|
||||
EXTERN void TclListObjValidate(Tcl_Interp *interp,
|
||||
Tcl_Obj *listObj);
|
||||
@@ -930,7 +930,7 @@ typedef struct TclIntStubs {
|
||||
void (*tclStaticLibrary) (Tcl_Interp *interp, const char *prefix, Tcl_LibraryInitProc *initProc, Tcl_LibraryInitProc *safeInitProc); /* 257 */
|
||||
Tcl_Obj * (*tclpCreateTemporaryDirectory) (Tcl_Obj *dirObj, Tcl_Obj *basenameObj); /* 258 */
|
||||
void (*reserved259)(void);
|
||||
Tcl_Obj * (*tclListTestObj) (int length, int leadingSpace, int endSpace); /* 260 */
|
||||
Tcl_Obj * (*tclListTestObj) (Tcl_Size length, Tcl_Size leadingSpace, Tcl_Size endSpace); /* 260 */
|
||||
void (*tclListObjValidate) (Tcl_Interp *interp, Tcl_Obj *listObj); /* 261 */
|
||||
} TclIntStubs;
|
||||
|
||||
|
||||
+3
-10
@@ -3514,15 +3514,8 @@ UpdateStringOfList(
|
||||
*------------------------------------------------------------------------
|
||||
*/
|
||||
Tcl_Obj *
|
||||
TclListTestObj (int length, int leadingSpace, int endSpace)
|
||||
TclListTestObj (Tcl_Size length, Tcl_Size leadingSpace, Tcl_Size endSpace)
|
||||
{
|
||||
if (length < 0)
|
||||
length = 0;
|
||||
if (leadingSpace < 0)
|
||||
leadingSpace = 0;
|
||||
if (endSpace < 0)
|
||||
endSpace = 0;
|
||||
|
||||
ListRep listRep;
|
||||
Tcl_Size capacity;
|
||||
Tcl_Obj *listObj;
|
||||
@@ -3538,9 +3531,9 @@ TclListTestObj (int length, int leadingSpace, int endSpace)
|
||||
ListRepInit(capacity, NULL, 0, &listRep);
|
||||
|
||||
ListStore *storePtr = listRep.storePtr;
|
||||
int i;
|
||||
Tcl_Size i;
|
||||
for (i = 0; i < length; ++i) {
|
||||
storePtr->slots[i + leadingSpace] = Tcl_NewIntObj(i);
|
||||
storePtr->slots[i + leadingSpace] = Tcl_NewIndexObj(i);
|
||||
Tcl_IncrRefCount(storePtr->slots[i + leadingSpace]);
|
||||
}
|
||||
storePtr->firstUsed = leadingSpace;
|
||||
|
||||
@@ -3216,6 +3216,33 @@ Tcl_NewWideIntObj(
|
||||
}
|
||||
#endif /* if TCL_MEM_DEBUG */
|
||||
|
||||
/*
|
||||
*----------------------------------------------------------------------
|
||||
*
|
||||
* Tcl_NewWideUIntObj --
|
||||
*
|
||||
* Results:
|
||||
* The newly created object is returned. This object will have an invalid
|
||||
* string representation. The returned object has ref count 0.
|
||||
*
|
||||
* Side effects:
|
||||
* None.
|
||||
*
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
Tcl_Obj *
|
||||
Tcl_NewWideUIntObj(
|
||||
Tcl_WideUInt uwideValue)
|
||||
/* Wide integer used to initialize the new
|
||||
* object. */
|
||||
{
|
||||
Tcl_Obj *objPtr;
|
||||
|
||||
TclNewUIntObj(objPtr, uwideValue);
|
||||
return objPtr;
|
||||
}
|
||||
|
||||
/*
|
||||
*----------------------------------------------------------------------
|
||||
*
|
||||
@@ -3312,6 +3339,46 @@ Tcl_SetWideIntObj(
|
||||
|
||||
TclSetIntObj(objPtr, wideValue);
|
||||
}
|
||||
|
||||
/*
|
||||
*----------------------------------------------------------------------
|
||||
*
|
||||
* Tcl_SetWideUIntObj --
|
||||
*
|
||||
* Modify an object to be a wide integer object or a bignum object
|
||||
* and to have the specified unsigned wide integer value.
|
||||
*
|
||||
* Results:
|
||||
* None.
|
||||
*
|
||||
* Side effects:
|
||||
* The object's old string rep, if any, is freed. Also, any old internal
|
||||
* rep is freed.
|
||||
*
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
void
|
||||
Tcl_SetWideUIntObj(
|
||||
Tcl_Obj *objPtr, /* Object w. internal rep to init. */
|
||||
Tcl_WideUInt uwideValue)
|
||||
/* Wide integer used to initialize the
|
||||
* object's value. */
|
||||
{
|
||||
if (Tcl_IsShared(objPtr)) {
|
||||
Tcl_Panic("%s called with shared object", "Tcl_SetWideUIntObj");
|
||||
}
|
||||
|
||||
if (uwideValue > WIDE_MAX) {
|
||||
mp_int bignumValue;
|
||||
if (mp_init_u64(&bignumValue, uwideValue) != MP_OKAY) {
|
||||
Tcl_Panic("%s: memory overflow", "Tcl_SetWideUIntObj");
|
||||
}
|
||||
TclSetBignumInternalRep(objPtr, &bignumValue);
|
||||
} {
|
||||
TclSetIntObj(objPtr, (Tcl_WideInt)uwideValue);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
*----------------------------------------------------------------------
|
||||
|
||||
+1
-1
@@ -1090,7 +1090,7 @@ Tcl_ScanObjCmd(
|
||||
if (code == TCL_OK) {
|
||||
if (underflow && (nconversions == 0)) {
|
||||
if (numVars) {
|
||||
TclNewIndexObj(objPtr, TCL_INDEX_NONE);
|
||||
TclNewIntObj(objPtr, -1);
|
||||
} else {
|
||||
if (objPtr) {
|
||||
Tcl_SetListObj(objPtr, 0, NULL);
|
||||
|
||||
@@ -2055,8 +2055,8 @@ const TclStubs tclStubs = {
|
||||
Tcl_GetNumber, /* 681 */
|
||||
Tcl_RemoveChannelMode, /* 682 */
|
||||
Tcl_GetEncodingNulLength, /* 683 */
|
||||
0, /* 684 */
|
||||
0, /* 685 */
|
||||
Tcl_NewWideUIntObj, /* 684 */
|
||||
Tcl_SetWideUIntObj, /* 685 */
|
||||
Tcl_GetWideUIntFromObj, /* 686 */
|
||||
Tcl_DStringToObj, /* 687 */
|
||||
};
|
||||
|
||||
+2
-2
@@ -3121,12 +3121,12 @@ TestlinkCmd(
|
||||
tmp = Tcl_NewWideIntObj(longVar);
|
||||
Tcl_AppendElement(interp, Tcl_GetString(tmp));
|
||||
Tcl_DecrRefCount(tmp);
|
||||
tmp = Tcl_NewWideIntObj((long)ulongVar);
|
||||
tmp = Tcl_NewWideUIntObj(ulongVar);
|
||||
Tcl_AppendElement(interp, Tcl_GetString(tmp));
|
||||
Tcl_DecrRefCount(tmp);
|
||||
Tcl_PrintDouble(NULL, (double)floatVar, buffer);
|
||||
Tcl_AppendElement(interp, buffer);
|
||||
tmp = Tcl_NewWideIntObj((Tcl_WideInt)uwideVar);
|
||||
tmp = Tcl_NewWideUIntObj(uwideVar);
|
||||
Tcl_AppendElement(interp, Tcl_GetString(tmp));
|
||||
Tcl_DecrRefCount(tmp);
|
||||
} else if (strcmp(argv[1], "set") == 0) {
|
||||
|
||||
+1
-1
@@ -71,7 +71,7 @@ test link-2.1 {writing C variables from Tcl} -constraints {testlink} -setup {
|
||||
set float 1.0987654321
|
||||
set uwide 12345678901234567890
|
||||
concat [testlink get] | $int $real $bool $string $wide $char $uchar $short $ushort $uint $long $ulong $float $uwide
|
||||
} -result {465 -10.5 1 abcdef 135135 79 161 8000 40000 -1073628482 34543 567890 1.0987653732299805 -6101065172474983726 | 0o0721 -10.5 true abcdef 135135 79 161 8000 40000 0xc001babe 34543 567890 1.0987654321 12345678901234567890}
|
||||
} -result {465 -10.5 1 abcdef 135135 79 161 8000 40000 -1073628482 34543 567890 1.0987653732299805 12345678901234567890 | 0o0721 -10.5 true abcdef 135135 79 161 8000 40000 0xc001babe 34543 567890 1.0987654321 12345678901234567890}
|
||||
test link-2.2 {writing bad values into variables} -setup {
|
||||
testlink delete
|
||||
} -constraints {testlink} -body {
|
||||
|
||||
Reference in New Issue
Block a user