Tcl Source Code

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

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

Overview
Comment:
[kennykb-numerics-branch]
* generic/tclObj.c: Extended bignum support to include bignums so large they will not pack into a Tcl_Obj. When they outgrow Tcl's string rep length limits, a panic will result.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | kennykb-numerics-branch
Files: files | file ages | folders
SHA1:4ef199b1b37b2fda4675b5faee948538a722d06a
User & Date: dgp 2005-08-30 19:20:41
Context
2005-09-01
16:09
[kennykb-numerics-branch]
* generic/tclScan.c: Extended scan to accept the %ll...
check-in: fc4c109c84 user: dgp tags: kennykb-numerics-branch
2005-08-30
19:20
[kennykb-numerics-branch]
* generic/tclObj.c: Extended bignum support to includ...
check-in: 4ef199b1b3 user: dgp tags: kennykb-numerics-branch
15:54
[kennykb-numerics-branch]
* generic/tclTomMath.h: Added mp_sqrt to routines from ...
check-in: 7e5e925b15 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-08-30  Don Porter  <dgp@users.sourceforge.net>

	[kennykb-numerics-branch]





	* generic/tclTomMath.h:	Added mp_sqrt to routines from
	* unix/Makefile.in:	libtommath used by Tcl.
	* win/Makefile.in:
	* win/makefile.vc:

	* generic/tclBasic.c:	Extended sqrt(.) so that range covers



>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
2005-08-30  Don Porter  <dgp@users.sourceforge.net>

	[kennykb-numerics-branch]

	* generic/tclObj.c:	Extended bignum support to include bignums
	so large they will not pack into a Tcl_Obj.  When they outgrow Tcl's
	string rep length limits, a panic will result.

	* generic/tclTomMath.h:	Added mp_sqrt to routines from
	* unix/Makefile.in:	libtommath used by Tcl.
	* win/Makefile.in:
	* win/makefile.vc:

	* generic/tclBasic.c:	Extended sqrt(.) so that range covers

Changes to generic/tclObj.c.

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
...
141
142
143
144
145
146
147





148



149
150
151
152
153
154
155

156


157
158
159
160
161
162
163
164
165
166
167
168
169
170
....
2516
2517
2518
2519
2520
2521
2522



