Tcl Source Code

Check-in [a74d98295f]
Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to [email protected]
or submit via the online form by Sep 9.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:
* generic/tclCmdAH.c: Added support for the "ll" width * generic/tclStringObj.c: specifier to [format].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | kennykb-numerics-branch
Files: files | file ages | folders
SHA1: a74d98295fef3b369d08c016eddc2832084bfd3a
User & Date: dgp 2005-09-12 19:12:27
Context
2005-09-12
19:39
uninitialized vars are bad, mm'kay? check-in: 948d18b8f7 user: dgp tags: kennykb-numerics-branch
19:12
* generic/tclCmdAH.c: Added support for the "ll" width * generic/tclString...
check-in: a74d98295f user: dgp tags: kennykb-numerics-branch
14:47
[kennykb-numerics-branch] Merge updates from HEAD.
check-in: 0b3ca397c7 user: dgp tags: kennykb-numerics-branch
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to ChangeLog.

1
2
3



4
5
6
7
8
9
10
2005-09-12  Don Porter  <[email protected]>

	[kennykb-numerics-branch]	Merge updates from HEAD.




	* generic/tclStringObj.c (TclAppendFormattedObjs):	Bug fix:
	make sure %ld formats force the collection of a wide value, when
	the value could be a different long.

2005-09-09  Andreas Kupries <[email protected]>



>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
2005-09-12  Don Porter  <[email protected]>

	[kennykb-numerics-branch]	Merge updates from HEAD.

	* generic/tclCmdAH.c:		Added support for the "ll" width	
	* generic/tclStringObj.c:	specifier to [format].

	* generic/tclStringObj.c (TclAppendFormattedObjs):	Bug fix:
	make sure %ld formats force the collection of a wide value, when
	the value could be a different long.

2005-09-09  Andreas Kupries <[email protected]>

Changes to generic/tclCmdAH.c.

6
7
8
9
10
11
12
13
14
15
16
17


