| ︙ | | | ︙ | |
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
* Copyright (c) 1998-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.
*
* This code contributed by Karl Lehenbauer and Mark Diekhans
*
* RCS: @(#) $Id: tclCkalloc.c,v 1.5 1999/08/10 02:42:12 welch Exp $
*/
#include "tclInt.h"
#include "tclPort.h"
#define FALSE 0
#define TRUE 1
|
|
|
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
* Copyright (c) 1998-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.
*
* This code contributed by Karl Lehenbauer and Mark Diekhans
*
* RCS: @(#) $Id: tclCkalloc.c,v 1.5.4.1 1999/09/22 04:12:45 hobbs Exp $
*/
#include "tclInt.h"
#include "tclPort.h"
#define FALSE 0
#define TRUE 1
|
| ︙ | | | ︙ | |
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
|
char *fileName;
{
FILE *fileP;
struct mem_header *memScanP;
char *address;
if (fileName == NULL) {
fileP = stdout;
} else {
fileP = fopen(fileName, "w");
if (fileP == NULL) {
return TCL_ERROR;
}
}
|
|
|
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
|
char *fileName;
{
FILE *fileP;
struct mem_header *memScanP;
char *address;
if (fileName == NULL) {
fileP = stderr;
} else {
fileP = fopen(fileName, "w");
if (fileP == NULL) {
return TCL_ERROR;
}
}
|
| ︙ | | | ︙ | |
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
|
* autodefines __FILE__ and __LINE__.
*
*----------------------------------------------------------------------
*/
int
Tcl_DbCkfree(ptr, file, line)
char * ptr;
char *file;
int line;
{
/*
* The following cast is *very* tricky. Must convert the pointer
* to an integer before doing arithmetic on it, because otherwise
* the arithmetic will be done differently (and incorrectly) on
* word-addressed machines such as Crays (will subtract only bytes,
* even though BODY_OFFSET is in words on these machines).
*/
struct mem_header *memp = (struct mem_header *)
(((unsigned long) ptr) - BODY_OFFSET);
if (alloc_tracing)
fprintf(stderr, "ckfree %lx %ld %s %d\n",
(long unsigned int) memp->body, memp->length, file, line);
if (validate_memory)
Tcl_ValidateAllMemory(file, line);
|
|
|
|
>
>
>
>
>
>
<
|
|
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
|
* autodefines __FILE__ and __LINE__.
*
*----------------------------------------------------------------------
*/
int
Tcl_DbCkfree(ptr, file, line)
char *ptr;
char *file;
int line;
{
struct mem_header *memp;
if (ptr == NULL) {
return;
}
/*
* The following cast is *very* tricky. Must convert the pointer
* to an integer before doing arithmetic on it, because otherwise
* the arithmetic will be done differently (and incorrectly) on
* word-addressed machines such as Crays (will subtract only bytes,
* even though BODY_OFFSET is in words on these machines).
*/
memp = (struct mem_header *) (((unsigned long) ptr) - BODY_OFFSET);
if (alloc_tracing)
fprintf(stderr, "ckfree %lx %ld %s %d\n",
(long unsigned int) memp->body, memp->length, file, line);
if (validate_memory)
Tcl_ValidateAllMemory(file, line);
|
| ︙ | | | ︙ | |
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
|
char *ptr;
unsigned int size;
char *file;
int line;
{
char *new;
unsigned int copySize;
/*
* See comment from Tcl_DbCkfree before you change the following
* line.
*/
struct mem_header *memp = (struct mem_header *)
(((unsigned long) ptr) - BODY_OFFSET);
copySize = size;
if (copySize > (unsigned int) memp->length) {
copySize = memp->length;
}
new = Tcl_DbCkalloc(size, file, line);
memcpy((VOID *) new, (VOID *) ptr, (size_t) copySize);
|
>
>
>
>
>
<
|
|
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
|
char *ptr;
unsigned int size;
char *file;
int line;
{
char *new;
unsigned int copySize;
struct mem_header *memp;
if (ptr == NULL) {
return Tcl_DbCkalloc(size, file, line);
}
/*
* See comment from Tcl_DbCkfree before you change the following
* line.
*/
memp = (struct mem_header *) (((unsigned long) ptr) - BODY_OFFSET);
copySize = size;
if (copySize > (unsigned int) memp->length) {
copySize = memp->length;
}
new = Tcl_DbCkalloc(size, file, line);
memcpy((VOID *) new, (VOID *) ptr, (size_t) copySize);
|
| ︙ | | | ︙ | |
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
|
*----------------------------------------------------------------------
*/
char *
Tcl_Alloc (size)
unsigned int size;
{
char *result;
result = TclpAlloc(size);
if (result == NULL)
panic("unable to alloc %d bytes", size);
return result;
}
char *
Tcl_DbCkalloc(size, file, line)
unsigned int size;
char *file;
int line;
{
char *result;
result = (char *) TclpAlloc(size);
if (result == NULL) {
fflush(stdout);
panic("unable to alloc %d bytes, %s line %d", size, file,
line);
}
return result;
}
|
|
|
>
>
>
>
>
>
>
>
>
|
|
>
|
|
|
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
|
*----------------------------------------------------------------------
*/
char *
Tcl_Alloc (size)
unsigned int size;
{
char *result;
result = TclpAlloc(size);
/*
* Most systems will not alloc(0), instead bumping it to one so
* that NULL isn't returned. Some systems (AIX, Tru64) will alloc(0)
* by returning NULL, so we have to check that the NULL we get is
* not in response to alloc(0).
*
* The ANSI spec actually says that systems either return NULL *or*
* a special pointer on failure, but we only check for NULL
*/
if ((result == NULL) && size) {
panic("unable to alloc %d bytes", size);
}
return result;
}
char *
Tcl_DbCkalloc(size, file, line)
unsigned int size;
char *file;
int line;
{
char *result;
result = (char *) TclpAlloc(size);
if ((result == NULL) && size) {
fflush(stdout);
panic("unable to alloc %d bytes, %s line %d", size, file,
line);
}
return result;
}
|
| ︙ | | | ︙ | |
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
|
Tcl_Realloc(ptr, size)
char *ptr;
unsigned int size;
{
char *result;
result = TclpRealloc(ptr, size);
if (result == NULL)
panic("unable to realloc %d bytes", size);
return result;
}
char *
Tcl_DbCkrealloc(ptr, size, file, line)
char *ptr;
unsigned int size;
char *file;
int line;
{
char *result;
result = (char *) TclpRealloc(ptr, size);
if (result == NULL) {
fflush(stdout);
panic("unable to realloc %d bytes, %s line %d", size, file,
line);
}
return result;
}
/*
*----------------------------------------------------------------------
*
* Tcl_Free --
* Interface to TclpFree when TCL_MEM_DEBUG is disabled. Done here
* rather in the macro to keep some modules from being compiled with
* TCL_MEM_DEBUG enabled and some with it disabled.
*
*----------------------------------------------------------------------
*/
void
Tcl_Free (ptr)
char *ptr;
{
TclpFree(ptr);
}
int
Tcl_DbCkfree(ptr, file, line)
char * ptr;
char *file;
int line;
{
TclpFree(ptr);
return 0;
}
/*
*----------------------------------------------------------------------
|
>
|
>
|
|
<
|
|
|
|
|
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
|
Tcl_Realloc(ptr, size)
char *ptr;
unsigned int size;
{
char *result;
result = TclpRealloc(ptr, size);
if ((result == NULL) && size) {
panic("unable to realloc %d bytes", size);
}
return result;
}
char *
Tcl_DbCkrealloc(ptr, size, file, line)
char *ptr;
unsigned int size;
char *file;
int line;
{
char *result;
result = (char *) TclpRealloc(ptr, size);
if ((result == NULL) && size) {
fflush(stdout);
panic("unable to realloc %d bytes, %s line %d", size, file, line);
}
return result;
}
/*
*----------------------------------------------------------------------
*
* Tcl_Free --
* Interface to TclpFree when TCL_MEM_DEBUG is disabled. Done here
* rather in the macro to keep some modules from being compiled with
* TCL_MEM_DEBUG enabled and some with it disabled.
*
*----------------------------------------------------------------------
*/
void
Tcl_Free (ptr)
char *ptr;
{
TclpFree(ptr);
}
int
Tcl_DbCkfree(ptr, file, line)
char *ptr;
char *file;
int line;
{
TclpFree(ptr);
return 0;
}
/*
*----------------------------------------------------------------------
|
| ︙ | | | ︙ | |