Tcl Source Code

Check-in [cd2c0f98f9]
Login

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

Overview
Comment:move the allocator stuff to the end of tclInt.h, in order not to interfere with tclIntDecls.h
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | mig-alloc-reform
Files: files | file ages | folders
SHA1: cd2c0f98f9d17aeb64f81a6166d796f2fb17df0b
User & Date: mig 2011-03-18 22:42:48
Context
2011-03-18
22:57
remove TclpAlloc and friends from internal stubs check-in: 28384cbc01 user: mig tags: mig-alloc-reform
22:42
move the allocator stuff to the end of tclInt.h, in order not to interfere with tclIntDecls.h check-in: cd2c0f98f9 user: mig tags: mig-alloc-reform
19:18
let TclAllocMaximize maintain zippys stats check-in: 9cb2f836cb user: mig tags: mig-alloc-reform
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to generic/tclInt.h.

3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
# define TclDecrRefCount(objPtr) \
    Tcl_DbDecrRefCount(objPtr, __FILE__, __LINE__)

# define TclNewListObjDirect(objc, objv) \
    TclDbNewListObjDirect(objc, objv, __FILE__, __LINE__)

#endif /* TCL_MEM_DEBUG */

/*
 * Macros that drive the allocator behaviour
 */

#if defined(TCL_THREADS)
/*
 * The TCL_THREADS mode is like the regular mode but allocates Tcl_Obj's from
 * per-thread caches.
 */
MODULE_SCOPE void	TclpFreeAllocCache(void *);
MODULE_SCOPE void *	TclpGetAllocCache(void);
MODULE_SCOPE void	TclpSetAllocCache(void *);
MODULE_SCOPE void	TclFreeAllocCache(void *);
MODULE_SCOPE void	TclpFreeAllocMutex(Tcl_Mutex *mutex);
MODULE_SCOPE Tcl_Mutex *TclpNewAllocMutex(void);
#endif

/*
 * List of valid allocators. Have to respect the following convention:
 *  - allocators that shunt TclpAlloc to malloc are below aNONE
 *  - allocators that use zippy are above aNONE
 */

#define aNATIVE    0
#define aPURIFY    1
#define aNONE      2 
#define aZIPPY     3
#define aMULTI     4

#if defined(TCL_ALLOCATOR) && ((TCL_ALLOCATOR < 0) || (TCL_ALLOCATOR > aMULTI))
#undef TCL_ALLOCATOR
#endif

#ifdef PURIFY
#  undef TCL_ALLOCATOR
#  define TCL_ALLOCATOR aPURIFY
#endif

#if !defined(TCL_ALLOCATOR)
#  if defined(USE_THREAD_ALLOC) || defined(USE_TCLALLOC)
#    define TCL_ALLOCATOR aZIPPY
#  else
#    define TCL_ALLOCATOR aNATIVE
#  endif
#endif

#if TCL_ALLOCATOR < aNONE /* native or purify */
#    define TclpAlloc(size) ckalloc(size)
#    define TclpRealloc(ptr, size) ckrealloc((ptr),(size))
#    define TclpFree(size) ckfree(size)
#    define TclAllocMaximize(ptr) UINT_MAX
#else
   MODULE_SCOPE char * TclpAlloc(unsigned int size);
   MODULE_SCOPE char * TclpRealloc(char * ptr, unsigned int size);
   MODULE_SCOPE void   TclpFree(char * ptr);
   MODULE_SCOPE unsigned int TclAllocMaximize(void *ptr);
#endif

#if TCL_ALLOCATOR == aPURIFY
#  define TclSmallAlloc() ckalloc(sizeof(Tcl_Obj))
#  define TclSmallFree(ptr) ckfree(ptr)
#  define TclInitAlloc()
#  define TclFinalizeAlloc()
#else
   MODULE_SCOPE void * TclSmallAlloc();
   MODULE_SCOPE void   TclSmallFree(void *ptr);
   MODULE_SCOPE void   TclInitAlloc(void);
   MODULE_SCOPE void   TclFinalizeAlloc(void);
#endif

#define TclCkSmallAlloc(nbytes, memPtr)					\
    do {								\
	TCL_CT_ASSERT((nbytes)<=sizeof(Tcl_Obj));			\
	memPtr = TclSmallAlloc();					\
    } while (0)

/*
 * Support for Clang Static Analyzer <http://clang-analyzer.llvm.org>
 */

#if (TCL_ALLOCATOR == aPURIFY) && defined(__clang__)
#if __has_feature(attribute_analyzer_noreturn) && \
       !defined(Tcl_Panic) && defined(Tcl_Panic_TCL_DECLARED)
void Tcl_Panic(const char *, ...) __attribute__((analyzer_noreturn));
#endif
#if !defined(CLANG_ASSERT)
#include <assert.h>
#define CLANG_ASSERT(x) assert(x)
#endif
#elif !defined(CLANG_ASSERT)
 #define CLANG_ASSERT(x)
#endif /* PURIFY && __clang__ */