18
19
20
21
22
23
24
 *
 * Copyright (c) 1987-1993 The Regents of the University of California.
 * Copyright (c) 1994-1997 Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * RCS: @(#) $Id: tclCmdAH.c,v 1.57.2.8 2005/09/09 18:48:40 dgp Exp $
 */

#include "tclInt.h"
#include <locale.h>



/*
 * Prototypes for local procedures defined in this file:
 */

static int		CheckAccess(Tcl_Interp *interp, Tcl_Obj *pathPtr,
			    int mode);






|




>
>







6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
 *
 * Copyright (c) 1987-1993 The Regents of the University of California.
 * Copyright (c) 1994-1997 Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * RCS: @(#) $Id: tclCmdAH.c,v 1.57.2.9 2005/09/12 19:12:27 dgp Exp $
 */

#include "tclInt.h"
#include <locale.h>

#define NEW_FORMAT 1

/*
 * Prototypes for local procedures defined in this file:
 */

static int		CheckAccess(Tcl_Interp *interp, Tcl_Obj *pathPtr,
			    int mode);

Changes to generic/tclStringObj.c.

29
30
31
32
33
34
35
36
37
38

39
40
41
42
43
44
45
....
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
....
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874







1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
....
1910
1911
1912
1913
1914
1915
1916




1917
1918
1919
1920
1921
1922
1923

1924
1925





1926
1927


1928
1929







1930
1931


1932
1933






1934
1935





1936

1937
1938
1939
1940
1941
1942
1943

1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
....
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
....
2022
2023
2024
2025
2026
2027
2028
2029

2030
2031
2032
2033
2034
2035
2036
2037

2038
2039
2040
2041
2042
2043
2044
....
2045
2046
2047
2048
2049
2050
2051








2052
2053
2054
2055
2056
2057
2058
....
2063
2064
2065
2066
2067
2068
2069








2070
2071
2072
2073
2074
2075
2076
2077
 *
 * Copyright (c) 1995-1997 Sun Microsystems, Inc.
 * Copyright (c) 1999 by Scriptics Corporation.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * RCS: @(#) $Id: tclStringObj.c,v 1.35.2.6 2005/09/12 14:47:16 dgp Exp $ */

#include "tclInt.h"


/*
 * Prototypes for functions defined later in this file:
 */

static void		AppendUnicodeToUnicodeRep _ANSI_ARGS_((
			    Tcl_Obj *objPtr, CONST Tcl_UniChar *unicode,
................................................................................
    }

    Tcl_IncrRefCount(appendObj);
    /* format string is NUL-terminated */
    while (*format != '\0') {
	char *end;
	int gotMinus, gotHash, gotZero, gotSpace, gotPlus, sawFlag;
	int width, gotPrecision, precision, useShort, useWide;
	int newXpg, numChars, allocSegment = 0;
	Tcl_Obj *segment;
	Tcl_UniChar ch;
	int step = Tcl_UtfToUniChar(format, &ch);

	format += step;
	if (ch != '%') {
................................................................................
	    objIndex++;
	    format += step;
	    step = Tcl_UtfToUniChar(format, &ch);
	}

	/* 5. Length modifier */

	useShort = useWide = 0;
	if (ch == 'h') {
	    useShort = 1;
	    format += step;
	    step = Tcl_UtfToUniChar(format, &ch);
	} else if (ch == 'l') {







#ifndef TCL_WIDE_INT_IS_LONG
	    useWide = 1;
#endif
	    format += step;
	    step = Tcl_UtfToUniChar(format, &ch);
	}

	format += step;
	span = format;

	/* 6. Conversion character */
	segment = objv[objIndex];
................................................................................
	    segment = Tcl_NewStringObj(buf, length);
	    Tcl_IncrRefCount(segment);
	    allocSegment = 1;
	    break;
	}
	
	case 'u':




	case 'd':
	case 'o':
	case 'x':
	case 'X': {
	    short int s;
	    long l;
	    Tcl_WideInt w;

	    int isNegative = 0;






	    if (useWide) {
		if (Tcl_GetWideIntFromObj(interp, segment, &w) != TCL_OK) {


		    goto error;
		}







	    } else if (Tcl_GetLongFromObj(NULL, segment, &l) != TCL_OK) {
		if (Tcl_GetWideIntFromObj(interp, segment, &w) != TCL_OK) {


		    goto error;
		}






		l = Tcl_WideAsLong(w);
	    }







	    if (useShort) {
		s = (short int) l;
		isNegative = (s < (short int)0);
	    } else if (useWide) {
		isNegative = (w < (Tcl_WideInt)0);
	    } else {
		isNegative = (l < (long)0);

	    }

	    segment = Tcl_NewObj();
	    allocSegment = 1;
	    Tcl_IncrRefCount(segment);

	    if (isNegative || gotPlus) {
		if (ch == 'd') {
		    if (isNegative) {
			Tcl_AppendToObj(segment, "-", 1);
		    } else {
			Tcl_AppendToObj(segment, "+", 1);
		    }
		}
	    }
................................................................................

	    switch (ch) {
	    case 'd': {
		int length;
		Tcl_Obj *pure;
		CONST char *bytes;

		if (isNegative) {
		    if (useShort) {
			pure = Tcl_NewIntObj((int)(-s));
		    } else if (useWide) {
			pure = Tcl_NewWideIntObj(-w);
		    } else {
			pure = Tcl_NewLongObj(-l);
		    }
		} else {
		    if (useShort) {
			pure = Tcl_NewIntObj((int)(s));
		    } else if (useWide) {
			pure = Tcl_NewWideIntObj(w);
		    } else {
			pure = Tcl_NewLongObj(l);
		    }
		}
		Tcl_IncrRefCount(pure);
		bytes = Tcl_GetStringFromObj(pure, &length);
		/* Handle things like -INT_MIN == INT_MIN */
		if (*bytes == '-') {
		    length--; bytes++;
		}
		/* Canonical decimal string reps for integers are composed
		 * entirely of one-byte encoded characters, so "length" is
		 * the number of chars */
		if (gotPrecision) {
................................................................................
	    }
		
	    case 'u':
	    case 'o':
	    case 'x':
	    case 'X': {
		Tcl_WideUInt bits;
		int length, numDigits = 0, base = 16;

		Tcl_Obj *pure;
		char *bytes;

		if (ch == 'u') {
		    base = 10;
		}
		if (ch == 'o') {
		    base = 8;

		}
		if (useShort) {
		    unsigned short int us = (unsigned short int) s;
		    bits = (Tcl_WideUInt) us;
		    while (us) {
			numDigits++;
			us /= base;
................................................................................
		    }
		} else if (useWide) {
		    Tcl_WideUInt uw = (Tcl_WideUInt) w;
		    bits = uw;
		    while (uw) {
			numDigits++;
			uw /= base;








		    }
		} else {
		    unsigned long int ul = (unsigned long int) l;
		    bits = (Tcl_WideUInt) ul;
		    while (ul) {
			numDigits++;
			ul /= base;
................................................................................
		    numDigits = 1;
		}
		pure = Tcl_NewObj();
		Tcl_SetObjLength(pure, numDigits);
		bytes = Tcl_GetString(pure);
		length = numDigits;
		while (numDigits--) {








		    int digitOffset = (int) (bits % base);
		    if (digitOffset > 9) {
			bytes[numDigits] = 'a' + digitOffset - 10;
		    } else {
			bytes[numDigits] = '0' + digitOffset;
		    }
		    bits /= base;
		}






|


>







 







|







 







|





>
>
>
>
>
>
>



|
<







 







>
>
>
>







>


>
>
>
>
>
|
|
>
>
|
|
>
>
>
>
>
>
>

|
>
>
|
|
>
>
>
>
>
>
|
|
>
>
>
>
>
|
>
|
|
|
<
<
|
|
>







|







 







<
|
|
|
|
<
<
<
<
<
<
|
|
|
|
<



|







 







|
>








>







 







>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>
|







29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
....
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
....
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886

1887
1888
1889
1890
1891
1892
1893
....
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979


1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
....
2011
2012
2013
2014
2015
2016
2017

2018
2019
2020
2021






2022
2023
2024
2025

2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
....
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
....
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
....
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
 *
 * Copyright (c) 1995-1997 Sun Microsystems, Inc.
 * Copyright (c) 1999 by Scriptics Corporation.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * RCS: @(#) $Id: tclStringObj.c,v 1.35.2.7 2005/09/12 19:12:27 dgp Exp $ */

#include "tclInt.h"
#include "tommath.h"

/*
 * Prototypes for functions defined later in this file:
 */

static void		AppendUnicodeToUnicodeRep _ANSI_ARGS_((
			    Tcl_Obj *objPtr, CONST Tcl_UniChar *unicode,
................................................................................
    }

    Tcl_IncrRefCount(appendObj);
    /* format string is NUL-terminated */
    while (*format != '\0') {
	char *end;
	int gotMinus, gotHash, gotZero, gotSpace, gotPlus, sawFlag;
	int width, gotPrecision, precision, useShort, useWide, useBig;
	int newXpg, numChars, allocSegment = 0;
	Tcl_Obj *segment;
	Tcl_UniChar ch;
	int step = Tcl_UtfToUniChar(format, &ch);

	format += step;
	if (ch != '%') {
................................................................................
	    objIndex++;
	    format += step;
	    step = Tcl_UtfToUniChar(format, &ch);
	}

	/* 5. Length modifier */

	useShort = useWide = useBig = 0;
	if (ch == 'h') {
	    useShort = 1;
	    format += step;
	    step = Tcl_UtfToUniChar(format, &ch);
	} else if (ch == 'l') {
	    format += step;
	    step = Tcl_UtfToUniChar(format, &ch);
	    if (ch == 'l') {
		useBig = 1;
		format += step;
		step = Tcl_UtfToUniChar(format, &ch);
	    } else {
#ifndef TCL_WIDE_INT_IS_LONG
	    useWide = 1;
#endif
	    }

	}

	format += step;
	span = format;

	/* 6. Conversion character */
	segment = objv[objIndex];
................................................................................
	    segment = Tcl_NewStringObj(buf, length);
	    Tcl_IncrRefCount(segment);
	    allocSegment = 1;
	    break;
	}
	
	case 'u':
	    if (useBig) {
		msg = "unsigned bignum format is invalid";
		goto errorMsg;
	    }
	case 'd':
	case 'o':
	case 'x':
	case 'X': {
	    short int s;
	    long l;
	    Tcl_WideInt w;
	    mp_int big;
	    int isNegative = 0;

	    if (useBig) {
		if (Tcl_GetBignumFromObj(interp, segment, &big) != TCL_OK) {
		    goto error;
		}
		isNegative = (big.sign == MP_NEG);
	    } else if (useWide) {
		if (Tcl_GetWideIntFromObj(NULL, segment, &w) != TCL_OK) {
		    Tcl_Obj *objPtr;
		    if (Tcl_GetBignumFromObj(interp, segment, &big) != TCL_OK) {
			goto error;
		    }
		    mp_mod_2d(&big, (int) CHAR_BIT * sizeof(Tcl_WideInt), &big);
		    objPtr = Tcl_NewBignumObj(&big);
		    Tcl_IncrRefCount(objPtr);
		    Tcl_GetWideIntFromObj(NULL, objPtr, &w);
		    Tcl_DecrRefCount(objPtr);
		}
		isNegative = (w < (Tcl_WideInt)0);
	    } else if (Tcl_GetLongFromObj(NULL, segment, &l) != TCL_OK) {
		if (Tcl_GetWideIntFromObj(NULL, segment, &w) != TCL_OK) {
		    Tcl_Obj *objPtr;
		    if (Tcl_GetBignumFromObj(interp, segment, &big) != TCL_OK) {
			goto error;
		    }
		    mp_mod_2d(&big, (int) CHAR_BIT * sizeof(long), &big);
		    objPtr = Tcl_NewBignumObj(&big);
		    Tcl_IncrRefCount(objPtr);
		    Tcl_GetLongFromObj(NULL, objPtr, &l);
		    Tcl_DecrRefCount(objPtr);
		} else {
		    l = Tcl_WideAsLong(w);
		}
		if (useShort) {
		    s = (short int) l;
		    isNegative = (s < (short int)0);
		} else {
		    isNegative = (l < (long)0);
		}
	    } else {
		if (useShort) {
		    s = (short int) l;
		    isNegative = (s < (short int)0);


		} else {
		    isNegative = (l < (long)0);
		}
	    }

	    segment = Tcl_NewObj();
	    allocSegment = 1;
	    Tcl_IncrRefCount(segment);

	    if (isNegative || gotPlus) {
		if (useBig || (ch == 'd')) {
		    if (isNegative) {
			Tcl_AppendToObj(segment, "-", 1);
		    } else {
			Tcl_AppendToObj(segment, "+", 1);
		    }
		}
	    }
................................................................................

	    switch (ch) {
	    case 'd': {
		int length;
		Tcl_Obj *pure;
		CONST char *bytes;


		if (useShort) {
		    pure = Tcl_NewIntObj((int)(s));
		} else if (useWide) {
		    pure = Tcl_NewWideIntObj(w);






		} else if (useBig) {
		    pure = Tcl_NewBignumObj(&big);
		} else {
		    pure = Tcl_NewLongObj(l);

		}
		Tcl_IncrRefCount(pure);
		bytes = Tcl_GetStringFromObj(pure, &length);
		/* Already did the sign above */
		if (*bytes == '-') {
		    length--; bytes++;
		}
		/* Canonical decimal string reps for integers are composed
		 * entirely of one-byte encoded characters, so "length" is
		 * the number of chars */
		if (gotPrecision) {
................................................................................
	    }
		
	    case 'u':
	    case 'o':
	    case 'x':
	    case 'X': {
		Tcl_WideUInt bits;
		int length, numBits = 4, numDigits = 0, base = 16;
		int index = 0, shift = 0;
		Tcl_Obj *pure;
		char *bytes;

		if (ch == 'u') {
		    base = 10;
		}
		if (ch == 'o') {
		    base = 8;
		    numBits = 3;
		}
		if (useShort) {
		    unsigned short int us = (unsigned short int) s;
		    bits = (Tcl_WideUInt) us;
		    while (us) {
			numDigits++;
			us /= base;
................................................................................
		    }
		} else if (useWide) {
		    Tcl_WideUInt uw = (Tcl_WideUInt) w;
		    bits = uw;
		    while (uw) {
			numDigits++;
			uw /= base;
		    }
		} else if (useBig) {
		    int leftover = (big.used * DIGIT_BIT) % numBits;
		    mp_digit mask = (~(mp_digit)0) << (DIGIT_BIT-leftover);
		    numDigits = 1 + ((big.used * DIGIT_BIT) / numBits);
		    while ((mask & big.dp[big.used-1]) == 0) {
			numDigits--;
			mask >>= numBits;
		    }
		} else {
		    unsigned long int ul = (unsigned long int) l;
		    bits = (Tcl_WideUInt) ul;
		    while (ul) {
			numDigits++;
			ul /= base;
................................................................................
		    numDigits = 1;
		}
		pure = Tcl_NewObj();
		Tcl_SetObjLength(pure, numDigits);
		bytes = Tcl_GetString(pure);
		length = numDigits;
		while (numDigits--) {
		    int digitOffset;
		    if (useBig) {
			if (shift<CHAR_BIT*sizeof(Tcl_WideUInt)-DIGIT_BIT) {
			    bits |= (big.dp[index++] << shift);
			    shift += DIGIT_BIT;
			}
			shift -= numBits;
		    }
		    digitOffset = (int) (bits % base);
		    if (digitOffset > 9) {
			bytes[numDigits] = 'a' + digitOffset - 10;
		    } else {
			bytes[numDigits] = '0' + digitOffset;
		    }
		    bits /= base;
		}