2523
2524
2525
2526
2527
2528
2529
....
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
 * Copyright (c) 1999 by Scriptics Corporation.
 * Copyright (c) 2001 by ActiveState Corporation.
 * Copyright (c) 2005 by Kevin B. Kenny.  All rights reserved.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * RCS: @(#) $Id: tclObj.c,v 1.72.2.31 2005/08/25 15:46:31 dgp Exp $
 */

#include "tclInt.h"
#include "tommath.h"
#include <float.h>

#define BIGNUM_AUTO_NARROW 1
................................................................................


/*
 * Macros to pack/unpack a bignum's fields in a Tcl_Obj internal rep
 */

#define PACK_BIGNUM(bignum, objPtr) \





    do { \



	(objPtr)->internalRep.bignumValue.digits = (void*) (bignum).dp; \
	(objPtr)->internalRep.bignumValue.misc = ( \
		((bignum).sign << 30) \
		| ((bignum).alloc << 15) \
		| ((bignum).used)); \
    } while (0)


#define UNPACK_BIGNUM(objPtr, bignum) \


    do { \
	(bignum).dp = (mp_digit*) (objPtr)->internalRep.bignumValue.digits; \
	(bignum).sign = (objPtr)->internalRep.bignumValue.misc >> 30; \
	(bignum).alloc = \
		((objPtr)->internalRep.bignumValue.misc >> 15) & 0x7fff; \
	(bignum).used = (objPtr)->internalRep.bignumValue.misc & 0x7fff; \
    } while (0)

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

static int		ParseBoolean _ANSI_ARGS_((Tcl_Obj *objPtr));
static int		SetBooleanFromAny _ANSI_ARGS_((Tcl_Interp *interp,
................................................................................
static void
FreeBignum(Tcl_Obj *objPtr)
{
    mp_int toFree;		/* Bignum to free */

    UNPACK_BIGNUM(objPtr, toFree);
    mp_clear(&toFree);



}
 
/*
 *----------------------------------------------------------------------
 *
 * DupBignum --
 *
................................................................................
}

void
TclSetBignumIntRep(objPtr, bignumValue)
    Tcl_Obj *objPtr;
    mp_int *bignumValue;
{
    if (bignumValue->used > 0x7fff) {
	Tcl_Panic("TclSetBignumIntRep: too large for packed bignum");
    }
    if (bignumValue->alloc > 0x7fff) {
	mp_shrink(bignumValue);
    }
    objPtr->typePtr = &tclBignumType;
    PACK_BIGNUM(*bignumValue, objPtr);

    /* Clear the value with mp_init; mp_clear overwrites the digit array. */

    mp_init(bignumValue);
}







|







 







>
>
>
>
>
|
>
>
>





<
|
>

>
>
|





|







 







>
>
>







 







<
<
<
<
<
<







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
...
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161

162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
....
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
....
2845
2846
2847
2848
2849
2850
2851






2852
2853
2854
2855
2856
2857
2858
 * Copyright (c) 1999 by Scriptics Corporation.
 * Copyright (c) 2001 by ActiveState Corporation.
 * Copyright (c) 2005 by Kevin B. Kenny.  All rights reserved.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * RCS: @(#) $Id: tclObj.c,v 1.72.2.32 2005/08/30 19:20:42 dgp Exp $
 */

#include "tclInt.h"
#include "tommath.h"
#include <float.h>

#define BIGNUM_AUTO_NARROW 1
................................................................................


/*
 * Macros to pack/unpack a bignum's fields in a Tcl_Obj internal rep
 */

#define PACK_BIGNUM(bignum, objPtr) \
    if ((bignum).used > 0x7fff) { \
	mp_int *temp = (void *) ckalloc((unsigned) sizeof(mp_int)); \
	*temp = bignum; \
	(objPtr)->internalRep.bignumValue.digits = (void*) temp; \
	(objPtr)->internalRep.bignumValue.misc = -1; \
    } else { \
	if ((bignum).alloc > 0x7fff) { \
	    mp_shrink(&(bignum)); \
	} \
	(objPtr)->internalRep.bignumValue.digits = (void*) (bignum).dp; \
	(objPtr)->internalRep.bignumValue.misc = ( \
		((bignum).sign << 30) \
		| ((bignum).alloc << 15) \
		| ((bignum).used)); \

    }

#define UNPACK_BIGNUM(objPtr, bignum) \
    if ((objPtr)->internalRep.bignumValue.misc == -1) { \
	(bignum) = *((mp_int *) ((objPtr)->internalRep.bignumValue.digits)); \
    } else { \
	(bignum).dp = (mp_digit*) (objPtr)->internalRep.bignumValue.digits; \
	(bignum).sign = (objPtr)->internalRep.bignumValue.misc >> 30; \
	(bignum).alloc = \
		((objPtr)->internalRep.bignumValue.misc >> 15) & 0x7fff; \
	(bignum).used = (objPtr)->internalRep.bignumValue.misc & 0x7fff; \
    }

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

static int		ParseBoolean _ANSI_ARGS_((Tcl_Obj *objPtr));
static int		SetBooleanFromAny _ANSI_ARGS_((Tcl_Interp *interp,
................................................................................
static void
FreeBignum(Tcl_Obj *objPtr)
{
    mp_int toFree;		/* Bignum to free */

    UNPACK_BIGNUM(objPtr, toFree);
    mp_clear(&toFree);
    if (objPtr->internalRep.bignumValue.misc < 0) {
	ckfree((char *)objPtr->internalRep.bignumValue.digits);
    }
}
 
/*
 *----------------------------------------------------------------------
 *
 * DupBignum --
 *
................................................................................
}

void
TclSetBignumIntRep(objPtr, bignumValue)
    Tcl_Obj *objPtr;
    mp_int *bignumValue;
{






    objPtr->typePtr = &tclBignumType;
    PACK_BIGNUM(*bignumValue, objPtr);

    /* Clear the value with mp_init; mp_clear overwrites the digit array. */

    mp_init(bignumValue);
}