/*
 *----------------------------------------------------------------
 * Macro used by the Tcl core to set a Tcl_Obj's string representation to a
 * copy of the "len" bytes starting at "bytePtr". This code works even if the
 * byte array contains NULLs as long as the length is correct. Because "len"
 * is referenced multiple times, it should be as simple an expression as







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







3809
3810
3811
3812
3813
3814
3815































































































3816
3817
3818
3819
3820
3821
3822
# define TclDecrRefCount(objPtr) \
    Tcl_DbDecrRefCount(objPtr, __FILE__, __LINE__)

# define TclNewListObjDirect(objc, objv) \
    TclDbNewListObjDirect(objc, objv, __FILE__, __LINE__)

#endif /* TCL_MEM_DEBUG */
































































































/*
 *----------------------------------------------------------------
 * Macro used by the Tcl core to set a Tcl_Obj's string representation to a
 * copy of the "len" bytes starting at "bytePtr". This code works even if the
 * byte array contains NULLs as long as the length is correct. Because "len"
 * is referenced multiple times, it should be as simple an expression as
4501
4502
4503
4504
4505
4506
4507
4508
































































































4509
4510
4511
4512
4513
4514
4515
4516
4517
#else
#define NRE_ASSERT(expr)
#endif

#include "tclIntDecls.h"
#include "tclIntPlatDecls.h"
#include "tclTomMathDecls.h"

































































































#endif /* _TCLINT */

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>









4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
#else
#define NRE_ASSERT(expr)
#endif

#include "tclIntDecls.h"
#include "tclIntPlatDecls.h"
#include "tclTomMathDecls.h"

/*
 * Macros that drive the allocator behaviour
 * WARNING: these have to come AFTER tclIntDecls.h, as some macros may
 * interfere with those declarations.
 */

#if defined(TCL_THREADS)
/*
 * The TCL_THREADS mode is like the regular mode but allocates Tcl_Obj's from
 * per-thread caches.
 */
MODULE_SCOPE void	TclpFreeAllocCache(void *);
MODULE_SCOPE void *	TclpGetAllocCache(void);
MODULE_SCOPE void	TclpSetAllocCache(void *);
MODULE_SCOPE void	TclFreeAllocCache(void *);
MODULE_SCOPE void	TclpFreeAllocMutex(Tcl_Mutex *mutex);
MODULE_SCOPE Tcl_Mutex *TclpNewAllocMutex(void);
#endif

/*
 * List of valid allocators. Have to respect the following convention:
 *  - allocators that shunt TclpAlloc to malloc are below aNONE
 *  - allocators that use zippy are above aNONE
 */

#define aNATIVE    0
#define aPURIFY    1
#define aNONE      2 
#define aZIPPY     3
#define aMULTI     4

#if defined(TCL_ALLOCATOR) && ((TCL_ALLOCATOR < 0) || (TCL_ALLOCATOR > aMULTI))
#undef TCL_ALLOCATOR
#endif

#ifdef PURIFY
#  undef TCL_ALLOCATOR
#  define TCL_ALLOCATOR aPURIFY
#endif

#if !defined(TCL_ALLOCATOR)
#  if defined(USE_THREAD_ALLOC) || defined(USE_TCLALLOC)
#    define TCL_ALLOCATOR aZIPPY
#  else
#    define TCL_ALLOCATOR aNATIVE
#  endif
#endif

#if TCL_ALLOCATOR < aNONE /* native or purify */
#    define TclpAlloc(size) ckalloc(size)
#    define TclpRealloc(ptr, size) ckrealloc((ptr),(size))
#    define TclpFree(size) ckfree(size)
#    define TclAllocMaximize(ptr) UINT_MAX
#else
   MODULE_SCOPE char * TclpAlloc(unsigned int size);
   MODULE_SCOPE char * TclpRealloc(char * ptr, unsigned int size);
   MODULE_SCOPE void   TclpFree(char * ptr);
   MODULE_SCOPE unsigned int TclAllocMaximize(void *ptr);
#endif

#if TCL_ALLOCATOR == aPURIFY
#  define TclSmallAlloc() ckalloc(sizeof(Tcl_Obj))
#  define TclSmallFree(ptr) ckfree(ptr)
#  define TclInitAlloc()
#  define TclFinalizeAlloc()
#else
   MODULE_SCOPE void * TclSmallAlloc();
   MODULE_SCOPE void   TclSmallFree(void *ptr);
   MODULE_SCOPE void   TclInitAlloc(void);
   MODULE_SCOPE void   TclFinalizeAlloc(void);
#endif

#define TclCkSmallAlloc(nbytes, memPtr)					\
    do {								\
	TCL_CT_ASSERT((nbytes)<=sizeof(Tcl_Obj));			\
	memPtr = TclSmallAlloc();					\
    } while (0)

/*
 * Support for Clang Static Analyzer <http://clang-analyzer.llvm.org>
 */

#if (TCL_ALLOCATOR == aPURIFY) && defined(__clang__)
#if __has_feature(attribute_analyzer_noreturn) && \
       !defined(Tcl_Panic) && defined(Tcl_Panic_TCL_DECLARED)
void Tcl_Panic(const char *, ...) __attribute__((analyzer_noreturn));
#endif
#if !defined(CLANG_ASSERT)
#include <assert.h>
#define CLANG_ASSERT(x) assert(x)
#endif
#elif !defined(CLANG_ASSERT)
 #define CLANG_ASSERT(x)
#endif /* PURIFY && __clang__ */


#endif /* _TCLINT */

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */