88 * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
99 * Portions Copyright (c) 1994, Regents of the University of California
1010 *
11- * $Id: c.h,v 1.64 2000/01/26 05:57:46 momjian Exp $
11+ * $Id: c.h,v 1.65 2000/03/19 22:08:51 tgl Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
1515/*
1616 * TABLE OF CONTENTS
1717 *
18- *When adding stuff to this file, please tryand put stuff
18+ *When adding stuff to this file, please tryto put stuff
1919 *into the relevant section, or add new sections as appropriate.
2020 *
2121 * sectiondescription
3434 *10)Berkeley-specific defs
3535 *11)system-specific hacks
3636 *
37- * NOTES
38- *
39- *This file is MACHINE AND COMPILER dependent!!!(For now.)
40- *
4137 * ----------------------------------------------------------------
4238 */
4339#ifndef C_H
@@ -279,8 +275,6 @@ typedef signed int Offset;
279275 *
280276 *If your machine meets these requirements, Datums should also be checked
281277 *to see if the positioning is correct.
282- *
283- *This file is MACHINE AND COMPILER dependent!!!
284278 */
285279
286280typedef unsigned long Datum ;/* XXX sizeof(long) >= sizeof(void *) */
@@ -403,28 +397,28 @@ typedef Datum *DatumPtr;
403397 *Returns pointer value of a datum.
404398 */
405399
406- #define DatumGetPointer (X ) ((Pointer)X )
400+ #define DatumGetPointer (X ) ((Pointer)(X) )
407401
408402/*
409403 * PointerGetDatum
410404 *Returns datum representation for a pointer.
411405 */
412406
413- #define PointerGetDatum (X ) ((Datum)X )
407+ #define PointerGetDatum (X ) ((Datum)(X) )
414408
415409/*
416410 * DatumGetName
417411 *Returns name value of a datum.
418412 */
419413
420- #define DatumGetName (X ) ((Name) DatumGetPointer((Datum)X ))
414+ #define DatumGetName (X ) ((Name) DatumGetPointer((Datum)(X) ))
421415
422416/*
423417 * NameGetDatum
424418 *Returns datum representation for a name.
425419 */
426420
427- #define NameGetDatum (X ) PointerGetDatum((Pointer)X )
421+ #define NameGetDatum (X ) PointerGetDatum((Pointer)(X) )
428422
429423
430424/*
@@ -433,15 +427,15 @@ typedef Datum *DatumPtr;
433427 *This is really a pointer, of course.
434428 */
435429
436- #define DatumGetFloat32 (X ) ((float32) DatumGetPointer((Datum) X))
430+ #define DatumGetFloat32 (X ) ((float32) DatumGetPointer(X))
437431
438432/*
439433 * Float32GetDatum
440434 *Returns datum representation for a 32-bit floating point number.
441435 *This is really a pointer, of course.
442436 */
443437
444- #define Float32GetDatum (X ) PointerGetDatum((Pointer)X )
438+ #define Float32GetDatum (X ) PointerGetDatum((Pointer)(X) )
445439
446440/*
447441 * DatumGetFloat64
@@ -457,7 +451,7 @@ typedef Datum *DatumPtr;
457451 *This is really a pointer, of course.
458452 */
459453
460- #define Float64GetDatum (X ) PointerGetDatum((Pointer)X )
454+ #define Float64GetDatum (X ) PointerGetDatum((Pointer)(X) )
461455
462456/* ----------------------------------------------------------------
463457 *Section 5:IsValid macros for system types
@@ -473,18 +467,7 @@ typedef Datum *DatumPtr;
473467 * PointerIsValid
474468 *True iff pointer is valid.
475469 */
476- #define PointerIsValid (pointer ) (bool)((void*)(pointer) != NULL)
477-
478- /*
479- * PointerIsInBounds
480- *True iff pointer is within given bounds.
481- *
482- * Note:
483- *Assumes the bounded interval to be [min,max),
484- *i.e. closed on the left and open on the right.
485- */
486- #define PointerIsInBounds (pointer ,min ,max ) \
487- ((min) <= (pointer) && (pointer) < (max))
470+ #define PointerIsValid (pointer ) ((void*)(pointer) != NULL)
488471
489472/*
490473 * PointerIsAligned
@@ -560,14 +543,14 @@ typedef struct Exception
560543 *Isn't CPP fun?
561544 */
562545#define TrapMacro (condition ,exception ) \
563- ((bool) ((! assert_enabled) ||(! condition) || \
546+ ((bool) ((! assert_enabled) ||! ( condition) || \
564547 (ExceptionalCondition(CppAsString(condition), \
565548 &(exception), \
566549 (char*) NULL, __FILE__, __LINE__))))
567550
568551#ifndef USE_ASSERT_CHECKING
569552#define Assert (condition )
570- #define AssertMacro (condition )(void)true
553+ #define AssertMacro (condition )(( void)true)
571554#define AssertArg (condition )
572555#define AssertState (condition )
573556#define assert_enabled 0
@@ -576,7 +559,7 @@ typedef struct Exception
576559Trap(!(condition), FailedAssertion)
577560
578561#define AssertMacro (condition ) \
579- (void)TrapMacro(!(condition), FailedAssertion)
562+ (( void) TrapMacro(!(condition), FailedAssertion) )
580563
581564#define AssertArg (condition ) \
582565Trap(!(condition), BadArg)
@@ -604,7 +587,7 @@ extern intassert_enabled;
604587 *#define foo(x) (LogAssertMacro(x != 0, "yow!") && bar(x))
605588 */
606589#define LogTrapMacro (condition ,exception ,printArgs ) \
607- ((bool) ((! assert_enabled) ||(! condition) || \
590+ ((bool) ((! assert_enabled) ||! ( condition) || \
608591 (ExceptionalCondition(CppAsString(condition), \
609592 &(exception), \
610593 vararg_format printArgs, __FILE__, __LINE__))))
@@ -659,46 +642,62 @@ extern intassertTest(int val);
659642
660643/*
661644 * StrNCpy
662- *Does string copy, and forces terminating NULL
663- */
664- /* we do this so if the macro is used in an if action, it will work */
665- #define StrNCpy (dst ,src ,len )\
666- ( \
667- ((len) > 0) ? \
668- ( \
669- strncpy((dst),(src),(len)-1), \
670- *((dst)+(len)-1)='\0' \
671- ) \
672- : \
673- (dummyret)NULL,(void)(dst) \
674- )
645+ *Like standard library function strncpy(), except that result string
646+ *is guaranteed to be null-terminated --- that is, at most N-1 bytes
647+ *of the source string will be kept.
648+ *Also, the macro returns no result (too hard to do that without
649+ *evaluating the arguments multiple times, which seems worse).
650+ */
651+ #define StrNCpy (dst ,src ,len ) \
652+ do \
653+ { \
654+ char * _dst = (dst); \
655+ Size _len = (len); \
656+ \
657+ if (_len > 0) \
658+ { \
659+ strncpy(_dst, (src), _len); \
660+ _dst[_len-1] = '\0'; \
661+ } \
662+ } while (0)
663+
675664
676665/* Get a bit mask of the bits set in non-int32 aligned addresses */
677666#define INT_ALIGN_MASK (sizeof(int32) - 1)
678667
679668/*
680- *This function gets call too often, so we inline it if we can.
681- *Are we aligned for int32?
682- *We have to cast the pointer to int so we can do the AND
669+ * MemSet
670+ *Exactly the same as standard library function memset(), but considerably
671+ *faster for zeroing small word-aligned structures (such as parsetree nodes).
672+ *This has to be a macro because the main point is to avoid function-call
673+ *overhead.
674+ *
683675 *We got the 64 number by testing this against the stock memset() on
684- *BSD/OS 3.0. Larger values were slower.
685- */
686- #define MemSet (start ,val ,len ) do \
687- { \
688- if (((long)(start) & INT_ALIGN_MASK) == 0 && \
689- ((len) & INT_ALIGN_MASK) == 0 && \
690- (val) == 0 && \
691- (len) <= 64) \
692- { \
693- int32 *_i = (int32 *)(start); \
694- int32 *_stop = (int32 *)((char *)(start) + (len)); \
695- \
696- while (_i < _stop) \
697- *_i++ = 0; \
698- } \
699- else \
700- memset((start), (val), (len)); \
701- } while (0)
676+ *BSD/OS 3.0. Larger values were slower. (I think the crossover point
677+ *could be a good deal higher for most platforms, actually --- tgl)
678+ */
679+ #define MemSet (start ,val ,len ) \
680+ do \
681+ { \
682+ int32 * _start = (int32 *) (start); \
683+ int_val = (val); \
684+ Size_len = (len); \
685+ \
686+ if ((((long) _start) & INT_ALIGN_MASK) == 0 && \
687+ (_len & INT_ALIGN_MASK) == 0 && \
688+ _val == 0 && \
689+ _len <= MEMSET_LOOP_LIMIT) \
690+ { \
691+ int32 * _stop = (int32 *) ((char *) _start + _len); \
692+ while (_start < _stop) \
693+ *_start++ = 0; \
694+ } \
695+ else \
696+ memset((char *) _start, _val, _len); \
697+ } while (0)
698+
699+ #define MEMSET_LOOP_LIMIT 64
700+
702701
703702/* ----------------------------------------------------------------
704703 *Section 9: externs