Minimal NSPR subset required to build JS engine

This commit is contained in:
fur%netscape.com 1998-09-02 22:37:14 +00:00
Родитель b73da9e0ca
Коммит 21b788956e
22 изменённых файлов: 8380 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,121 @@
# Microsoft Developer Studio Project File - Name="miniNSPR" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 5.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
CFG=miniNSPR - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "miniNSPR.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "miniNSPR.mak" CFG="miniNSPR - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "miniNSPR - Win32 Release" (based on\
"Win32 (x86) Dynamic-Link Library")
!MESSAGE "miniNSPR - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
!MESSAGE
# Begin Project
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe
!IF "$(CFG)" == "miniNSPR - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "..\Release"
# PROP Intermediate_Dir "..\Release"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
# ADD CPP /nologo /MD /W3 /GX /O2 /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "MINI_NSPR" /YX /FD /c
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o NUL /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o NUL /win32
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386
!ELSEIF "$(CFG)" == "miniNSPR - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "..\Debug"
# PROP Intermediate_Dir "..\Debug"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "MINI_NSPR" /YX /FD /c
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o NUL /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o NUL /win32
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept
!ENDIF
# Begin Target
# Name "miniNSPR - Win32 Release"
# Name "miniNSPR - Win32 Debug"
# Begin Source File
SOURCE=.\plhash.c
# End Source File
# Begin Source File
SOURCE=.\prdtoa.c
# End Source File
# Begin Source File
SOURCE=.\prlog.c
# End Source File
# Begin Source File
SOURCE=.\prlog2.c
# End Source File
# Begin Source File
SOURCE=.\prlong.c
# End Source File
# Begin Source File
SOURCE=.\prmem.c
# End Source File
# Begin Source File
SOURCE=.\prprf.c
# End Source File
# Begin Source File
SOURCE=.\prstubs.c
# End Source File
# End Target
# End Project

193
js/src/mininspr/plarena.h Normal file
Просмотреть файл

@ -0,0 +1,193 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef plarena_h___
#define plarena_h___
/*
* Lifetime-based fast allocation, inspired by much prior art, including
* "Fast Allocation and Deallocation of Memory Based on Object Lifetimes"
* David R. Hanson, Software -- Practice and Experience, Vol. 20(1).
*
* Also supports LIFO allocation (PL_ARENA_MARK/PL_ARENA_RELEASE).
*/
#include "prtypes.h"
#include "plarenas.h"
PR_BEGIN_EXTERN_C
typedef struct PLArena PLArena;
struct PLArena {
PLArena *next; /* next arena for this lifetime */
PRUword base; /* aligned base address, follows this header */
PRUword limit; /* one beyond last byte in arena */
PRUword avail; /* points to next available byte */
};
#ifdef PL_ARENAMETER
typedef struct PLArenaStats PLArenaStats;
struct PLArenaStats {
PLArenaStats *next; /* next in arenaStats list */
char *name; /* name for debugging */
PRUint32 narenas; /* number of arenas in pool */
PRUint32 nallocs; /* number of PL_ARENA_ALLOCATE() calls */
PRUint32 nreclaims; /* number of reclaims from freeArenas */
PRUint32 nmallocs; /* number of malloc() calls */
PRUint32 ndeallocs; /* number of lifetime deallocations */
PRUint32 ngrows; /* number of PL_ARENA_GROW() calls */
PRUint32 ninplace; /* number of in-place growths */
PRUint32 nreleases; /* number of PL_ARENA_RELEASE() calls */
PRUint32 nfastrels; /* number of "fast path" releases */
PRUint32 nbytes; /* total bytes allocated */
PRUint32 maxalloc; /* maximum allocation size in bytes */
PRFloat64 variance; /* size variance accumulator */
};
#endif
struct PLArenaPool {
PLArena first; /* first arena in pool list */
PLArena *current; /* arena from which to allocate space */
PRUint32 arenasize; /* net exact size of a new arena */
PRUword mask; /* alignment mask (power-of-2 - 1) */
#ifdef PL_ARENAMETER
PLArenaStats stats;
#endif
};
/*
* If the including .c file uses only one power-of-2 alignment, it may define
* PL_ARENA_CONST_ALIGN_MASK to the alignment mask and save a few instructions
* per ALLOCATE and GROW.
*/
#ifdef PL_ARENA_CONST_ALIGN_MASK
#define PL_ARENA_ALIGN(pool, n) (((PRUword)(n) + PL_ARENA_CONST_ALIGN_MASK) \
& ~PL_ARENA_CONST_ALIGN_MASK)
#define PL_INIT_ARENA_POOL(pool, name, size) \
PL_InitArenaPool(pool, name, size, PL_ARENA_CONST_ALIGN_MASK + 1)
#else
#define PL_ARENA_ALIGN(pool, n) (((PRUword)(n) + (pool)->mask) & ~(pool)->mask)
#endif
#define PL_ARENA_ALLOCATE(p, pool, nb) \
PR_BEGIN_MACRO \
PLArena *_a = (pool)->current; \
PRUint32 _nb = PL_ARENA_ALIGN(pool, nb); \
PRUword _p = _a->avail; \
PRUword _q = _p + _nb; \
if (_q > _a->limit) \
_p = (PRUword)PL_ArenaAllocate(pool, _nb); \
else \
_a->avail = _q; \
p = (void *)_p; \
PL_ArenaCountAllocation(pool, nb); \
PR_END_MACRO
#define PL_ARENA_GROW(p, pool, size, incr) \
PR_BEGIN_MACRO \
PLArena *_a = (pool)->current; \
PRUint32 _incr = PL_ARENA_ALIGN(pool, incr); \
PRUword _p = _a->avail; \
PRUword _q = _p + _incr; \
if (_p == (PRUword)(p) + PL_ARENA_ALIGN(pool, size) && \
_q <= _a->limit) { \
_a->avail = _q; \
PL_ArenaCountInplaceGrowth(pool, size, incr); \
} else { \
p = PL_ArenaGrow(pool, p, size, incr); \
} \
PL_ArenaCountGrowth(pool, size, incr); \
PR_END_MACRO
#define PL_ARENA_MARK(pool) ((void *) (pool)->current->avail)
#define PR_UPTRDIFF(p,q) ((PRUword)(p) - (PRUword)(q))
#ifdef DEBUG
#define PL_FREE_PATTERN 0xDA
#define PL_CLEAR_UNUSED(a) (PR_ASSERT((a)->avail <= (a)->limit), \
memset((void*)(a)->avail, PL_FREE_PATTERN, \
(a)->limit - (a)->avail))
#define PL_CLEAR_ARENA(a) memset((void*)(a), PL_FREE_PATTERN, \
(a)->limit - (PRUword)(a))
#else
#define PL_CLEAR_UNUSED(a)
#define PL_CLEAR_ARENA(a)
#endif
#define PL_ARENA_RELEASE(pool, mark) \
PR_BEGIN_MACRO \
char *_m = (char *)(mark); \
PLArena *_a = (pool)->current; \
if (PR_UPTRDIFF(_m, _a) <= PR_UPTRDIFF(_a->avail, _a)) { \
_a->avail = (PRUword)PL_ARENA_ALIGN(pool, _m); \
PL_CLEAR_UNUSED(_a); \
PL_ArenaCountRetract(pool, _m); \
} else { \
PL_ArenaRelease(pool, _m); \
} \
PL_ArenaCountRelease(pool, _m); \
PR_END_MACRO
#ifdef PL_ARENAMETER
#define PL_COUNT_ARENA(pool,op) ((pool)->stats.narenas op)
#else
#define PL_COUNT_ARENA(pool,op)
#endif
#define PL_ARENA_DESTROY(pool, a, pnext) \
PR_BEGIN_MACRO \
PL_COUNT_ARENA(pool,--); \
if ((pool)->current == (a)) (pool)->current = &(pool)->first; \
*(pnext) = (a)->next; \
PL_CLEAR_ARENA(a); \
free(a); \
(a) = 0; \
PR_END_MACRO
#ifdef PL_ARENAMETER
#include <stdio.h>
PR_EXTERN(void) PL_ArenaCountAllocation(PLArenaPool *pool, PRUint32 nb);
PR_EXTERN(void) PL_ArenaCountInplaceGrowth(
PLArenaPool *pool, PRUint32 size, PRUint32 incr);
PR_EXTERN(void) PL_ArenaCountGrowth(
PLArenaPool *pool, PRUint32 size, PRUint32 incr);
PR_EXTERN(void) PL_ArenaCountRelease(PLArenaPool *pool, char *mark);
PR_EXTERN(void) PL_ArenaCountRetract(PLArenaPool *pool, char *mark);
PR_EXTERN(void) PL_DumpArenaStats(FILE *fp);
#else /* !PL_ARENAMETER */
#define PL_ArenaCountAllocation(ap, nb) /* nothing */
#define PL_ArenaCountInplaceGrowth(ap, size, incr) /* nothing */
#define PL_ArenaCountGrowth(ap, size, incr) /* nothing */
#define PL_ArenaCountRelease(ap, mark) /* nothing */
#define PL_ArenaCountRetract(ap, mark) /* nothing */
#endif /* !PL_ARENAMETER */
PR_END_EXTERN_C
#endif /* plarena_h___ */

Просмотреть файл

@ -0,0 +1,95 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#if defined(PLARENAS_H)
#else /* defined(PLARENAS_H) */
PR_BEGIN_EXTERN_C
typedef struct PLArenaPool PLArenaPool;
/*
** Allocate an arena pool as specified by the parameters.
**
** This is equivelant to allocating the space yourself and then
** calling PL_InitArenaPool().
**
** This function may fail (and return a NULL) for a variety of
** reasons. The reason for a particular failure can be discovered
** by calling PR_GetError().
*/
#if 0 /* Not implemented */
PR_EXTERN(PLArenaPool*) PL_AllocArenaPool(
const char *name, PRUint32 size, PRUint32 align);
#endif
/*
** Destroy an arena pool previously allocated by PL_AllocArenaPool().
**
** This function may fail if the arena is not empty and the caller
** wishes to check for empty upon descruction.
*/
#if 0 /* Not implemented */
PR_EXTERN(PRStatus) PL_DestroyArenaPool(PLArenaPool *pool, PRBool checkEmpty);
#endif
/*
** Initialize an arena pool with the given name for debugging and metering,
** with a minimum size per arena of size bytes.
**/
PR_EXTERN(void) PL_InitArenaPool(
PLArenaPool *pool, const char *name, PRUint32 size, PRUint32 align);
/*
** Finish using arenas, freeing all memory associated with them.
**/
PR_EXTERN(void) PL_ArenaFinish(void);
/*
** Free the arenas in pool. The user may continue to allocate from pool
** after calling this function. There is no need to call PL_InitArenaPool()
** again unless PL_FinishArenaPool(pool) has been called.
**/
PR_EXTERN(void) PL_FreeArenaPool(PLArenaPool *pool);
/*
** Free the arenas in pool and finish using it altogether.
**/
PR_EXTERN(void) PL_FinishArenaPool(PLArenaPool *pool);
/*
** Compact all of the arenas in a pool so that no space is wasted.
**/
PR_EXTERN(void) PL_CompactArenaPool(PLArenaPool *pool);
/*
** Friend functions used by the PL_ARENA_*() macros.
**/
PR_EXTERN(void *) PL_ArenaAllocate(PLArenaPool *pool, PRUint32 nb);
PR_EXTERN(void *) PL_ArenaGrow(
PLArenaPool *pool, void *p, PRUint32 size, PRUint32 incr);
PR_EXTERN(void) PL_ArenaRelease(PLArenaPool *pool, char *mark);
PR_END_EXTERN_C
#endif /* defined(PLARENAS_H) */
/* plarenas */

477
js/src/mininspr/plhash.c Normal file
Просмотреть файл

@ -0,0 +1,477 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/*
* PL hash table package.
*/
#include "plhash.h"
#include "prbit.h"
#include "prlog.h"
#include "prmem.h"
#include "prtypes.h"
#include <stdlib.h>
#include <string.h>
/* Compute the number of buckets in ht */
#define NBUCKETS(ht) (1 << (PL_HASH_BITS - (ht)->shift))
/* The smallest table has 16 buckets */
#define MINBUCKETSLOG2 4
#define MINBUCKETS (1 << MINBUCKETSLOG2)
/* Compute the maximum entries given n buckets that we will tolerate, ~90% */
#define OVERLOADED(n) ((n) - ((n) >> 3))
/* Compute the number of entries below which we shrink the table by half */
#define UNDERLOADED(n) (((n) > MINBUCKETS) ? ((n) >> 2) : 0)
/*
** Stubs for default hash allocator ops.
*/
static void * PR_CALLBACK
DefaultAllocTable(void *pool, PRSize size)
{
#if defined(XP_MAC)
#pragma unused (pool)
#endif
return PR_MALLOC(size);
}
static void PR_CALLBACK
DefaultFreeTable(void *pool, void *item)
{
#if defined(XP_MAC)
#pragma unused (pool)
#endif
PR_DELETE(item);
}
static PLHashEntry * PR_CALLBACK
DefaultAllocEntry(void *pool, const void *key)
{
#if defined(XP_MAC)
#pragma unused (pool,key)
#endif
return PR_NEW(PLHashEntry);
}
static void PR_CALLBACK
DefaultFreeEntry(void *pool, PLHashEntry *he, PRUintn flag)
{
#if defined(XP_MAC)
#pragma unused (pool)
#endif
if (flag == HT_FREE_ENTRY)
PR_DELETE(he);
}
static PLHashAllocOps defaultHashAllocOps = {
DefaultAllocTable, DefaultFreeTable,
DefaultAllocEntry, DefaultFreeEntry
};
PR_IMPLEMENT(PLHashTable *)
PL_NewHashTable(PRUint32 n, PLHashFunction keyHash,
PLHashComparator keyCompare, PLHashComparator valueCompare,
PLHashAllocOps *allocOps, void *allocPriv)
{
PLHashTable *ht;
PRUint32 nb;
if (n <= MINBUCKETS) {
n = MINBUCKETSLOG2;
} else {
n = PR_CeilingLog2(n);
if ((PRInt32)n < 0)
return 0;
}
if (!allocOps) allocOps = &defaultHashAllocOps;
ht = (PLHashTable*)((*allocOps->allocTable)(allocPriv, sizeof *ht));
if (!ht)
return 0;
memset(ht, 0, sizeof *ht);
ht->shift = PL_HASH_BITS - n;
n = 1 << n;
#if defined(XP_PC) && !defined(_WIN32)
if (n > 16000) {
(*allocOps->freeTable)(allocPriv, ht);
return 0;
}
#endif /* WIN16 */
nb = n * sizeof(PLHashEntry *);
ht->buckets = (PLHashEntry**)((*allocOps->allocTable)(allocPriv, nb));
if (!ht->buckets) {
(*allocOps->freeTable)(allocPriv, ht);
return 0;
}
memset(ht->buckets, 0, nb);
ht->keyHash = keyHash;
ht->keyCompare = keyCompare;
ht->valueCompare = valueCompare;
ht->allocOps = allocOps;
ht->allocPriv = allocPriv;
return ht;
}
PR_IMPLEMENT(void)
PL_HashTableDestroy(PLHashTable *ht)
{
PRUint32 i, n;
PLHashEntry *he, *next;
PLHashAllocOps *allocOps = ht->allocOps;
void *allocPriv = ht->allocPriv;
n = NBUCKETS(ht);
for (i = 0; i < n; i++) {
for (he = ht->buckets[i]; he; he = next) {
next = he->next;
(*allocOps->freeEntry)(allocPriv, he, HT_FREE_ENTRY);
}
}
#ifdef DEBUG
memset(ht->buckets, 0xDB, n * sizeof ht->buckets[0]);
#endif
(*allocOps->freeTable)(allocPriv, ht->buckets);
#ifdef DEBUG
memset(ht, 0xDB, sizeof *ht);
#endif
(*allocOps->freeTable)(allocPriv, ht);
}
/*
** Multiplicative hash, from Knuth 6.4.
*/
#define GOLDEN_RATIO 0x9E3779B9U
PR_IMPLEMENT(PLHashEntry **)
PL_HashTableRawLookup(PLHashTable *ht, PLHashNumber keyHash, const void *key)
{
PLHashEntry *he, **hep, **hep0;
PLHashNumber h;
#ifdef HASHMETER
ht->nlookups++;
#endif
h = keyHash * GOLDEN_RATIO;
h >>= ht->shift;
hep = hep0 = &ht->buckets[h];
while ((he = *hep) != 0) {
if (he->keyHash == keyHash && (*ht->keyCompare)(key, he->key)) {
/* Move to front of chain if not already there */
if (hep != hep0) {
*hep = he->next;
he->next = *hep0;
*hep0 = he;
}
return hep0;
}
hep = &he->next;
#ifdef HASHMETER
ht->nsteps++;
#endif
}
return hep;
}
PR_IMPLEMENT(PLHashEntry *)
PL_HashTableRawAdd(PLHashTable *ht, PLHashEntry **hep,
PLHashNumber keyHash, const void *key, void *value)
{
PRUint32 i, n;
PLHashEntry *he, *next, **oldbuckets;
PRUint32 nb;
/* Grow the table if it is overloaded */
n = NBUCKETS(ht);
if (ht->nentries >= OVERLOADED(n)) {
#ifdef HASHMETER
ht->ngrows++;
#endif
ht->shift--;
oldbuckets = ht->buckets;
#if defined(XP_PC) && !defined(_WIN32)
if (2 * n > 16000)
return 0;
#endif /* WIN16 */
nb = 2 * n * sizeof(PLHashEntry *);
ht->buckets = (PLHashEntry**)
((*ht->allocOps->allocTable)(ht->allocPriv, nb));
if (!ht->buckets) {
ht->buckets = oldbuckets;
return 0;
}
memset(ht->buckets, 0, nb);
for (i = 0; i < n; i++) {
for (he = oldbuckets[i]; he; he = next) {
next = he->next;
hep = PL_HashTableRawLookup(ht, he->keyHash, he->key);
PR_ASSERT(*hep == 0);
he->next = 0;
*hep = he;
}
}
#ifdef DEBUG
memset(oldbuckets, 0xDB, n * sizeof oldbuckets[0]);
#endif
(*ht->allocOps->freeTable)(ht->allocPriv, oldbuckets);
hep = PL_HashTableRawLookup(ht, keyHash, key);
}
/* Make a new key value entry */
he = (*ht->allocOps->allocEntry)(ht->allocPriv, key);
if (!he)
return 0;
he->keyHash = keyHash;
he->key = key;
he->value = value;
he->next = *hep;
*hep = he;
ht->nentries++;
return he;
}
PR_IMPLEMENT(PLHashEntry *)
PL_HashTableAdd(PLHashTable *ht, const void *key, void *value)
{
PLHashNumber keyHash;
PLHashEntry *he, **hep;
keyHash = (*ht->keyHash)(key);
hep = PL_HashTableRawLookup(ht, keyHash, key);
if ((he = *hep) != 0) {
/* Hit; see if values match */
if ((*ht->valueCompare)(he->value, value)) {
/* key,value pair is already present in table */
return he;
}
if (he->value)
(*ht->allocOps->freeEntry)(ht->allocPriv, he, HT_FREE_VALUE);
he->value = value;
return he;
}
return PL_HashTableRawAdd(ht, hep, keyHash, key, value);
}
PR_IMPLEMENT(void)
PL_HashTableRawRemove(PLHashTable *ht, PLHashEntry **hep, PLHashEntry *he)
{
PRUint32 i, n;
PLHashEntry *next, **oldbuckets;
PRUint32 nb;
*hep = he->next;
(*ht->allocOps->freeEntry)(ht->allocPriv, he, HT_FREE_ENTRY);
/* Shrink table if it's underloaded */
n = NBUCKETS(ht);
if (--ht->nentries < UNDERLOADED(n)) {
#ifdef HASHMETER
ht->nshrinks++;
#endif
ht->shift++;
oldbuckets = ht->buckets;
nb = n * sizeof(PLHashEntry*) / 2;
ht->buckets = (PLHashEntry**)(
(*ht->allocOps->allocTable)(ht->allocPriv, nb));
if (!ht->buckets) {
ht->buckets = oldbuckets;
return;
}
memset(ht->buckets, 0, nb);
for (i = 0; i < n; i++) {
for (he = oldbuckets[i]; he; he = next) {
next = he->next;
hep = PL_HashTableRawLookup(ht, he->keyHash, he->key);
PR_ASSERT(*hep == 0);
he->next = 0;
*hep = he;
}
}
#ifdef DEBUG
memset(oldbuckets, 0xDB, n * sizeof oldbuckets[0]);
#endif
(*ht->allocOps->freeTable)(ht->allocPriv, oldbuckets);
}
}
PR_IMPLEMENT(PRBool)
PL_HashTableRemove(PLHashTable *ht, const void *key)
{
PLHashNumber keyHash;
PLHashEntry *he, **hep;
keyHash = (*ht->keyHash)(key);
hep = PL_HashTableRawLookup(ht, keyHash, key);
if ((he = *hep) == 0)
return PR_FALSE;
/* Hit; remove element */
PL_HashTableRawRemove(ht, hep, he);
return PR_TRUE;
}
PR_IMPLEMENT(void *)
PL_HashTableLookup(PLHashTable *ht, const void *key)
{
PLHashNumber keyHash;
PLHashEntry *he, **hep;
keyHash = (*ht->keyHash)(key);
hep = PL_HashTableRawLookup(ht, keyHash, key);
if ((he = *hep) != 0) {
return he->value;
}
return 0;
}
/*
** Iterate over the entries in the hash table calling func for each
** entry found. Stop if "f" says to (return value & PR_ENUMERATE_STOP).
** Return a count of the number of elements scanned.
*/
PR_IMPLEMENT(int)
PL_HashTableEnumerateEntries(PLHashTable *ht, PLHashEnumerator f, void *arg)
{
PLHashEntry *he, **hep;
PRUint32 i, nbuckets;
int rv, n = 0;
PLHashEntry *todo = 0;
nbuckets = NBUCKETS(ht);
for (i = 0; i < nbuckets; i++) {
hep = &ht->buckets[i];
while ((he = *hep) != 0) {
rv = (*f)(he, n, arg);
n++;
if (rv & (HT_ENUMERATE_REMOVE | HT_ENUMERATE_UNHASH)) {
*hep = he->next;
if (rv & HT_ENUMERATE_REMOVE) {
he->next = todo;
todo = he;
}
} else {
hep = &he->next;
}
if (rv & HT_ENUMERATE_STOP) {
goto out;
}
}
}
out:
hep = &todo;
while ((he = *hep) != 0) {
PL_HashTableRawRemove(ht, hep, he);
}
return n;
}
#ifdef HASHMETER
#include <math.h>
#include <stdio.h>
PR_IMPLEMENT(void)
PL_HashTableDumpMeter(PLHashTable *ht, PLHashEnumerator dump, FILE *fp)
{
double mean, variance;
PRUint32 nchains, nbuckets;
PRUint32 i, n, maxChain, maxChainLen;
PLHashEntry *he;
variance = 0;
nchains = 0;
maxChainLen = 0;
nbuckets = NBUCKETS(ht);
for (i = 0; i < nbuckets; i++) {
he = ht->buckets[i];
if (!he)
continue;
nchains++;
for (n = 0; he; he = he->next)
n++;
variance += n * n;
if (n > maxChainLen) {
maxChainLen = n;
maxChain = i;
}
}
mean = (double)ht->nentries / nchains;
variance = fabs(variance / nchains - mean * mean);
fprintf(fp, "\nHash table statistics:\n");
fprintf(fp, " number of lookups: %u\n", ht->nlookups);
fprintf(fp, " number of entries: %u\n", ht->nentries);
fprintf(fp, " number of grows: %u\n", ht->ngrows);
fprintf(fp, " number of shrinks: %u\n", ht->nshrinks);
fprintf(fp, " mean steps per hash: %g\n", (double)ht->nsteps
/ ht->nlookups);
fprintf(fp, "mean hash chain length: %g\n", mean);
fprintf(fp, " standard deviation: %g\n", sqrt(variance));
fprintf(fp, " max hash chain length: %u\n", maxChainLen);
fprintf(fp, " max hash chain: [%u]\n", maxChain);
for (he = ht->buckets[maxChain], i = 0; he; he = he->next, i++)
if ((*dump)(he, i, fp) != HT_ENUMERATE_NEXT)
break;
}
#endif /* HASHMETER */
PR_IMPLEMENT(int)
PL_HashTableDump(PLHashTable *ht, PLHashEnumerator dump, FILE *fp)
{
int count;
count = PL_HashTableEnumerateEntries(ht, dump, fp);
#ifdef HASHMETER
PL_HashTableDumpMeter(ht, dump, fp);
#endif
return count;
}
PR_IMPLEMENT(PLHashNumber)
PL_HashString(const void *key)
{
PLHashNumber h;
const PRUint8 *s;
h = 0;
for (s = (const PRUint8*)key; *s; s++)
h = (h >> 28) ^ (h << 4) ^ *s;
return h;
}
PR_IMPLEMENT(int)
PL_CompareStrings(const void *v1, const void *v2)
{
return strcmp((const char*)v1, (const char*)v2) == 0;
}
PR_IMPLEMENT(int)
PL_CompareValues(const void *v1, const void *v2)
{
return v1 == v2;
}

131
js/src/mininspr/plhash.h Normal file
Просмотреть файл

@ -0,0 +1,131 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef plhash_h___
#define plhash_h___
/*
* API to portable hash table code.
*/
#include <stddef.h>
#include <stdio.h>
#include "prtypes.h"
PR_BEGIN_EXTERN_C
typedef struct PLHashEntry PLHashEntry;
typedef struct PLHashTable PLHashTable;
typedef PRUint32 PLHashNumber;
#define PL_HASH_BITS 32
typedef PLHashNumber (PR_CALLBACK *PLHashFunction)(const void *key);
typedef PRIntn (PR_CALLBACK *PLHashComparator)(const void *v1, const void *v2);
typedef PRIntn (PR_CALLBACK *PLHashEnumerator)(PLHashEntry *he, PRIntn i, void *arg);
/* Flag bits in PLHashEnumerator's return value */
#define HT_ENUMERATE_NEXT 0 /* continue enumerating entries */
#define HT_ENUMERATE_STOP 1 /* stop enumerating entries */
#define HT_ENUMERATE_REMOVE 2 /* remove and free the current entry */
#define HT_ENUMERATE_UNHASH 4 /* just unhash the current entry */
typedef struct PLHashAllocOps {
void * (PR_CALLBACK *allocTable)(void *pool, PRSize size);
void (PR_CALLBACK *freeTable)(void *pool, void *item);
PLHashEntry * (PR_CALLBACK *allocEntry)(void *pool, const void *key);
void (PR_CALLBACK *freeEntry)(void *pool, PLHashEntry *he, PRUintn flag);
} PLHashAllocOps;
#define HT_FREE_VALUE 0 /* just free the entry's value */
#define HT_FREE_ENTRY 1 /* free value and entire entry */
struct PLHashEntry {
PLHashEntry *next; /* hash chain linkage */
PLHashNumber keyHash; /* key hash function result */
const void *key; /* ptr to opaque key */
void *value; /* ptr to opaque value */
};
struct PLHashTable {
PLHashEntry **buckets; /* vector of hash buckets */
PRUint32 nentries; /* number of entries in table */
PRUint32 shift; /* multiplicative hash shift */
PLHashFunction keyHash; /* key hash function */
PLHashComparator keyCompare; /* key comparison function */
PLHashComparator valueCompare; /* value comparison function */
PLHashAllocOps *allocOps; /* allocation operations */
void *allocPriv; /* allocation private data */
#ifdef HASHMETER
PRUint32 nlookups; /* total number of lookups */
PRUint32 nsteps; /* number of hash chains traversed */
PRUint32 ngrows; /* number of table expansions */
PRUint32 nshrinks; /* number of table contractions */
#endif
};
/*
* Create a new hash table.
* If allocOps is null, use default allocator ops built on top of malloc().
*/
PR_EXTERN(PLHashTable *)
PL_NewHashTable(PRUint32 n, PLHashFunction keyHash,
PLHashComparator keyCompare, PLHashComparator valueCompare,
PLHashAllocOps *allocOps, void *allocPriv);
PR_EXTERN(void)
PL_HashTableDestroy(PLHashTable *ht);
/* Low level access methods */
PR_EXTERN(PLHashEntry **)
PL_HashTableRawLookup(PLHashTable *ht, PLHashNumber keyHash, const void *key);
PR_EXTERN(PLHashEntry *)
PL_HashTableRawAdd(PLHashTable *ht, PLHashEntry **hep, PLHashNumber keyHash,
const void *key, void *value);
PR_EXTERN(void)
PL_HashTableRawRemove(PLHashTable *ht, PLHashEntry **hep, PLHashEntry *he);
/* Higher level access methods */
PR_EXTERN(PLHashEntry *)
PL_HashTableAdd(PLHashTable *ht, const void *key, void *value);
PR_EXTERN(PRBool)
PL_HashTableRemove(PLHashTable *ht, const void *key);
PR_EXTERN(PRIntn)
PL_HashTableEnumerateEntries(PLHashTable *ht, PLHashEnumerator f, void *arg);
PR_EXTERN(void *)
PL_HashTableLookup(PLHashTable *ht, const void *key);
PR_EXTERN(PRIntn)
PL_HashTableDump(PLHashTable *ht, PLHashEnumerator dump, FILE *fp);
/* General-purpose C string hash function. */
PR_EXTERN(PLHashNumber)
PL_HashString(const void *key);
/* Compare strings using strcmp(), return true if equal. */
PR_EXTERN(int)
PL_CompareStrings(const void *v1, const void *v2);
/* Stub function just returns v1 == v2 */
PR_EXTERN(PRIntn)
PL_CompareValues(const void *v1, const void *v2);
PR_END_EXTERN_C
#endif /* plhash_h___ */

92
js/src/mininspr/prbit.h Normal file
Просмотреть файл

@ -0,0 +1,92 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef prbit_h___
#define prbit_h___
#include "prtypes.h"
PR_BEGIN_EXTERN_C
/*
** A prbitmap_t is a long integer that can be used for bitmaps
*/
typedef unsigned long prbitmap_t;
#define PR_TEST_BIT(_map,_bit) \
((_map)[(_bit)>>PR_BITS_PER_LONG_LOG2] & (1L << ((_bit) & (PR_BITS_PER_LONG-1))))
#define PR_SET_BIT(_map,_bit) \
((_map)[(_bit)>>PR_BITS_PER_LONG_LOG2] |= (1L << ((_bit) & (PR_BITS_PER_LONG-1))))
#define PR_CLEAR_BIT(_map,_bit) \
((_map)[(_bit)>>PR_BITS_PER_LONG_LOG2] &= ~(1L << ((_bit) & (PR_BITS_PER_LONG-1))))
/*
** Compute the log of the least power of 2 greater than or equal to n
*/
PR_EXTERN(PRIntn) PR_CeilingLog2(PRUint32 i);
/*
** Compute the log of the greatest power of 2 less than or equal to n
*/
PR_EXTERN(PRIntn) PR_FloorLog2(PRUint32 i);
/*
** Macro version of PR_CeilingLog2: Compute the log of the least power of
** 2 greater than or equal to _n. The result is returned in _log2.
*/
#define PR_CEILING_LOG2(_log2,_n) \
PR_BEGIN_MACRO \
PRUint32 j_ = (PRUint32)(_n); \
(_log2) = 0; \
if ((j_) & ((j_)-1)) \
(_log2) += 1; \
if ((j_) >> 16) \
(_log2) += 16, (j_) >>= 16; \
if ((j_) >> 8) \
(_log2) += 8, (j_) >>= 8; \
if ((j_) >> 4) \
(_log2) += 4, (j_) >>= 4; \
if ((j_) >> 2) \
(_log2) += 2, (j_) >>= 2; \
if ((j_) >> 1) \
(_log2) += 1; \
PR_END_MACRO
/*
** Macro version of PR_FloorLog2: Compute the log of the greatest power of
** 2 less than or equal to _n. The result is returned in _log2.
**
** This is equivalent to finding the highest set bit in the word.
*/
#define PR_FLOOR_LOG2(_log2,_n) \
PR_BEGIN_MACRO \
PRUint32 j_ = (PRUint32)(_n); \
(_log2) = 0; \
if ((j_) >> 16) \
(_log2) += 16, (j_) >>= 16; \
if ((j_) >> 8) \
(_log2) += 8, (j_) >>= 8; \
if ((j_) >> 4) \
(_log2) += 4, (j_) >>= 4; \
if ((j_) >> 2) \
(_log2) += 2, (j_) >>= 2; \
if ((j_) >> 1) \
(_log2) += 1; \
PR_END_MACRO
PR_END_EXTERN_C
#endif /* prbit_h___ */

121
js/src/mininspr/prclist.h Normal file
Просмотреть файл

@ -0,0 +1,121 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef prclist_h___
#define prclist_h___
#include "prtypes.h"
typedef struct PRCListStr PRCList;
/*
** Circular linked list
*/
struct PRCListStr {
PRCList *next;
PRCList *prev;
};
/*
** Insert element "_e" into the list, before "_l".
*/
#define PR_INSERT_BEFORE(_e,_l) \
PR_BEGIN_MACRO \
(_e)->next = (_l); \
(_e)->prev = (_l)->prev; \
(_l)->prev->next = (_e); \
(_l)->prev = (_e); \
PR_END_MACRO
/*
** Insert element "_e" into the list, after "_l".
*/
#define PR_INSERT_AFTER(_e,_l) \
PR_BEGIN_MACRO \
(_e)->next = (_l)->next; \
(_e)->prev = (_l); \
(_l)->next->prev = (_e); \
(_l)->next = (_e); \
PR_END_MACRO
/*
** Return the element following element "_e"
*/
#define PR_NEXT_LINK(_e) \
((_e)->next)
/*
** Return the element preceding element "_e"
*/
#define PR_PREV_LINK(_e) \
((_e)->prev)
/*
** Append an element "_e" to the end of the list "_l"
*/
#define PR_APPEND_LINK(_e,_l) PR_INSERT_BEFORE(_e,_l)
/*
** Insert an element "_e" at the head of the list "_l"
*/
#define PR_INSERT_LINK(_e,_l) PR_INSERT_AFTER(_e,_l)
/* Return the head/tail of the list */
#define PR_LIST_HEAD(_l) (_l)->next
#define PR_LIST_TAIL(_l) (_l)->prev
/*
** Remove the element "_e" from it's circular list.
*/
#define PR_REMOVE_LINK(_e) \
PR_BEGIN_MACRO \
(_e)->prev->next = (_e)->next; \
(_e)->next->prev = (_e)->prev; \
PR_END_MACRO
/*
** Remove the element "_e" from it's circular list. Also initializes the
** linkage.
*/
#define PR_REMOVE_AND_INIT_LINK(_e) \
PR_BEGIN_MACRO \
(_e)->prev->next = (_e)->next; \
(_e)->next->prev = (_e)->prev; \
(_e)->next = (_e); \
(_e)->prev = (_e); \
PR_END_MACRO
/*
** Return non-zero if the given circular list "_l" is empty, zero if the
** circular list is not empty
*/
#define PR_CLIST_IS_EMPTY(_l) \
((_l)->next == (_l))
/*
** Initialize a circular list
*/
#define PR_INIT_CLIST(_l) \
PR_BEGIN_MACRO \
(_l)->next = (_l); \
(_l)->prev = (_l); \
PR_END_MACRO
#define PR_INIT_STATIC_CLIST(_l) \
{(_l), (_l)}
#endif /* prclist_h___ */

699
js/src/mininspr/prcpucfg.h Normal file
Просмотреть файл

@ -0,0 +1,699 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nspr_cpucfg___
#define nspr_cpucfg___
#ifdef XP_MAC
#undef IS_LITTLE_ENDIAN
#define IS_BIG_ENDIAN 1
#define PR_BYTES_PER_BYTE 1L
#define PR_BYTES_PER_SHORT 2L
#define PR_BYTES_PER_INT 4L
#define PR_BYTES_PER_INT64 8L
#define PR_BYTES_PER_LONG 4L
#define PR_BYTES_PER_FLOAT 4L
#define PR_BYTES_PER_DOUBLE 8L
#define PR_BYTES_PER_WORD 4L
#define PR_BYTES_PER_DWORD 8L
#define PR_BITS_PER_BYTE 8L
#define PR_BITS_PER_SHORT 16L
#define PR_BITS_PER_INT 32L
#define PR_BITS_PER_INT64 64L
#define PR_BITS_PER_LONG 32L
#define PR_BITS_PER_FLOAT 32L
#define PR_BITS_PER_DOUBLE 64L
#define PR_BITS_PER_WORD 32L
#define PR_BITS_PER_BYTE_LOG2 3L
#define PR_BITS_PER_SHORT_LOG2 4L
#define PR_BITS_PER_INT_LOG2 5L
#define PR_BITS_PER_INT64_LOG2 6L
#define PR_BITS_PER_LONG_LOG2 5L
#define PR_BITS_PER_FLOAT_LOG2 5L
#define PR_BITS_PER_DOUBLE_LOG2 6L
#define PR_BITS_PER_WORD_LOG2 5L
#define PR_ALIGN_OF_SHORT 2L
#define PR_ALIGN_OF_INT 4L
#define PR_ALIGN_OF_LONG 4L
#define PR_ALIGN_OF_INT64 2L
#define PR_ALIGN_OF_FLOAT 4L
#define PR_ALIGN_OF_DOUBLE 4L
#define PR_ALIGN_OF_POINTER 4L
#define PR_ALIGN_OF_WORD 4L
#define PR_BYTES_PER_WORD_LOG2 2L
#define PR_BYTES_PER_DWORD_LOG2 3L
#define PR_WORDS_PER_DWORD_LOG2 1L
#endif /* XP_MAC */
#ifdef _WIN32
#define IS_LITTLE_ENDIAN 1
#undef IS_BIG_ENDIAN
#define PR_BYTES_PER_BYTE 1L
#define PR_BYTES_PER_SHORT 2L
#define PR_BYTES_PER_INT 4L
#define PR_BYTES_PER_INT64 8L
#define PR_BYTES_PER_LONG 4L
#define PR_BYTES_PER_FLOAT 4L
#define PR_BYTES_PER_DOUBLE 8L
#define PR_BYTES_PER_WORD 4L
#define PR_BYTES_PER_DWORD 8L
#define PR_BITS_PER_BYTE 8L
#define PR_BITS_PER_SHORT 16L
#define PR_BITS_PER_INT 32L
#define PR_BITS_PER_INT64 64L
#define PR_BITS_PER_LONG 32L
#define PR_BITS_PER_FLOAT 32L
#define PR_BITS_PER_DOUBLE 64L
#define PR_BITS_PER_WORD 32L
#define PR_BITS_PER_BYTE_LOG2 3L
#define PR_BITS_PER_SHORT_LOG2 4L
#define PR_BITS_PER_INT_LOG2 5L
#define PR_BITS_PER_INT64_LOG2 6L
#define PR_BITS_PER_LONG_LOG2 5L
#define PR_BITS_PER_FLOAT_LOG2 5L
#define PR_BITS_PER_DOUBLE_LOG2 6L
#define PR_BITS_PER_WORD_LOG2 5L
#define PR_ALIGN_OF_SHORT 2L
#define PR_ALIGN_OF_INT 4L
#define PR_ALIGN_OF_LONG 4L
#define PR_ALIGN_OF_INT64 8L
#define PR_ALIGN_OF_FLOAT 4L
#define PR_ALIGN_OF_DOUBLE 4L
#define PR_ALIGN_OF_POINTER 4L
#define PR_ALIGN_OF_WORD 4L
#define PR_BYTES_PER_WORD_LOG2 2L
#define PR_BYTES_PER_DWORD_LOG2 3L
#define PR_WORDS_PER_DWORD_LOG2 1L
#endif /* _WIN32 */
#if defined(_WINDOWS) && !defined(_WIN32) /* WIN16 */
#define IS_LITTLE_ENDIAN 1
#undef IS_BIG_ENDIAN
#define PR_BYTES_PER_BYTE 1L
#define PR_BYTES_PER_SHORT 2L
#define PR_BYTES_PER_INT 2L
#define PR_BYTES_PER_INT64 8L
#define PR_BYTES_PER_LONG 4L
#define PR_BYTES_PER_FLOAT 4L
#define PR_BYTES_PER_DOUBLE 8L
#define PR_BYTES_PER_WORD 4L
#define PR_BYTES_PER_DWORD 8L
#define PR_BITS_PER_BYTE 8L
#define PR_BITS_PER_SHORT 16L
#define PR_BITS_PER_INT 16L
#define PR_BITS_PER_INT64 64L
#define PR_BITS_PER_LONG 32L
#define PR_BITS_PER_FLOAT 32L
#define PR_BITS_PER_DOUBLE 64L
#define PR_BITS_PER_WORD 32L
#define PR_BITS_PER_BYTE_LOG2 3L
#define PR_BITS_PER_SHORT_LOG2 4L
#define PR_BITS_PER_INT_LOG2 4L
#define PR_BITS_PER_INT64_LOG2 6L
#define PR_BITS_PER_LONG_LOG2 5L
#define PR_BITS_PER_FLOAT_LOG2 5L
#define PR_BITS_PER_DOUBLE_LOG2 6L
#define PR_BITS_PER_WORD_LOG2 5L
#define PR_ALIGN_OF_SHORT 2L
#define PR_ALIGN_OF_INT 2L
#define PR_ALIGN_OF_LONG 2L
#define PR_ALIGN_OF_INT64 2L
#define PR_ALIGN_OF_FLOAT 2L
#define PR_ALIGN_OF_DOUBLE 2L
#define PR_ALIGN_OF_POINTER 2L
#define PR_ALIGN_OF_WORD 2L
#define PR_BYTES_PER_WORD_LOG2 2L
#define PR_BYTES_PER_DWORD_LOG2 3L
#define PR_WORDS_PER_DWORD_LOG2 1L
#endif /* defined(_WINDOWS) && !defined(_WIN32) */
#ifdef XP_UNIX
#if defined(AIXV3)
#undef IS_LITTLE_ENDIAN
#define IS_BIG_ENDIAN 1
#define PR_BYTES_PER_BYTE 1L
#define PR_BYTES_PER_SHORT 2L
#define PR_BYTES_PER_INT 4L
#define PR_BYTES_PER_INT64 8L
#define PR_BYTES_PER_LONG 4L
#define PR_BYTES_PER_FLOAT 4L
#define PR_BYTES_PER_DOUBLE 8L
#define PR_BYTES_PER_WORD 4L
#define PR_BYTES_PER_DWORD 8L
#define PR_BITS_PER_BYTE 8L
#define PR_BITS_PER_SHORT 16L
#define PR_BITS_PER_INT 32L
#define PR_BITS_PER_INT64 64L
#define PR_BITS_PER_LONG 32L
#define PR_BITS_PER_FLOAT 32L
#define PR_BITS_PER_DOUBLE 64L
#define PR_BITS_PER_WORD 32L
#define PR_BITS_PER_BYTE_LOG2 3L
#define PR_BITS_PER_SHORT_LOG2 4L
#define PR_BITS_PER_INT_LOG2 5L
#define PR_BITS_PER_INT64_LOG2 6L
#define PR_BITS_PER_LONG_LOG2 5L
#define PR_BITS_PER_FLOAT_LOG2 5L
#define PR_BITS_PER_DOUBLE_LOG2 6L
#define PR_BITS_PER_WORD_LOG2 5L
#define PR_ALIGN_OF_SHORT 2L
#define PR_ALIGN_OF_INT 4L
#define PR_ALIGN_OF_LONG 4L
#define PR_ALIGN_OF_INT64 8L
#define PR_ALIGN_OF_FLOAT 4L
#define PR_ALIGN_OF_DOUBLE 4L
#define PR_ALIGN_OF_POINTER 4L
#define PR_ALIGN_OF_WORD 4L
#define PR_BYTES_PER_WORD_LOG2 2L
#define PR_BYTES_PER_DWORD_LOG2 3L
#define PR_WORDS_PER_DWORD_LOG2 1L
#elif defined(BSDI)
#define IS_LITTLE_ENDIAN 1
#undef IS_BIG_ENDIAN
#define PR_BYTES_PER_BYTE 1L
#define PR_BYTES_PER_SHORT 2L
#define PR_BYTES_PER_INT 4L
#define PR_BYTES_PER_INT64 8L
#define PR_BYTES_PER_LONG 4L
#define PR_BYTES_PER_FLOAT 4L
#define PR_BYTES_PER_DOUBLE 8L
#define PR_BYTES_PER_WORD 4L
#define PR_BYTES_PER_DWORD 8L
#define PR_BITS_PER_BYTE 8L
#define PR_BITS_PER_SHORT 16L
#define PR_BITS_PER_INT 32L
#define PR_BITS_PER_INT64 64L
#define PR_BITS_PER_LONG 32L
#define PR_BITS_PER_FLOAT 32L
#define PR_BITS_PER_DOUBLE 64L
#define PR_BITS_PER_WORD 32L
#define PR_BITS_PER_BYTE_LOG2 3L
#define PR_BITS_PER_SHORT_LOG2 4L
#define PR_BITS_PER_INT_LOG2 5L
#define PR_BITS_PER_INT64_LOG2 6L
#define PR_BITS_PER_LONG_LOG2 5L
#define PR_BITS_PER_FLOAT_LOG2 5L
#define PR_BITS_PER_DOUBLE_LOG2 6L
#define PR_BITS_PER_WORD_LOG2 5L
#define PR_ALIGN_OF_SHORT 2L
#define PR_ALIGN_OF_INT 4L
#define PR_ALIGN_OF_LONG 4L
#define PR_ALIGN_OF_INT64 4L
#define PR_ALIGN_OF_FLOAT 4L
#define PR_ALIGN_OF_DOUBLE 4L
#define PR_ALIGN_OF_POINTER 4L
#define PR_ALIGN_OF_WORD 4L
#define PR_BYTES_PER_WORD_LOG2 2L
#define PR_BYTES_PER_DWORD_LOG2 3L
#define PR_WORDS_PER_DWORD_LOG2 1L
#elif defined(HPUX)
#undef IS_LITTLE_ENDIAN
#define IS_BIG_ENDIAN 1
#define PR_BYTES_PER_BYTE 1L
#define PR_BYTES_PER_SHORT 2L
#define PR_BYTES_PER_INT 4L
#define PR_BYTES_PER_INT64 8L
#define PR_BYTES_PER_LONG 4L
#define PR_BYTES_PER_FLOAT 4L
#define PR_BYTES_PER_DOUBLE 8L
#define PR_BYTES_PER_WORD 4L
#define PR_BYTES_PER_DWORD 8L
#define PR_BITS_PER_BYTE 8L
#define PR_BITS_PER_SHORT 16L
#define PR_BITS_PER_INT 32L
#define PR_BITS_PER_INT64 64L
#define PR_BITS_PER_LONG 32L
#define PR_BITS_PER_FLOAT 32L
#define PR_BITS_PER_DOUBLE 64L
#define PR_BITS_PER_WORD 32L
#define PR_BITS_PER_BYTE_LOG2 3L
#define PR_BITS_PER_SHORT_LOG2 4L
#define PR_BITS_PER_INT_LOG2 5L
#define PR_BITS_PER_INT64_LOG2 6L
#define PR_BITS_PER_LONG_LOG2 5L
#define PR_BITS_PER_FLOAT_LOG2 5L
#define PR_BITS_PER_DOUBLE_LOG2 6L
#define PR_BITS_PER_WORD_LOG2 5L
#define PR_ALIGN_OF_SHORT 2L
#define PR_ALIGN_OF_INT 4L
#define PR_ALIGN_OF_LONG 4L
#define PR_ALIGN_OF_INT64 4L
#define PR_ALIGN_OF_FLOAT 4L
#define PR_ALIGN_OF_DOUBLE 8L
#define PR_ALIGN_OF_POINTER 4L
#define PR_ALIGN_OF_WORD 4L
#define PR_BYTES_PER_WORD_LOG2 2L
#define PR_BYTES_PER_DWORD_LOG2 3L
#define PR_WORDS_PER_DWORD_LOG2 1L
#elif defined(IRIX)
#undef IS_LITTLE_ENDIAN
#define IS_BIG_ENDIAN 1
#define PR_BYTES_PER_BYTE 1L
#define PR_BYTES_PER_SHORT 2L
#define PR_BYTES_PER_INT 4L
#define PR_BYTES_PER_INT64 8L
#define PR_BYTES_PER_LONG 4L
#define PR_BYTES_PER_FLOAT 4L
#define PR_BYTES_PER_DOUBLE 8L
#define PR_BYTES_PER_WORD 4L
#define PR_BYTES_PER_DWORD 8L
#define PR_BITS_PER_BYTE 8L
#define PR_BITS_PER_SHORT 16L
#define PR_BITS_PER_INT 32L
#define PR_BITS_PER_INT64 64L
#define PR_BITS_PER_LONG 32L
#define PR_BITS_PER_FLOAT 32L
#define PR_BITS_PER_DOUBLE 64L
#define PR_BITS_PER_WORD 32L
#define PR_BITS_PER_BYTE_LOG2 3L
#define PR_BITS_PER_SHORT_LOG2 4L
#define PR_BITS_PER_INT_LOG2 5L
#define PR_BITS_PER_INT64_LOG2 6L
#define PR_BITS_PER_LONG_LOG2 5L
#define PR_BITS_PER_FLOAT_LOG2 5L
#define PR_BITS_PER_DOUBLE_LOG2 6L
#define PR_BITS_PER_WORD_LOG2 5L
#define PR_ALIGN_OF_SHORT 2L
#define PR_ALIGN_OF_INT 4L
#define PR_ALIGN_OF_LONG 4L
#define PR_ALIGN_OF_INT64 8L
#define PR_ALIGN_OF_FLOAT 4L
#define PR_ALIGN_OF_DOUBLE 8L
#define PR_ALIGN_OF_POINTER 4L
#define PR_ALIGN_OF_WORD 4L
#define PR_BYTES_PER_WORD_LOG2 2L
#define PR_BYTES_PER_DWORD_LOG2 3L
#define PR_WORDS_PER_DWORD_LOG2 1L
#elif defined(LINUX)
#ifdef __powerpc__
#undef IS_LITTLE_ENDIAN
#define IS_BIG_ENDIAN 1
#elif __i386__
#define IS_LITTLE_ENDIAN 1
#undef IS_BIG_ENDIAN
#else
#error "linux cpu architecture not supported by prcpucfg.h"
#endif
#define PR_BYTES_PER_BYTE 1L
#define PR_BYTES_PER_SHORT 2L
#define PR_BYTES_PER_INT 4L
#define PR_BYTES_PER_INT64 8L
#define PR_BYTES_PER_LONG 4L
#define PR_BYTES_PER_FLOAT 4L
#define PR_BYTES_PER_DOUBLE 8L
#define PR_BYTES_PER_WORD 4L
#define PR_BYTES_PER_DWORD 8L
#define PR_BITS_PER_BYTE 8L
#define PR_BITS_PER_SHORT 16L
#define PR_BITS_PER_INT 32L
#define PR_BITS_PER_INT64 64L
#define PR_BITS_PER_LONG 32L
#define PR_BITS_PER_FLOAT 32L
#define PR_BITS_PER_DOUBLE 64L
#define PR_BITS_PER_WORD 32L
#define PR_BITS_PER_BYTE_LOG2 3L
#define PR_BITS_PER_SHORT_LOG2 4L
#define PR_BITS_PER_INT_LOG2 5L
#define PR_BITS_PER_INT64_LOG2 6L
#define PR_BITS_PER_LONG_LOG2 5L
#define PR_BITS_PER_FLOAT_LOG2 5L
#define PR_BITS_PER_DOUBLE_LOG2 6L
#define PR_BITS_PER_WORD_LOG2 5L
#define PR_ALIGN_OF_SHORT 2L
#define PR_ALIGN_OF_INT 4L
#define PR_ALIGN_OF_LONG 4L
#define PR_ALIGN_OF_INT64 4L
#define PR_ALIGN_OF_FLOAT 4L
#define PR_ALIGN_OF_DOUBLE 4L
#define PR_ALIGN_OF_POINTER 4L
#define PR_ALIGN_OF_WORD 4L
#define PR_BYTES_PER_WORD_LOG2 2L
#define PR_BYTES_PER_DWORD_LOG2 3L
#define PR_WORDS_PER_DWORD_LOG2 1L
#elif defined(OSF1)
#define IS_LITTLE_ENDIAN 1
#undef IS_BIG_ENDIAN
#define PR_BYTES_PER_BYTE 1L
#define PR_BYTES_PER_SHORT 2L
#define PR_BYTES_PER_INT 4L
#define PR_BYTES_PER_INT64 8L
#define PR_BYTES_PER_LONG 8L
#define PR_BYTES_PER_FLOAT 4L
#define PR_BYTES_PER_DOUBLE 8L
#define PR_BYTES_PER_WORD 8L
#define PR_BYTES_PER_DWORD 8L
#define PR_BITS_PER_BYTE 8L
#define PR_BITS_PER_SHORT 16L
#define PR_BITS_PER_INT 32L
#define PR_BITS_PER_INT64 64L
#define PR_BITS_PER_LONG 64L
#define PR_BITS_PER_FLOAT 32L
#define PR_BITS_PER_DOUBLE 64L
#define PR_BITS_PER_WORD 64L
#define PR_BITS_PER_BYTE_LOG2 3L
#define PR_BITS_PER_SHORT_LOG2 4L
#define PR_BITS_PER_INT_LOG2 5L
#define PR_BITS_PER_INT64_LOG2 6L
#define PR_BITS_PER_LONG_LOG2 6L
#define PR_BITS_PER_FLOAT_LOG2 5L
#define PR_BITS_PER_DOUBLE_LOG2 6L
#define PR_BITS_PER_WORD_LOG2 6L
#define PR_ALIGN_OF_SHORT 2L
#define PR_ALIGN_OF_INT 4L
#define PR_ALIGN_OF_LONG 8L
#define PR_ALIGN_OF_INT64 8L
#define PR_ALIGN_OF_FLOAT 4L
#define PR_ALIGN_OF_DOUBLE 8L
#define PR_ALIGN_OF_POINTER 8L
#define PR_ALIGN_OF_WORD 8L
#define PR_BYTES_PER_WORD_LOG2 3L
#define PR_BYTES_PER_DWORD_LOG2 3L
#define PR_WORDS_PER_DWORD_LOG2 0L
#elif defined(SOLARIS)
#ifdef i386
/* PC-based */
#undef IS_BIG_ENDIAN
#define IS_LITTLE_ENDIAN 1
#else
/* Sparc-based */
#undef IS_LITTLE_ENDIAN
#define IS_BIG_ENDIAN 1
#endif
#define PR_BYTES_PER_BYTE 1L
#define PR_BYTES_PER_SHORT 2L
#define PR_BYTES_PER_INT 4L
#define PR_BYTES_PER_INT64 8L
#define PR_BYTES_PER_LONG 4L
#define PR_BYTES_PER_FLOAT 4L
#define PR_BYTES_PER_DOUBLE 8L
#define PR_BYTES_PER_WORD 4L
#define PR_BYTES_PER_DWORD 8L
#define PR_BITS_PER_BYTE 8L
#define PR_BITS_PER_SHORT 16L
#define PR_BITS_PER_INT 32L
#define PR_BITS_PER_INT64 64L
#define PR_BITS_PER_LONG 32L
#define PR_BITS_PER_FLOAT 32L
#define PR_BITS_PER_DOUBLE 64L
#define PR_BITS_PER_WORD 32L
#define PR_BITS_PER_BYTE_LOG2 3L
#define PR_BITS_PER_SHORT_LOG2 4L
#define PR_BITS_PER_INT_LOG2 5L
#define PR_BITS_PER_INT64_LOG2 6L
#define PR_BITS_PER_LONG_LOG2 5L
#define PR_BITS_PER_FLOAT_LOG2 5L
#define PR_BITS_PER_DOUBLE_LOG2 6L
#define PR_BITS_PER_WORD_LOG2 5L
#define PR_ALIGN_OF_SHORT 2L
#define PR_ALIGN_OF_INT 4L
#define PR_ALIGN_OF_LONG 4L
#define PR_ALIGN_OF_INT64 8L
#define PR_ALIGN_OF_FLOAT 4L
#define PR_ALIGN_OF_DOUBLE 8L
#define PR_ALIGN_OF_POINTER 4L
#define PR_ALIGN_OF_WORD 4L
#ifdef i386
#undef PR_ALIGN_OF_INT64
#undef PR_ALIGN_OF_DOUBLE
#define PR_ALIGN_OF_INT64 4L
#define PR_ALIGN_OF_DOUBLE 4L
#endif
#define PR_BYTES_PER_WORD_LOG2 2L
#define PR_BYTES_PER_DWORD_LOG2 3L
#define PR_WORDS_PER_DWORD_LOG2 1L
#elif defined(SUNOS4)
#undef IS_LITTLE_ENDIAN
#define IS_BIG_ENDIAN 1
#define PR_BYTES_PER_BYTE 1L
#define PR_BYTES_PER_SHORT 2L
#define PR_BYTES_PER_INT 4L
#define PR_BYTES_PER_INT64 8L
#define PR_BYTES_PER_LONG 4L
#define PR_BYTES_PER_FLOAT 4L
#define PR_BYTES_PER_DOUBLE 8L
#define PR_BYTES_PER_WORD 4L
#define PR_BYTES_PER_DWORD 8L
#define PR_BITS_PER_BYTE 8L
#define PR_BITS_PER_SHORT 16L
#define PR_BITS_PER_INT 32L
#define PR_BITS_PER_INT64 64L
#define PR_BITS_PER_LONG 32L
#define PR_BITS_PER_FLOAT 32L
#define PR_BITS_PER_DOUBLE 64L
#define PR_BITS_PER_WORD 32L
#define PR_BITS_PER_BYTE_LOG2 3L
#define PR_BITS_PER_SHORT_LOG2 4L
#define PR_BITS_PER_INT_LOG2 5L
#define PR_BITS_PER_INT64_LOG2 6L
#define PR_BITS_PER_LONG_LOG2 5L
#define PR_BITS_PER_FLOAT_LOG2 5L
#define PR_BITS_PER_DOUBLE_LOG2 6L
#define PR_BITS_PER_WORD_LOG2 5L
#define PR_ALIGN_OF_SHORT 2L
#define PR_ALIGN_OF_INT 4L
#define PR_ALIGN_OF_LONG 4L
#define PR_ALIGN_OF_INT64 8L
#define PR_ALIGN_OF_FLOAT 4L
#define PR_ALIGN_OF_DOUBLE 8L
#define PR_ALIGN_OF_POINTER 4L
#define PR_ALIGN_OF_WORD 4L
#define PR_BYTES_PER_WORD_LOG2 2L
#define PR_BYTES_PER_DWORD_LOG2 3L
#define PR_WORDS_PER_DWORD_LOG2 1L
#elif defined(SNI)
#undef IS_LITTLE_ENDIAN
#define IS_BIG_ENDIAN 1
#define PR_BYTES_PER_BYTE 1L
#define PR_BYTES_PER_SHORT 2L
#define PR_BYTES_PER_INT 4L
#define PR_BYTES_PER_INT64 8L
#define PR_BYTES_PER_LONG 4L
#define PR_BYTES_PER_FLOAT 4L
#define PR_BYTES_PER_DOUBLE 8L
#define PR_BYTES_PER_WORD 4L
#define PR_BYTES_PER_DWORD 8L
#define PR_BITS_PER_BYTE 8L
#define PR_BITS_PER_SHORT 16L
#define PR_BITS_PER_INT 32L
#define PR_BITS_PER_INT64 64L
#define PR_BITS_PER_LONG 32L
#define PR_BITS_PER_FLOAT 32L
#define PR_BITS_PER_DOUBLE 64L
#define PR_BITS_PER_WORD 32L
#define PR_BITS_PER_BYTE_LOG2 3L
#define PR_BITS_PER_SHORT_LOG2 4L
#define PR_BITS_PER_INT_LOG2 5L
#define PR_BITS_PER_INT64_LOG2 6L
#define PR_BITS_PER_LONG_LOG2 5L
#define PR_BITS_PER_FLOAT_LOG2 5L
#define PR_BITS_PER_DOUBLE_LOG2 6L
#define PR_BITS_PER_WORD_LOG2 5L
#define PR_ALIGN_OF_SHORT 2L
#define PR_ALIGN_OF_INT 4L
#define PR_ALIGN_OF_LONG 4L
#define PR_ALIGN_OF_INT64 8L
#define PR_ALIGN_OF_FLOAT 4L
#define PR_ALIGN_OF_DOUBLE 8L
#define PR_ALIGN_OF_POINTER 4L
#define PR_ALIGN_OF_WORD 4L
#define PR_BYTES_PER_WORD_LOG2 2L
#define PR_BYTES_PER_DWORD_LOG2 3L
#define PR_WORDS_PER_DWORD_LOG2 1L
#elif defined(SONY)
/* Don't have it */
#elif defined(NECSVR4)
/* Don't have it */
#elif defined(SCO)
#define IS_LITTLE_ENDIAN 1
#undef IS_BIG_ENDIAN
#define PR_BYTES_PER_BYTE 1L
#define PR_BYTES_PER_SHORT 2L
#define PR_BYTES_PER_INT 4L
#define PR_BYTES_PER_INT64 8L
#define PR_BYTES_PER_LONG 4L
#define PR_BYTES_PER_FLOAT 4L
#define PR_BYTES_PER_DOUBLE 8L
#define PR_BYTES_PER_WORD 4L
#define PR_BYTES_PER_DWORD 8L
#define PR_BITS_PER_BYTE 8L
#define PR_BITS_PER_SHORT 16L
#define PR_BITS_PER_INT 32L
#define PR_BITS_PER_INT64 64L
#define PR_BITS_PER_LONG 32L
#define PR_BITS_PER_FLOAT 32L
#define PR_BITS_PER_DOUBLE 64L
#define PR_BITS_PER_WORD 32L
#define PR_BITS_PER_BYTE_LOG2 3L
#define PR_BITS_PER_SHORT_LOG2 4L
#define PR_BITS_PER_INT_LOG2 5L
#define PR_BITS_PER_INT64_LOG2 6L
#define PR_BITS_PER_LONG_LOG2 5L
#define PR_BITS_PER_FLOAT_LOG2 5L
#define PR_BITS_PER_DOUBLE_LOG2 6L
#define PR_BITS_PER_WORD_LOG2 5L
#define PR_ALIGN_OF_SHORT 2L
#define PR_ALIGN_OF_INT 4L
#define PR_ALIGN_OF_LONG 4L
#define PR_ALIGN_OF_INT64 4L
#define PR_ALIGN_OF_FLOAT 4L
#define PR_ALIGN_OF_DOUBLE 4L
#define PR_ALIGN_OF_POINTER 4L
#define PR_ALIGN_OF_WORD 4L
#define PR_BYTES_PER_WORD_LOG2 2L
#define PR_BYTES_PER_DWORD_LOG2 3L
#define PR_WORDS_PER_DWORD_LOG2 1L
#elif defined(UNIXWARE)
#define IS_LITTLE_ENDIAN 1
#undef IS_BIG_ENDIAN
#define PR_BYTES_PER_BYTE 1L
#define PR_BYTES_PER_SHORT 2L
#define PR_BYTES_PER_INT 4L
#define PR_BYTES_PER_INT64 8L
#define PR_BYTES_PER_LONG 4L
#define PR_BYTES_PER_FLOAT 4L
#define PR_BYTES_PER_DOUBLE 8L
#define PR_BYTES_PER_WORD 4L
#define PR_BYTES_PER_DWORD 8L
#define PR_BITS_PER_BYTE 8L
#define PR_BITS_PER_SHORT 16L
#define PR_BITS_PER_INT 32L
#define PR_BITS_PER_INT64 64L
#define PR_BITS_PER_LONG 32L
#define PR_BITS_PER_FLOAT 32L
#define PR_BITS_PER_DOUBLE 64L
#define PR_BITS_PER_WORD 32L
#define PR_BITS_PER_BYTE_LOG2 3L
#define PR_BITS_PER_SHORT_LOG2 4L
#define PR_BITS_PER_INT_LOG2 5L
#define PR_BITS_PER_INT64_LOG2 6L
#define PR_BITS_PER_LONG_LOG2 5L
#define PR_BITS_PER_FLOAT_LOG2 5L
#define PR_BITS_PER_DOUBLE_LOG2 6L
#define PR_BITS_PER_WORD_LOG2 5L
#define PR_ALIGN_OF_SHORT 2L
#define PR_ALIGN_OF_INT 4L
#define PR_ALIGN_OF_LONG 4L
#define PR_ALIGN_OF_INT64 4L
#define PR_ALIGN_OF_FLOAT 4L
#define PR_ALIGN_OF_DOUBLE 4L
#define PR_ALIGN_OF_POINTER 4L
#define PR_ALIGN_OF_WORD 4L
#define PR_BYTES_PER_WORD_LOG2 2L
#define PR_BYTES_PER_DWORD_LOG2 3L
#define PR_WORDS_PER_DWORD_LOG2 1L
#endif
#endif /* XP_UNIX */
#endif /* nspr_cpucfg___ */

2577
js/src/mininspr/prdtoa.c Normal file

Разница между файлами не показана из-за своего большого размера Загрузить разницу

469
js/src/mininspr/prlog.c Normal file
Просмотреть файл

@ -0,0 +1,469 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifdef MINI_NSPR
#include "prstubs.h"
#include "prlog.h"
#include "prmem.h"
#else
#include "primpl.h"
#include "prenv.h"
#endif
#include "prprf.h"
#include <string.h>
/*
* Lock used to lock the log.
*
* We can't define _PR_LOCK_LOG simply as PR_Lock because PR_Lock may
* contain assertions. We have to avoid assertions in _PR_LOCK_LOG
* because PR_ASSERT calls PR_LogPrint, which in turn calls _PR_LOCK_LOG.
* This can lead to infinite recursion.
*/
static PRLock *_pr_logLock;
#if (defined(_PR_PTHREADS) || defined(_PR_GLOBAL_THREADS_ONLY))
#define _PR_LOCK_LOG() { _PR_LOCK_LOCK(_pr_logLock)
#define _PR_UNLOCK_LOG() _PR_LOCK_UNLOCK(_pr_logLock); }
#else
#define _PR_LOCK_LOG() \
{ \
PRIntn _is; \
PRThread *_me = _PR_MD_CURRENT_THREAD(); \
if (!_PR_IS_NATIVE_THREAD(_me)) \
_PR_INTSOFF(_is); \
_PR_LOCK_LOCK(_pr_logLock)
#define _PR_UNLOCK_LOG() \
_PR_LOCK_UNLOCK(_pr_logLock); \
PR_ASSERT(_me == _PR_MD_CURRENT_THREAD()); \
if (!_PR_IS_NATIVE_THREAD(_me)) \
_PR_INTSON(_is); \
}
#endif
#ifdef XP_PC
#define strcasecmp stricmp
#define strncasecmp strnicmp
#endif
/*
* On NT, we can't define _PUT_LOG as PR_Write or _PR_MD_WRITE,
* because every asynchronous file io operation leads to a fiber context
* switch. So we define _PUT_LOG as fputs (from stdio.h). A side
* benefit is that fputs handles the LF->CRLF translation. This
* code can also be used on other platforms with file stream io.
*/
#if defined(WIN32) || defined(XP_OS2)
#define _PR_USE_STDIO_FOR_LOGGING
#endif
/* Macros used to reduce #ifdef pollution */
#if defined(_PR_USE_STDIO_FOR_LOGGING)
#define _PUT_LOG(fd, buf, nb) fputs(buf, fd)
#elif defined(_PR_PTHREADS)
#define _PUT_LOG(fd, buf, nb) PR_Write(fd, buf, nb)
#elif defined(XP_MAC)
#define _PUT_LOG(fd, buf, nb) _PR_MD_WRITE_SYNC(fd, buf, nb)
#else
#define _PUT_LOG(fd, buf, nb) _PR_MD_WRITE(fd, buf, nb)
#endif
/************************************************************************/
static PRLogModuleInfo *logModules;
#ifdef PR_LOGGING
static char *logBuf = NULL;
static char *logp;
static char *logEndp;
#ifdef _PR_USE_STDIO_FOR_LOGGING
static FILE *logFile = NULL;
#else
static PRFileDesc *logFile = 0;
#endif
#define LINE_BUF_SIZE 200
#define DEFAULT_BUF_SIZE 16384
#ifdef _PR_NEED_STRCASECMP
/*
* strcasecmp is defined in /usr/ucblib/libucb.a on some platforms
* such as NCR and Unixware. Linking with both libc and libucb
* may cause some problem, so I just provide our own implementation
* of strcasecmp here.
*/
static const unsigned char uc[] =
{
'\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007',
'\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
'\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
'\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
' ', '!', '"', '#', '$', '%', '&', '\'',
'(', ')', '*', '+', ',', '-', '.', '/',
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', ':', ';', '<', '=', '>', '?',
'@', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
'X', 'Y', 'Z', '[', '\\', ']', '^', '_',
'`', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
'X', 'Y', 'Z', '{', '|', '}', '~', '\177'
};
PRIntn strcasecmp(const char *a, const char *b)
{
const unsigned char *ua = (const unsigned char *)a;
const unsigned char *ub = (const unsigned char *)b;
if( ((const char *)0 == a) || (const char *)0 == b )
return (PRIntn)(a-b);
while( (uc[*ua] == uc[*ub]) && ('\0' != *a) )
{
a++;
ua++;
ub++;
}
return (PRIntn)(uc[*ua] - uc[*ub]);
}
#endif /* _PR_NEED_STRCASECMP */
void _PR_InitLog(void)
{
char *ev;
_pr_logLock = PR_NewLock();
ev = PR_GetEnv("NSPR_LOG_MODULES");
if (ev && ev[0]) {
char module[64];
PRBool isSync = PR_FALSE;
PRIntn evlen = strlen(ev), pos = 0;
PRInt32 bufSize = DEFAULT_BUF_SIZE;
while (pos < evlen) {
PRIntn level = 1, count = 0, delta = 0;
count = sscanf(&ev[pos], "%64[A-Za-z0-9]%n:%d%n",
module, &delta, &level, &delta);
pos += delta;
if (count == 0) break;
/*
** If count == 2, then we got module and level. If count
** == 1, then level defaults to 1 (module enabled).
*/
if (strcasecmp(module, "sync") == 0) {
isSync = PR_TRUE;
} else if (strcasecmp(module, "bufsize") == 0) {
if (level >= LINE_BUF_SIZE) {
bufSize = level;
}
} else {
PRLogModuleInfo *lm = logModules;
PRBool skip_modcheck =
(0 == strcasecmp (module, "all")) ? PR_TRUE : PR_FALSE;
while (lm != NULL) {
if (skip_modcheck) lm -> level = (PRLogModuleLevel)level;
else if (strcasecmp(module, lm->name) == 0) {
lm->level = (PRLogModuleLevel)level;
break;
}
lm = lm->next;
}
if (NULL == lm) {
#ifdef XP_PC
char* str = PR_smprintf("Unrecognized NSPR_LOG_MODULE: %s=%d\n",
module, level);
if (str) {
OutputDebugString(str);
PR_smprintf_free(str);
}
#else
fprintf(stderr, "Unrecognized NSPR_LOG_MODULE: %s=%d\n",
module, level);
#endif
}
}
/*found:*/
count = sscanf(&ev[pos], " , %n", &delta);
pos += delta;
if (count == -1) break;
}
PR_SetLogBuffering(isSync ? bufSize : 0);
ev = PR_GetEnv("NSPR_LOG_FILE");
if (ev && ev[0]) {
if (!PR_SetLogFile(ev)) {
#ifdef XP_PC
char* str = PR_smprintf("Unable to create nspr log file '%s'\n", ev);
if (str) {
OutputDebugString(str);
PR_smprintf_free(str);
}
#else
fprintf(stderr, "Unable to create nspr log file '%s'\n", ev);
#endif
}
} else {
#ifdef _PR_USE_STDIO_FOR_LOGGING
logFile = stderr;
#else
logFile = _pr_stderr;
#endif
}
}
}
void _PR_LogCleanup(void)
{
PR_LogFlush();
#ifdef _PR_USE_STDIO_FOR_LOGGING
if (logFile && logFile != stdout && logFile != stderr) {
fclose(logFile);
}
#else
if (logFile && logFile != _pr_stdout && logFile != _pr_stderr) {
PR_Close(logFile);
}
#endif
}
#endif /* PR_LOGGING */
static void _PR_SetLogModuleLevel( PRLogModuleInfo *lm )
{
#ifdef PR_LOGGING
char *ev;
ev = PR_GetEnv("NSPR_LOG_MODULES");
if (ev && ev[0]) {
char module[64];
PRIntn evlen = strlen(ev), pos = 0;
while (pos < evlen) {
PRIntn level = 1, count = 0, delta = 0;
PRLogModuleInfo *lm = logModules;
PRBool skip_modcheck;
count = sscanf(&ev[pos], "%64[A-Za-z0-9]%n:%d%n",
module, &delta, &level, &delta);
pos += delta;
if (count == 0) break;
/*
** If count == 2, then we got module and level. If count
** == 1, then level defaults to 1 (module enabled).
*/
skip_modcheck = (0 == strcasecmp (module, "all")) ? PR_TRUE : PR_FALSE;
while (lm != NULL)
{
if (skip_modcheck)
lm->level = (PRLogModuleLevel)level;
else if (strcasecmp(module, lm->name) == 0)
{
lm->level = (PRLogModuleLevel)level;
break;
}
lm = lm->next;
}
/*found:*/
count = sscanf(&ev[pos], " , %n", &delta);
pos += delta;
if (count == -1) break;
}
}
#endif /* PR_LOGGING */
} /* end _PR_SetLogModuleLevel() */
PR_IMPLEMENT(PRLogModuleInfo*) PR_NewLogModule(const char *name)
{
PRLogModuleInfo *lm;
if (!_pr_initialized) _PR_ImplicitInitialization();
lm = PR_NEWZAP(PRLogModuleInfo);
if (lm) {
lm->name = strdup(name);
lm->level = PR_LOG_NONE;
lm->next = logModules;
logModules = lm;
}
_PR_SetLogModuleLevel(lm);
return lm;
}
PR_IMPLEMENT(PRBool) PR_SetLogFile(const char *file)
{
#ifdef PR_LOGGING
#ifdef _PR_USE_STDIO_FOR_LOGGING
FILE *newLogFile;
newLogFile = fopen(file, "w");
if (newLogFile) {
/* We do buffering ourselves. */
setvbuf(newLogFile, NULL, _IONBF, 0);
if (logFile && logFile != stdout && logFile != stderr) {
fclose(logFile);
}
logFile = newLogFile;
}
return (PRBool) (newLogFile != 0);
#else
PRFileDesc *newLogFile;
newLogFile = PR_Open(file, PR_WRONLY|PR_CREATE_FILE, 0666);
if (newLogFile) {
if (logFile && logFile != _pr_stdout && logFile != _pr_stderr) {
PR_Close(logFile);
}
logFile = newLogFile;
#if defined(XP_MAC)
SetLogFileTypeCreator(file);
#endif
}
return (PRBool) (newLogFile != 0);
#endif /* _PR_USE_STDIO_FOR_LOGGING */
#else /* PR_LOGGING */
PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
return PR_FALSE;
#endif /* PR_LOGGING */
}
PR_IMPLEMENT(void) PR_SetLogBuffering(PRIntn buffer_size)
{
#ifdef PR_LOGGING
PR_LogFlush();
if (logBuf)
PR_DELETE(logBuf);
logBuf = 0;
if (buffer_size >= LINE_BUF_SIZE) {
logp = logBuf = (char*) PR_MALLOC(buffer_size);
logEndp = logp + buffer_size;
}
#endif /* PR_LOGGING */
}
PR_IMPLEMENT(void) PR_LogPrint(const char *fmt, ...)
{
#ifdef PR_LOGGING
va_list ap;
char line[LINE_BUF_SIZE];
PRUint32 nb;
PRThread *me;
if (!_pr_initialized) _PR_ImplicitInitialization();
if (!logFile) {
return;
}
va_start(ap, fmt);
me = PR_GetCurrentThread();
nb = PR_snprintf(line, sizeof(line)-1, "%ld[%p]: ",
#if defined(_PR_DCETHREADS)
/* The problem is that for _PR_DCETHREADS, pthread_t is not a
* pointer, but a structure; so you can't easily print it...
*/
me ? &(me->id): 0L, me);
#else
me ? me->id : 0L, me);
#endif
nb += PR_vsnprintf(line+nb, sizeof(line)-nb-1, fmt, ap);
if (nb && (line[nb-1] != '\n')) {
#ifndef XP_MAC
line[nb++] = '\n';
#else
line[nb++] = '\015';
#endif
line[nb] = '\0';
} else {
#ifdef XP_MAC
line[nb-1] = '\015';
#endif
}
va_end(ap);
_PR_LOCK_LOG();
if (logBuf == 0) {
_PUT_LOG(logFile, line, nb);
} else {
if (logp + nb > logEndp) {
_PUT_LOG(logFile, logBuf, logp - logBuf);
logp = logBuf;
}
memcpy(logp, line, nb);
logp += nb;
}
_PR_UNLOCK_LOG();
PR_LogFlush();
#endif /* PR_LOGGING */
}
PR_IMPLEMENT(void) PR_LogFlush(void)
{
#ifdef PR_LOGGING
if (logBuf && logFile) {
_PR_LOCK_LOG();
if (logp > logBuf) {
_PUT_LOG(logFile, logBuf, logp - logBuf);
logp = logBuf;
}
_PR_UNLOCK_LOG();
}
#endif /* PR_LOGGING */
}
PR_IMPLEMENT(void) PR_Abort(void)
{
#ifdef PR_LOGGING
PR_LogPrint("Aborting");
abort();
#endif /* PR_LOGGING */
PR_ASSERT(1);
}
PR_IMPLEMENT(void) PR_Assert(const char *s, const char *file, PRIntn ln)
{
#ifdef PR_LOGGING
PR_LogPrint("Assertion failure: %s, at %s:%d\n", s, file, ln);
#if defined(XP_UNIX) || defined(XP_OS2)
fprintf(stderr, "Assertion failure: %s, at %s:%d\n", s, file, ln);
#endif
#ifdef XP_MAC
dprintf("Assertion failure: %s, at %s:%d\n", s, file, ln);
#endif
#ifdef WIN32
DebugBreak();
#endif
#ifndef XP_MAC
abort();
#endif
#endif /* PR_LOGGING */
}

232
js/src/mininspr/prlog.h Normal file
Просмотреть файл

@ -0,0 +1,232 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef prlog_h___
#define prlog_h___
#include "prtypes.h"
PR_BEGIN_EXTERN_C
/*
** prlog.h -- Declare interfaces to NSPR's Logging service
**
** NSPR provides a logging service that is used by NSPR itself and is
** available to client programs.
**
** To use the service from a client program, you should create a
** PRLogModuleInfo structure by calling PR_NewLogModule(). After
** creating the LogModule, you can write to the log using the PR_LOG()
** macro.
**
** Initialization of the log service is handled by NSPR initialization.
**
** At execution time, you must enable the log service. To enable the
** log service, set the environment variable: NSPR_LOG_MODULES
** variable.
**
** NSPR_LOG_MODULES variable has the form:
**
** <moduleName>:<value>[, <moduleName>:<value>]*
**
** Where:
** <moduleName> is the name passed to PR_NewLogModule().
** <value> is a numeric constant, e.g. 5. This value is the maximum
** value of a log event, enumerated by PRLogModuleLevel, that you want
** written to the log.
**
** For example: to record all events of greater value than or equal to
** PR_LOG_ERROR for a LogModule names "gizmo", say:
**
** set NSPR_LOG_MODULES=gizmo:2
**
** Note that you must specify the numeric value of PR_LOG_ERROR.
**
** Special LogModule names are provided for controlling NSPR's log
** service at execution time. These controls should be set in the
** NSPR_LOG_MODULES environment variable at execution time to affect
** NSPR's log service for your application.
**
** The special LogModule "all" enables all LogModules. To enable all
** LogModule calls to PR_LOG(), say:
**
** set NSPR_LOG_MODULES=all:5
**
** The special LogModule name "sync" tells the NSPR log service to do
** unbuffered logging.
**
** The special LogModule name "buffsize:<size>" tells NSPR to set the
** log buffer to <size>.
**
** The environment variable NSPR_LOG_FILE specifies the log file to use
** unless the default of "stderr" is acceptable.
**
** To put log messages in your programs, use the PR_LOG macro:
**
** PR_LOG(<module>, <level>, (<printfString>, <args>*));
**
** Where <module> is the address of a PRLogModuleInfo structure, and
** <level> is one of the levels defined by the enumeration:
** PRLogModuleLevel. <args> is a printf() style of argument list. That
** is: (fmtstring, ...).
**
** Example:
**
** main() {
** PRIntn one = 1;
** PRLogModuleInfo * myLm = PR_NewLogModule("gizmo");
** PR_LOG( myLm, PR_LOG_ALWAYS, ("Log this! %d\n", one));
** return;
** }
**
** Note the use of printf() style arguments as the third agrument(s) to
** PR_LOG().
**
** After compiling and linking you application, set the environment:
**
** SET NSPR_LOGMODULES=gizmo:5
** SET NSPR_LOG_FILE=logfile.txt
**
** When you execute your application, the string "Log this! 1" will be
** written to the file "logfile.txt".
**
** Note to NSPR engineers: a number of PRLogModuleInfo structures are
** defined and initialized in prinit.c. See this module for ideas on
** what to log where.
**
*/
typedef enum PRLogModuleLevel {
PR_LOG_NONE = 0, /* nothing */
PR_LOG_ALWAYS = 1, /* always printed */
PR_LOG_ERROR = 2, /* error messages */
PR_LOG_WARNING = 3, /* warning messages */
PR_LOG_DEBUG = 4, /* debug messages */
PR_LOG_NOTICE = PR_LOG_DEBUG, /* notice messages */
PR_LOG_WARN = PR_LOG_WARNING, /* warning messages */
PR_LOG_MIN = PR_LOG_DEBUG, /* minimal debugging messages */
PR_LOG_MAX = PR_LOG_DEBUG /* maximal debugging messages */
} PRLogModuleLevel;
/*
** One of these structures is created for each module that uses logging.
** "name" is the name of the module
** "level" is the debugging level selected for that module
*/
typedef struct PRLogModuleInfo {
const char *name;
PRLogModuleLevel level;
struct PRLogModuleInfo *next;
} PRLogModuleInfo;
/*
** Create a new log module.
*/
PR_EXTERN(PRLogModuleInfo*) PR_NewLogModule(const char *name);
/*
** Set the file to use for logging. Returns PR_FALSE if the file cannot
** be created
*/
PR_EXTERN(PRBool) PR_SetLogFile(const char *name);
/*
** Set the size of the logging buffer. If "buffer_size" is zero then the
** logging becomes "synchronous" (or unbuffered).
*/
PR_EXTERN(void) PR_SetLogBuffering(PRIntn buffer_size);
/*
** Print a string to the log. "fmt" is a PR_snprintf format type. All
** messages printed to the log are preceeded by the name of the thread
** and a time stamp. Also, the routine provides a missing newline if one
** is not provided.
*/
PR_EXTERN(void) PR_LogPrint(const char *fmt, ...);
/*
** Flush the log to its file.
*/
PR_EXTERN(void) PR_LogFlush(void);
/*
** Windoze 16 can't support a large static string space for all of the
** various debugging strings so logging is not enabled for it.
*/
#if (defined(DEBUG) || defined(FORCE_PR_LOG)) && !defined(WIN16)
#define PR_LOGGING 1
#define PR_LOG_TEST(_module,_level) \
((_module)->level >= (_level))
/*
** Log something.
** "module" is the address of a PRLogModuleInfo structure
** "level" is the desired logging level
** "args" is a variable length list of arguments to print, in the following
** format: ("printf style format string", ...)
*/
#define PR_LOG(_module,_level,_args) \
PR_BEGIN_MACRO \
if (PR_LOG_TEST(_module,_level)) { \
PR_LogPrint _args; \
} \
PR_END_MACRO
#else /* (defined(DEBUG) || defined(FORCE_PR_LOG)) && !defined(WIN16) */
#undef PR_LOGGING
#define PR_LOG_TEST(module,level) 0
#define PR_LOG(module,level,args)
#endif /* (defined(DEBUG) || defined(FORCE_PR_LOG)) && !defined(WIN16) */
#ifndef NO_NSPR_10_SUPPORT
#ifdef PR_LOGGING
#define PR_LOG_BEGIN PR_LOG
#define PR_LOG_END PR_LOG
#define PR_LOG_DEFINE PR_NewLogModule
#else
#define PR_LOG_BEGIN(module,level,args)
#define PR_LOG_END(module,level,args)
#define PR_LOG_DEFINE(_name) NULL
#endif /* PR_LOGGING */
#endif /* NO_NSPR_10_SUPPORT */
#if defined(DEBUG)
PR_EXTERN(void) PR_Assert(const char *s, const char *file, PRIntn ln);
#define PR_ASSERT(_expr) \
((_expr)?((void)0):PR_Assert(# _expr,__FILE__,__LINE__))
#define PR_NOT_REACHED(_reasonStr) \
PR_Assert(_reasonStr,__FILE__,__LINE__)
#else
#define PR_ASSERT(expr) ((void) 0)
#define PR_NOT_REACHED(reasonStr)
#endif /* defined(DEBUG) */
PR_END_EXTERN_C
#endif /* prlog_h___ */

62
js/src/mininspr/prlog2.c Normal file
Просмотреть файл

@ -0,0 +1,62 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "prbit.h"
/*
** Compute the log of the least power of 2 greater than or equal to n
*/
PR_IMPLEMENT(PRIntn) PR_CeilingLog2(PRUint32 n)
{
PRIntn log2 = 0;
if (n & (n-1))
log2++;
if (n >> 16)
log2 += 16, n >>= 16;
if (n >> 8)
log2 += 8, n >>= 8;
if (n >> 4)
log2 += 4, n >>= 4;
if (n >> 2)
log2 += 2, n >>= 2;
if (n >> 1)
log2++;
return log2;
}
/*
** Compute the log of the greatest power of 2 less than or equal to n.
** This really just finds the highest set bit in the word.
*/
PR_IMPLEMENT(PRIntn) PR_FloorLog2(PRUint32 n)
{
PRIntn log2 = 0;
if (n >> 16)
log2 += 16, n >>= 16;
if (n >> 8)
log2 += 8, n >>= 8;
if (n >> 4)
log2 += 4, n >>= 4;
if (n >> 2)
log2 += 2, n >>= 2;
if (n >> 1)
log2++;
return log2;
}

264
js/src/mininspr/prlong.c Normal file
Просмотреть файл

@ -0,0 +1,264 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifdef MINI_NSPR
#include "prtypes.h"
#include "prlong.h"
#else
#include "primpl.h"
#endif
static PRInt64 ll_zero = LL_INIT( 0x00000000,0x00000000 );
static PRInt64 ll_maxint = LL_INIT( 0x7fffffff, 0xffffffff );
static PRInt64 ll_minint = LL_INIT( 0x80000000, 0x00000000 );
#if defined(HAVE_WATCOM_BUG_2)
PRInt64 __pascal __loadds __export
LL_Zero(void) { return ll_zero; }
PRInt64 __pascal __loadds __export
LL_MaxInt(void) { return ll_maxint; }
PRInt64 __pascal __loadds __export
LL_MinInt(void) { return ll_minint; }
#else
PR_IMPLEMENT(PRInt64) LL_Zero(void) { return ll_zero; }
PR_IMPLEMENT(PRInt64) LL_MaxInt(void) { return ll_maxint; }
PR_IMPLEMENT(PRInt64) LL_MinInt(void) { return ll_minint; }
#endif
#ifndef HAVE_LONG_LONG
/*
** Divide 64-bit a by 32-bit b, which must be normalized so its high bit is 1.
*/
static void norm_udivmod32(PRUint32 *qp, PRUint32 *rp, PRUint64 a, PRUint32 b)
{
PRUint32 d1, d0, q1, q0;
PRUint32 r1, r0, m;
d1 = _hi16(b);
d0 = _lo16(b);
r1 = a.hi % d1;
q1 = a.hi / d1;
m = q1 * d0;
r1 = (r1 << 16) | _hi16(a.lo);
if (r1 < m) {
q1--, r1 += b;
if (r1 >= b /* i.e., we didn't get a carry when adding to r1 */
&& r1 < m) {
q1--, r1 += b;
}
}
r1 -= m;
r0 = r1 % d1;
q0 = r1 / d1;
m = q0 * d0;
r0 = (r0 << 16) | _lo16(a.lo);
if (r0 < m) {
q0--, r0 += b;
if (r0 >= b
&& r0 < m) {
q0--, r0 += b;
}
}
*qp = (q1 << 16) | q0;
*rp = r0 - m;
}
static PRUint32 CountLeadingZeros(PRUint32 a)
{
PRUint32 t;
PRUint32 r = 32;
if ((t = a >> 16) != 0)
r -= 16, a = t;
if ((t = a >> 8) != 0)
r -= 8, a = t;
if ((t = a >> 4) != 0)
r -= 4, a = t;
if ((t = a >> 2) != 0)
r -= 2, a = t;
if ((t = a >> 1) != 0)
r -= 1, a = t;
if (a & 1)
r--;
return r;
}
PR_IMPLEMENT(void) ll_udivmod(PRUint64 *qp, PRUint64 *rp, PRUint64 a, PRUint64 b)
{
PRUint32 n0, n1, n2;
PRUint32 q0, q1;
PRUint32 rsh, lsh;
n0 = a.lo;
n1 = a.hi;
if (b.hi == 0) {
if (b.lo > n1) {
/* (0 q0) = (n1 n0) / (0 D0) */
lsh = CountLeadingZeros(b.lo);
if (lsh) {
/*
* Normalize, i.e. make the most significant bit of the
* denominator be set.
*/
b.lo = b.lo << lsh;
n1 = (n1 << lsh) | (n0 >> (32 - lsh));
n0 = n0 << lsh;
}
a.lo = n0, a.hi = n1;
norm_udivmod32(&q0, &n0, a, b.lo);
q1 = 0;
/* remainder is in n0 >> lsh */
} else {
/* (q1 q0) = (n1 n0) / (0 d0) */
if (b.lo == 0) /* user wants to divide by zero! */
b.lo = 1 / b.lo; /* so go ahead and crash */
lsh = CountLeadingZeros(b.lo);
if (lsh == 0) {
/*
* From (n1 >= b.lo)
* && (the most significant bit of b.lo is set),
* conclude that
* (the most significant bit of n1 is set)
* && (the leading quotient digit q1 = 1).
*
* This special case is necessary, not an optimization
* (Shifts counts of 32 are undefined).
*/
n1 -= b.lo;
q1 = 1;
} else {
/*
* Normalize.
*/
rsh = 32 - lsh;
b.lo = b.lo << lsh;
n2 = n1 >> rsh;
n1 = (n1 << lsh) | (n0 >> rsh);
n0 = n0 << lsh;
a.lo = n1, a.hi = n2;
norm_udivmod32(&q1, &n1, a, b.lo);
}
/* n1 != b.lo... */
a.lo = n0, a.hi = n1;
norm_udivmod32(&q0, &n0, a, b.lo);
/* remainder in n0 >> lsh */
}
if (rp) {
rp->lo = n0 >> lsh;
rp->hi = 0;
}
} else {
if (b.hi > n1) {
/* (0 0) = (n1 n0) / (D1 d0) */
q0 = 0;
q1 = 0;
/* remainder in (n1 n0) */
if (rp) {
rp->lo = n0;
rp->hi = n1;
}
} else {
/* (0 q0) = (n1 n0) / (d1 d0) */
lsh = CountLeadingZeros(b.hi);
if (lsh == 0) {
/*
* From (n1 >= b.hi)
* && (the most significant bit of b.hi is set),
* conclude that
* (the most significant bit of n1 is set)
* && (the quotient digit q0 = 0 or 1).
*
* This special case is necessary, not an optimization.
*/
/*
* The condition on the next line takes advantage of that
* n1 >= b.hi (true due to control flow).
*/
if (n1 > b.hi || n0 >= b.lo) {
q0 = 1;
a.lo = n0, a.hi = n1;
LL_SUB(a, a, b);
} else {
q0 = 0;
}
q1 = 0;
if (rp) {
rp->lo = n0;
rp->hi = n1;
}
} else {
PRInt64 m;
/*
* Normalize.
*/
rsh = 32 - lsh;
b.hi = (b.hi << lsh) | (b.lo >> rsh);
b.lo = b.lo << lsh;
n2 = n1 >> rsh;
n1 = (n1 << lsh) | (n0 >> rsh);
n0 = n0 << lsh;
a.lo = n1, a.hi = n2;
norm_udivmod32(&q0, &n1, a, b.hi);
LL_MUL32(m, q0, b.lo);
if ((m.hi > n1) || ((m.hi == n1) && (m.lo > n0))) {
q0--;
LL_SUB(m, m, b);
}
q1 = 0;
/* Remainder is ((n1 n0) - (m1 m0)) >> lsh */
if (rp) {
a.lo = n0, a.hi = n1;
LL_SUB(a, a, m);
rp->lo = (a.hi << rsh) | (a.lo >> lsh);
rp->hi = a.hi >> lsh;
}
}
}
}
if (qp) {
qp->lo = q0;
qp->hi = q1;
}
}
#endif /* !HAVE_LONG_LONG */

409
js/src/mininspr/prlong.h Normal file
Просмотреть файл

@ -0,0 +1,409 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/*
** File: prlong.h
** Description: Portable access to 64 bit numerics
**
** Long-long (64-bit signed integer type) support. Some C compilers
** don't support 64 bit integers yet, so we use these macros to
** support both machines that do and don't.
**/
#ifndef prlong_h___
#define prlong_h___
#include "prtypes.h"
PR_BEGIN_EXTERN_C
/***********************************************************************
** DEFINES: LL_MaxInt
** LL_MinInt
** LL_Zero
** DESCRIPTION:
** Various interesting constants and static variable
** initializer
***********************************************************************/
#if defined(HAVE_WATCOM_BUG_2)
PRInt64 __pascal __loadds __export
LL_MaxInt(void);
PRInt64 __pascal __loadds __export
LL_MinInt(void);
PRInt64 __pascal __loadds __export
LL_Zero(void);
#else
PR_EXTERN(PRInt64) LL_MaxInt(void);
PR_EXTERN(PRInt64) LL_MinInt(void);
PR_EXTERN(PRInt64) LL_Zero(void);
#endif
#define LL_MAXINT LL_MaxInt()
#define LL_MININT LL_MinInt()
#define LL_ZERO LL_Zero()
#if defined(HAVE_LONG_LONG)
#if PR_BYTES_PER_LONG == 8
#define LL_INIT(hi, lo) ((hi ## L << 32) + lo ## L)
#elif defined(WIN32) || defined(WIN16)
#define LL_INIT(hi, lo) ((hi ## i64 << 32) + lo ## i64)
#else
#define LL_INIT(hi, lo) ((hi ## LL << 32) + lo ## LL)
#endif
/***********************************************************************
** MACROS: LL_*
** DESCRIPTION:
** The following macros define portable access to the 64 bit
** math facilities.
**
***********************************************************************/
/***********************************************************************
** MACROS: LL_<relational operators>
**
** LL_IS_ZERO Test for zero
** LL_EQ Test for equality
** LL_NE Test for inequality
** LL_GE_ZERO Test for zero or positive
** LL_CMP Compare two values
***********************************************************************/
#define LL_IS_ZERO(a) ((a) == 0)
#define LL_EQ(a, b) ((a) == (b))
#define LL_NE(a, b) ((a) != (b))
#define LL_GE_ZERO(a) ((a) >= 0)
#define LL_CMP(a, op, b) ((PRInt64)(a) op (PRInt64)(b))
#define LL_UCMP(a, op, b) ((PRUint64)(a) op (PRUint64)(b))
/***********************************************************************
** MACROS: LL_<logical operators>
**
** LL_AND Logical and
** LL_OR Logical or
** LL_XOR Logical exclusion
** LL_OR2 A disgusting deviation
** LL_NOT Negation (one's compliment)
***********************************************************************/
#define LL_AND(r, a, b) ((r) = (a) & (b))
#define LL_OR(r, a, b) ((r) = (a) | (b))
#define LL_XOR(r, a, b) ((r) = (a) ^ (b))
#define LL_OR2(r, a) ((r) = (r) | (a))
#define LL_NOT(r, a) ((r) = ~(a))
/***********************************************************************
** MACROS: LL_<mathematical operators>
**
** LL_NEG Negation (two's compliment)
** LL_ADD Summation (two's compliment)
** LL_SUB Difference (two's compliment)
***********************************************************************/
#define LL_NEG(r, a) ((r) = -(a))
#define LL_ADD(r, a, b) ((r) = (a) + (b))
#define LL_SUB(r, a, b) ((r) = (a) - (b))
/***********************************************************************
** MACROS: LL_<mathematical operators>
**
** LL_MUL Product (two's compliment)
** LL_DIV Quotient (two's compliment)
** LL_MOD Modulus (two's compliment)
***********************************************************************/
#define LL_MUL(r, a, b) ((r) = (a) * (b))
#define LL_DIV(r, a, b) ((r) = (a) / (b))
#define LL_MOD(r, a, b) ((r) = (a) % (b))
/***********************************************************************
** MACROS: LL_<shifting operators>
**
** LL_SHL Shift left [0..64] bits
** LL_SHR Shift right [0..64] bits with sign extension
** LL_USHR Unsigned shift right [0..64] bits
** LL_ISHL Signed shift left [0..64] bits
***********************************************************************/
#define LL_SHL(r, a, b) ((r) = (PRInt64)(a) << (b))
#define LL_SHR(r, a, b) ((r) = (PRInt64)(a) >> (b))
#define LL_USHR(r, a, b) ((r) = (PRUint64)(a) >> (b))
#define LL_ISHL(r, a, b) ((r) = (PRInt64)(a) << (b))
/***********************************************************************
** MACROS: LL_<conversion operators>
**
** LL_L2I Convert to signed 32 bit
** LL_L2UI Convert to unsigned 32 bit
** LL_L2F Convert to floating point
** LL_L2D Convert to floating point
** LL_I2L Convert signed to 64 bit
** LL_UI2L Convert unsigned to 64 bit
** LL_F2L Convert float to 64 bit
** LL_D2L Convert float to 64 bit
***********************************************************************/
#define LL_L2I(i, l) ((i) = (PRInt32)(l))
#define LL_L2UI(ui, l) ((ui) = (PRUint32)(l))
#define LL_L2F(f, l) ((f) = (PRFloat64)(l))
#define LL_L2D(d, l) ((d) = (PRFloat64)(l))
#define LL_I2L(l, i) ((l) = (PRInt64)(i))
#define LL_UI2L(l, ui) ((l) = (PRInt64)(ui))
#define LL_F2L(l, f) ((l) = (PRInt64)(f))
#define LL_D2L(l, d) ((l) = (PRInt64)(d))
/***********************************************************************
** MACROS: LL_UDIVMOD
** DESCRIPTION:
** Produce both a quotient and a remainder given an unsigned
** INPUTS: PRUint64 a: The dividend of the operation
** PRUint64 b: The quotient of the operation
** OUTPUTS: PRUint64 *qp: pointer to quotient
** PRUint64 *rp: pointer to remainder
***********************************************************************/
#define LL_UDIVMOD(qp, rp, a, b) \
(*(qp) = ((PRUint64)(a) / (b)), \
*(rp) = ((PRUint64)(a) % (b)))
#else /* !HAVE_LONG_LONG */
#ifdef IS_LITTLE_ENDIAN
#define LL_INIT(hi, lo) {PR_INT32(lo), PR_INT32(hi)}
#else
#define LL_INIT(hi, lo) {PR_INT32(hi), PR_INT32(lo)}
#endif
#define LL_IS_ZERO(a) (((a).hi == 0) && ((a).lo == 0))
#define LL_EQ(a, b) (((a).hi == (b).hi) && ((a).lo == (b).lo))
#define LL_NE(a, b) (((a).hi != (b).hi) || ((a).lo != (b).lo))
#define LL_GE_ZERO(a) (((a).hi >> 31) == 0)
#define LL_CMP(a, op, b) (((PRInt32)(a).hi op (PRInt32)(b).hi) || \
(((a).hi == (b).hi) && ((a).lo op (b).lo)))
#define LL_UCMP(a, op, b) (((a).hi op (b).hi) || \
(((a).hi == (b).hi) && ((a).lo op (b).lo)))
#define LL_AND(r, a, b) ((r).lo = (a).lo & (b).lo, \
(r).hi = (a).hi & (b).hi)
#define LL_OR(r, a, b) ((r).lo = (a).lo | (b).lo, \
(r).hi = (a).hi | (b).hi)
#define LL_XOR(r, a, b) ((r).lo = (a).lo ^ (b).lo, \
(r).hi = (a).hi ^ (b).hi)
#define LL_OR2(r, a) ((r).lo = (r).lo | (a).lo, \
(r).hi = (r).hi | (a).hi)
#define LL_NOT(r, a) ((r).lo = ~(a).lo, \
(r).hi = ~(a).hi)
#define LL_NEG(r, a) ((r).lo = -(PRInt32)(a).lo, \
(r).hi = -(PRInt32)(a).hi - ((r).lo != 0))
#define LL_ADD(r, a, b) { \
PRInt64 _a, _b; \
_a = a; _b = b; \
(r).lo = _a.lo + _b.lo; \
(r).hi = _a.hi + _b.hi + ((r).lo < _b.lo); \
}
#define LL_SUB(r, a, b) { \
PRInt64 _a, _b; \
_a = a; _b = b; \
(r).lo = _a.lo - _b.lo; \
(r).hi = _a.hi - _b.hi - (_a.lo < _b.lo); \
}
#define LL_MUL(r, a, b) { \
PRInt64 _a, _b; \
_a = a; _b = b; \
LL_MUL32(r, _a.lo, _b.lo); \
(r).hi += _a.hi * _b.lo + _a.lo * _b.hi; \
}
#define _lo16(a) ((a) & PR_BITMASK(16))
#define _hi16(a) ((a) >> 16)
#define LL_MUL32(r, a, b) { \
PRUint32 _a1, _a0, _b1, _b0, _y0, _y1, _y2, _y3; \
_a1 = _hi16(a), _a0 = _lo16(a); \
_b1 = _hi16(b), _b0 = _lo16(b); \
_y0 = _a0 * _b0; \
_y1 = _a0 * _b1; \
_y2 = _a1 * _b0; \
_y3 = _a1 * _b1; \
_y1 += _hi16(_y0); /* can't carry */ \
_y1 += _y2; /* might carry */ \
if (_y1 < _y2) \
_y3 += (PRUint32)(PR_BIT(16)); /* propagate */ \
(r).lo = (_lo16(_y1) << 16) + _lo16(_y0); \
(r).hi = _y3 + _hi16(_y1); \
}
#define LL_UDIVMOD(qp, rp, a, b) ll_udivmod(qp, rp, a, b)
PR_EXTERN(void) ll_udivmod(PRUint64 *qp, PRUint64 *rp, PRUint64 a, PRUint64 b);
#define LL_DIV(r, a, b) { \
PRInt64 _a, _b; \
PRUint32 _negative = (PRInt32)(a).hi < 0; \
if (_negative) { \
LL_NEG(_a, a); \
} else { \
_a = a; \
} \
if ((PRInt32)(b).hi < 0) { \
_negative ^= 1; \
LL_NEG(_b, b); \
} else { \
_b = b; \
} \
LL_UDIVMOD(&(r), 0, _a, _b); \
if (_negative) \
LL_NEG(r, r); \
}
#define LL_MOD(r, a, b) { \
PRInt64 _a, _b; \
PRUint32 _negative = (PRInt32)(a).hi < 0; \
if (_negative) { \
LL_NEG(_a, a); \
} else { \
_a = a; \
} \
if ((PRInt32)(b).hi < 0) { \
LL_NEG(_b, b); \
} else { \
_b = b; \
} \
LL_UDIVMOD(0, &(r), _a, _b); \
if (_negative) \
LL_NEG(r, r); \
}
#define LL_SHL(r, a, b) { \
if (b) { \
PRInt64 _a; \
_a = a; \
if ((b) < 32) { \
(r).lo = _a.lo << ((b) & 31); \
(r).hi = (_a.hi << ((b) & 31)) | (_a.lo >> (32 - (b))); \
} else { \
(r).lo = 0; \
(r).hi = _a.lo << ((b) & 31); \
} \
} else { \
(r) = (a); \
} \
}
/* a is an PRInt32, b is PRInt32, r is PRInt64 */
#define LL_ISHL(r, a, b) { \
if (b) { \
PRInt64 _a; \
_a.lo = (a); \
_a.hi = 0; \
if ((b) < 32) { \
(r).lo = (a) << ((b) & 31); \
(r).hi = ((a) >> (32 - (b))); \
} else { \
(r).lo = 0; \
(r).hi = (a) << ((b) & 31); \
} \
} else { \
(r).lo = (a); \
(r).hi = 0; \
} \
}
#define LL_SHR(r, a, b) { \
if (b) { \
PRInt64 _a; \
_a = a; \
if ((b) < 32) { \
(r).lo = (_a.hi << (32 - (b))) | (_a.lo >> ((b) & 31)); \
(r).hi = (PRInt32)_a.hi >> ((b) & 31); \
} else { \
(r).lo = (PRInt32)_a.hi >> ((b) & 31); \
(r).hi = (PRInt32)_a.hi >> 31; \
} \
} else { \
(r) = (a); \
} \
}
#define LL_USHR(r, a, b) { \
if (b) { \
PRInt64 _a; \
_a = a; \
if ((b) < 32) { \
(r).lo = (_a.hi << (32 - (b))) | (_a.lo >> ((b) & 31)); \
(r).hi = _a.hi >> ((b) & 31); \
} else { \
(r).lo = _a.hi >> ((b) & 31); \
(r).hi = 0; \
} \
} else { \
(r) = (a); \
} \
}
#define LL_L2I(i, l) ((i) = (l).lo)
#define LL_L2UI(ui, l) ((ui) = (l).lo)
#define LL_L2F(f, l) { double _d; LL_L2D(_d, l); (f) = (PRFloat64)_d; }
#define LL_L2D(d, l) { \
int _negative; \
PRInt64 _absval; \
\
_negative = (l).hi >> 31; \
if (_negative) { \
LL_NEG(_absval, l); \
} else { \
_absval = l; \
} \
(d) = (double)_absval.hi * 4.294967296e9 + _absval.lo; \
if (_negative) \
(d) = -(d); \
}
#define LL_I2L(l, i) { PRInt32 _i = (i) >> 31; (l).lo = (i); (l).hi = _i; }
#define LL_UI2L(l, ui) ((l).lo = (ui), (l).hi = 0)
#define LL_F2L(l, f) { double _d = (double)f; LL_D2L(l, _d); }
#define LL_D2L(l, d) { \
int _negative; \
double _absval, _d_hi; \
PRInt64 _lo_d; \
\
_negative = ((d) < 0); \
_absval = _negative ? -(d) : (d); \
\
(l).hi = _absval / 4.294967296e9; \
(l).lo = 0; \
LL_L2D(_d_hi, l); \
_absval -= _d_hi; \
_lo_d.hi = 0; \
if (_absval < 0) { \
_lo_d.lo = -_absval; \
LL_SUB(l, l, _lo_d); \
} else { \
_lo_d.lo = _absval; \
LL_ADD(l, l, _lo_d); \
} \
\
if (_negative) \
LL_NEG(l, l); \
}
#endif /* !HAVE_LONG_LONG */
PR_END_EXTERN_C
#endif /* prlong_h___ */

238
js/src/mininspr/prmem.c Normal file
Просмотреть файл

@ -0,0 +1,238 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/*
** Thread safe versions of malloc, free, realloc, calloc and cfree.
*/
#ifdef MINI_NSPR
#include "prtypes.h"
#include <malloc.h>
#else
#include "primpl.h"
#endif
/*
** The PR_Malloc, PR_Calloc, PR_Realloc, and PR_Free functions simply
** call their libc equivalents now. This may seem redundant, but it
** ensures that we are calling into the same runtime library. On
** Win32, it is possible to have multiple runtime libraries (e.g.,
** objects compiled with /MD and /MDd) in the same process, and
** they maintain separate heaps, which cannot be mixed.
*/
PR_IMPLEMENT(void *) PR_Malloc(PRUint32 size)
{
#if defined (WIN16)
return PR_MD_malloc( (size_t) size);
#else
return malloc(size);
#endif
}
PR_IMPLEMENT(void *) PR_Calloc(PRUint32 nelem, PRUint32 elsize)
{
#if defined (WIN16)
return PR_MD_calloc( (size_t)nelem, (size_t)elsize );
#else
return calloc(nelem, elsize);
#endif
}
PR_IMPLEMENT(void *) PR_Realloc(void *ptr, PRUint32 size)
{
#if defined (WIN16)
return PR_MD_realloc( ptr, (size_t) size);
#else
return realloc(ptr, size);
#endif
}
PR_IMPLEMENT(void) PR_Free(void *ptr)
{
#if defined (WIN16)
PR_MD_free( ptr );
#else
free(ptr);
#endif
}
/*
** Complexity alert!
**
** If malloc/calloc/free (etc.) were implemented to use pr lock's then
** the entry points could block when called if some other thread had the
** lock.
**
** Most of the time this isn't a problem. However, in the case that we
** are using the thread safe malloc code after PR_Init but before
** PR_AttachThread has been called (on a native thread that nspr has yet
** to be told about) we could get royally screwed if the lock was busy
** and we tried to context switch the thread away. In this scenario
** PR_CURRENT_THREAD() == NULL
**
** To avoid this unfortunate case, we use the low level locking
** facilities for malloc protection instead of the slightly higher level
** locking. This makes malloc somewhat faster so maybe it's a good thing
** anyway.
*/
#ifdef _PR_OVERRIDE_MALLOC
/* Imports */
extern void *_PR_UnlockedMalloc(size_t size);
extern void *_PR_UnlockedMemalign(size_t alignment, size_t size);
extern void _PR_UnlockedFree(void *ptr);
extern void *_PR_UnlockedRealloc(void *ptr, size_t size);
extern void *_PR_UnlockedCalloc(size_t n, size_t elsize);
static PRBool _PR_malloc_initialised = PR_FALSE;
#ifdef _PR_PTHREADS
static pthread_mutex_t _PR_MD_malloc_crustylock;
#define _PR_Lock_Malloc() { \
if(PR_TRUE == _PR_malloc_initialised) { \
PRStatus rv; \
rv = pthread_mutex_lock(&_PR_MD_malloc_crustylock); \
PR_ASSERT(0 == rv); \
}
#define _PR_Unlock_Malloc() if(PR_TRUE == _PR_malloc_initialised) { \
PRStatus rv; \
rv = pthread_mutex_unlock(&_PR_MD_malloc_crustylock); \
PR_ASSERT(0 == rv); \
} \
}
#else /* _PR_PTHREADS */
static _MDLock _PR_MD_malloc_crustylock;
#define _PR_Lock_Malloc() { \
PRIntn _is; \
if(PR_TRUE == _PR_malloc_initialised) { \
if (_PR_MD_CURRENT_THREAD() && \
!_PR_IS_NATIVE_THREAD( \
_PR_MD_CURRENT_THREAD())) \
_PR_INTSOFF(_is); \
_PR_MD_LOCK(&_PR_MD_malloc_crustylock); \
}
#define _PR_Unlock_Malloc() if(PR_TRUE == _PR_malloc_initialised) { \
_PR_MD_UNLOCK(&_PR_MD_malloc_crustylock); \
if (_PR_MD_CURRENT_THREAD() && \
!_PR_IS_NATIVE_THREAD( \
_PR_MD_CURRENT_THREAD())) \
_PR_INTSON(_is); \
} \
}
#endif /* _PR_PTHREADS */
PR_IMPLEMENT(PRStatus) _PR_MallocInit(void)
{
PRStatus rv = PR_SUCCESS;
if( PR_TRUE == _PR_malloc_initialised ) return PR_SUCCESS;
#ifdef _PR_PTHREADS
{
int status;
pthread_mutexattr_t mattr;
status = PTHREAD_MUTEXATTR_INIT(&mattr);
PR_ASSERT(0 == status);
status = PTHREAD_MUTEX_INIT(_PR_MD_malloc_crustylock, mattr);
PR_ASSERT(0 == status);
status = PTHREAD_MUTEXATTR_DESTROY(&mattr);
PR_ASSERT(0 == status);
}
#else /* _PR_PTHREADS */
_MD_NEW_LOCK(&_PR_MD_malloc_crustylock);
#endif /* _PR_PTHREADS */
if( PR_SUCCESS == rv )
{
_PR_malloc_initialised = PR_TRUE;
}
return rv;
}
void *malloc(size_t size)
{
void *p;
_PR_Lock_Malloc();
p = _PR_UnlockedMalloc(size);
_PR_Unlock_Malloc();
return p;
}
#if defined(IRIX)
void *memalign(size_t alignment, size_t size)
{
void *p;
_PR_Lock_Malloc();
p = _PR_UnlockedMemalign(alignment, size);
_PR_Unlock_Malloc();
return p;
}
void *valloc(size_t size)
{
return(memalign(sysconf(_SC_PAGESIZE),size));
}
#endif /* IRIX */
void free(void *ptr)
{
_PR_Lock_Malloc();
_PR_UnlockedFree(ptr);
_PR_Unlock_Malloc();
}
void *realloc(void *ptr, size_t size)
{
void *p;
_PR_Lock_Malloc();
p = _PR_UnlockedRealloc(ptr, size);
_PR_Unlock_Malloc();
return p;
}
void *calloc(size_t n, size_t elsize)
{
void *p;
_PR_Lock_Malloc();
p = _PR_UnlockedCalloc(n, elsize);
_PR_Unlock_Malloc();
return p;
}
void cfree(void *p)
{
_PR_Lock_Malloc();
_PR_UnlockedFree(p);
_PR_Unlock_Malloc();
}
void _PR_InitMem(void)
{
PRStatus rv;
rv = _PR_MallocInit();
PR_ASSERT(PR_SUCCESS == rv);
}
#endif /* _PR_OVERRIDE_MALLOC */

243
js/src/mininspr/prmem.h Normal file
Просмотреть файл

@ -0,0 +1,243 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/*
** File: prmem.h
** Description: API to NSPR 2.0 memory management functions
**
*/
#ifndef prmem_h___
#define prmem_h___
#include "prtypes.h"
#include <stddef.h>
#include <stdlib.h>
PR_BEGIN_EXTERN_C
/*
** Thread safe memory allocation.
**
** NOTE: pr wraps up malloc, free, calloc, realloc so they are already
** thread safe (and are not declared here - look in stdlib.h).
*/
/*
** PR_Malloc, PR_Calloc, PR_Realloc, and PR_Free have the same signatures
** as their libc equivalent malloc, calloc, realloc, and free, and have
** the same semantics. (Note that the argument type size_t is replaced
** by PRUint32.) Memory allocated by PR_Malloc, PR_Calloc, or PR_Realloc
** must be freed by PR_Free.
*/
PR_EXTERN(void *) PR_Malloc(PRUint32 size);
PR_EXTERN(void *) PR_Calloc(PRUint32 nelem, PRUint32 elsize);
PR_EXTERN(void *) PR_Realloc(void *ptr, PRUint32 size);
PR_EXTERN(void) PR_Free(void *ptr);
/*
** The following are some convenience macros defined in terms of
** PR_Malloc, PR_Calloc, PR_Realloc, and PR_Free.
*/
/***********************************************************************
** FUNCTION: PR_MALLOC()
** DESCRIPTION:
** PR_NEW() allocates an untyped item of size _size from the heap.
** INPUTS: _size: size in bytes of item to be allocated
** OUTPUTS: untyped pointer to the node allocated
** RETURN: pointer to node or error returned from malloc().
***********************************************************************/
#define PR_MALLOC(_bytes) (PR_Malloc((_bytes)))
/***********************************************************************
** FUNCTION: PR_NEW()
** DESCRIPTION:
** PR_NEW() allocates an item of type _struct from the heap.
** INPUTS: _struct: a data type
** OUTPUTS: pointer to _struct
** RETURN: pointer to _struct or error returns from malloc().
***********************************************************************/
#define PR_NEW(_struct) ((_struct *) PR_MALLOC(sizeof(_struct)))
/***********************************************************************
** FUNCTION: PR_REALLOC()
** DESCRIPTION:
** PR_REALLOC() re-allocates _ptr bytes from the heap as a _size
** untyped item.
** INPUTS: _ptr: pointer to node to reallocate
** _size: size of node to allocate
** OUTPUTS: pointer to node allocated
** RETURN: pointer to node allocated
***********************************************************************/
#define PR_REALLOC(_ptr, _size) (PR_Realloc((_ptr), (_size)))
/***********************************************************************
** FUNCTION: PR_CALLOC()
** DESCRIPTION:
** PR_CALLOC() allocates a _size bytes untyped item from the heap
** and sets the allocated memory to all 0x00.
** INPUTS: _size: size of node to allocate
** OUTPUTS: pointer to node allocated
** RETURN: pointer to node allocated
***********************************************************************/
#define PR_CALLOC(_size) (PR_Calloc(1, (_size)))
/***********************************************************************
** FUNCTION: PR_NEWZAP()
** DESCRIPTION:
** PR_NEWZAP() allocates an item of type _struct from the heap
** and sets the allocated memory to all 0x00.
** INPUTS: _struct: a data type
** OUTPUTS: pointer to _struct
** RETURN: pointer to _struct
***********************************************************************/
#define PR_NEWZAP(_struct) ((_struct*)PR_Calloc(1, sizeof(_struct)))
/***********************************************************************
** FUNCTION: PR_DELETE()
** DESCRIPTION:
** PR_DELETE() unallocates an object previosly allocated via PR_NEW()
** or PR_NEWZAP() to the heap.
** INPUTS: pointer to previously allocated object
** OUTPUTS: the referenced object is returned to the heap
** RETURN: void
***********************************************************************/
#define PR_DELETE(_ptr) { PR_Free(_ptr); (_ptr) = NULL; }
/***********************************************************************
** FUNCTION: PR_FREEIF()
** DESCRIPTION:
** PR_FREEIF() conditionally unallocates an object previously allocated
** vial PR_NEW() or PR_NEWZAP(). If the pointer to the object is
** equal to zero (0), the object is not released.
** INPUTS: pointer to previously allocated object
** OUTPUTS: the referenced object is conditionally returned to the heap
** RETURN: void
***********************************************************************/
#define PR_FREEIF(_ptr) if (_ptr) PR_DELETE(_ptr)
/***********************************************************************
** Typedef ENUM: PRSegmentAccess
** DESCRIPTION:
** Defines a number of segment accessor types for PR_Seg* functions
**
***********************************************************************/
typedef struct PRSegment PRSegment;
typedef enum {
PR_SEGMENT_NONE,
PR_SEGMENT_RDONLY,
PR_SEGMENT_RDWR
} PRSegmentAccess;
/***********************************************************************
** FUNCTION: PR_NewSegment()
** DESCRIPTION:
** Allocate a memory segment. The "size" value is rounded up to the
** native system page size and a page aligned portion of memory is
** returned. This memory is not part of the malloc heap. If "vaddr" is
** not NULL then PR tries to allocate the segment at the desired virtual
** address. Segments are mapped PR_SEGMENT_RDWR when created.
** INPUTS: size: size of the desired memory segment
** vaddr: address at which the newly aquired segment is to be
** mapped into memory.
** OUTPUTS: a memory segment is allocated, a PRSegment is allocated
** RETURN: pointer to PRSegment
***********************************************************************/
PR_EXTERN(PRSegment*) PR_NewSegment(PRUint32 size, void *vaddr);
/***********************************************************************
** FUNCTION: PR_DestroySegment()
** DESCRIPTION:
** The memory segment and the PRSegment are freed
** INPUTS: seg: pointer to PRSegment to be freed
** OUTPUTS: the the PRSegment and its associated memory segment are freed
** RETURN: void
***********************************************************************/
PR_EXTERN(void) PR_DestroySegment(PRSegment *seg);
/***********************************************************************
** FUNCTION: PR_GrowSegment()
** DESCRIPTION:
** Attempt to grow/shrink a memory segment. If deltaBytes is positive,
** the segment is grown. If deltaBytes is negative, the segment is
** shrunk. This returns the number of bytes added to the segment if
** successful, zero otherwise.
** INPUTS: seg: pointer to a PRSegment
** OUTPUTS:
** RETURN: PRUint32: number of bytes added to the memory segment or zero
***********************************************************************/
PR_EXTERN(PRUint32) PR_GrowSegment(PRSegment *seg, PRInt32 deltaBytes);
/***********************************************************************
** FUNCTION: PR_GetSegmentVaddr()
** DESCRIPTION:
** PR_Segment member accessor function.
** Return the virtual address of the memory segment
**
** INPUTS: seg: pointer to a PRSegment
** OUTPUTS: none
** RETURN: void*: Address where the memory segment is mapped.
***********************************************************************/
PR_EXTERN(void*) PR_GetSegmentVaddr(PRSegment *seg);
/***********************************************************************
** FUNCTION: PR_GetSegmentSize()
** DESCRIPTION:
** PR_Segment member accessor function.
** Return the size of the associated memory segment
** INPUTS: seg: pointer to a PRSegment
** OUTPUTS: none
** RETURN: size_t: size of the associated memory segment
***********************************************************************/
PR_EXTERN(size_t) PR_GetSegmentSize(PRSegment *seg);
/***********************************************************************
** FUNCTION: PR_MapSegment()
** DESCRIPTION:
** Change the mapping on a segment.
** "how" == PR_SEGMENT_NONE: the segment becomes unmapped
** "how" == PR_SEGMENT_RDONLY: the segment becomes mapped and readable
** "how" == PR_SEGMENT_RDWR: the segment becomes mapped read/write
**
** Note: If a segment can be read then it is also possible to execute
** code in it.
** INPUTS: seg: pointer to a PRSegment
** how: one of PRSegmentAccess enumerated values
** OUTPUTS: the access for the associated memory segment is changed
** RETURN: void
***********************************************************************/
PR_EXTERN(void) PR_MapSegment(PRSegment *seg, PRSegmentAccess how);
/***********************************************************************
** FUNCTION: PR_GetSegmentAccess()
** DESCRIPTION:
** PR_Segment member accessor function.
** Return a memory segment's current access rights
** INPUTS: seg: pointer to a PRSegment
** OUTPUTS:
** RETURN: PRSegmentAccess: current access rights
***********************************************************************/
PR_EXTERN(PRSegmentAccess) PR_GetSegmentAccess(PRSegment *seg);
PR_END_EXTERN_C
#endif /* prmem_h___ */

173
js/src/mininspr/protypes.h Normal file
Просмотреть файл

@ -0,0 +1,173 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/*
* This section typedefs the old 'native' types to the new PR<type>s.
* These definitions are scheduled to be eliminated at the earliest
* possible time. The NSPR API is implemented and documented using
* the new definitions.
*/
#if !defined(PROTYPES_H)
#define PROTYPES_H
/* SVR4 typedef of uint is commonly found on UNIX machines. */
#ifndef XP_UNIX
typedef PRUintn uint;
#endif
typedef PRUintn uintn;
typedef PRUint64 uint64;
#if !defined(XP_MAC) && !defined(_WIN32) && !defined(XP_OS2)
typedef PRUint32 uint32;
#else
typedef unsigned long uint32;
#endif
typedef PRUint16 uint16;
typedef PRUint8 uint8;
#ifndef _XP_Core_
typedef PRIntn intn;
#endif
/*
* On AIX 4.3, sys/inttypes.h (which is included by sys/types.h, a very
* common header file) defines the types int8, int16, int32, and int64.
* So we don't define these four types here to avoid conflicts in case
* the code also includes sys/types.h.
*/
#if defined(AIX4_3)
#include <sys/inttypes.h>
#else
typedef PRInt64 int64;
/* /usr/include/model.h on HP-UX defines int8, int16, and int32 */
#if defined(HPUX)
#include <model.h>
#else
#if !defined(WIN32) || !defined(_WINSOCK2API_) /* defines its own "int32" */
#if !defined(XP_MAC) && !defined(_WIN32) && !defined(XP_OS2)
typedef PRInt32 int32;
#else
typedef long int32;
#endif
#endif
typedef PRInt16 int16;
typedef PRInt8 int8;
#endif /* HPUX */
#endif /* AIX4_3 */
typedef PRFloat64 float64;
typedef PRUptrdiff uptrdiff_t;
typedef PRUword uprword_t;
typedef PRWord prword_t;
/* Re: prbit.h */
#define TEST_BIT PR_TEST_BIT
#define SET_BIT PR_SET_BIT
#define CLEAR_BIT PR_CLEAR_BIT
/* Re: prarena.h->plarena.h */
#define PRArena PLArena
#define PRArenaPool PLArenaPool
#define PRArenaStats PLArenaStats
#define PR_ARENA_ALIGN PL_ARENA_ALIGN
#define PR_INIT_ARENA_POOL PL_INIT_ARENA_POOL
#define PR_ARENA_ALLOCATE PL_ARENA_ALLOCATE
#define PR_ARENA_GROW PL_ARENA_GROW
#define PR_ARENA_MARK PL_ARENA_MARK
#define PR_CLEAR_UNUSED PL_CLEAR_UNUSED
#define PR_CLEAR_ARENA PL_CLEAR_ARENA
#define PR_ARENA_RELEASE PL_ARENA_RELEASE
#define PR_COUNT_ARENA PL_COUNT_ARENA
#define PR_ARENA_DESTROY PL_ARENA_DESTROY
#define PR_InitArenaPool PL_InitArenaPool
#define PR_FreeArenaPool PL_FreeArenaPool
#define PR_FinishArenaPool PL_FinishArenaPool
#define PR_CompactArenaPool PL_CompactArenaPool
#define PR_ArenaFinish PL_ArenaFinish
#define PR_ArenaAllocate PL_ArenaAllocate
#define PR_ArenaGrow PL_ArenaGrow
#define PR_ArenaRelease PL_ArenaRelease
#define PR_ArenaCountAllocation PL_ArenaCountAllocation
#define PR_ArenaCountInplaceGrowth PL_ArenaCountInplaceGrowth
#define PR_ArenaCountGrowth PL_ArenaCountGrowth
#define PR_ArenaCountRelease PL_ArenaCountRelease
#define PR_ArenaCountRetract PL_ArenaCountRetract
/* Re: prevent.h->plevent.h */
#define PREvent PLEvent
#define PREventQueue PLEventQueue
#define PR_CreateEventQueue PL_CreateEventQueue
#define PR_DestroyEventQueue PL_DestroyEventQueue
#define PR_GetEventQueueMonitor PL_GetEventQueueMonitor
#define PR_ENTER_EVENT_QUEUE_MONITOR PL_ENTER_EVENT_QUEUE_MONITOR
#define PR_EXIT_EVENT_QUEUE_MONITOR PL_EXIT_EVENT_QUEUE_MONITOR
#define PR_PostEvent PL_PostEvent
#define PR_PostSynchronousEvent PL_PostSynchronousEvent
#define PR_GetEvent PL_GetEvent
#define PR_EventAvailable PL_EventAvailable
#define PREventFunProc PLEventFunProc
#define PR_MapEvents PL_MapEvents
#define PR_RevokeEvents PL_RevokeEvents
#define PR_ProcessPendingEvents PL_ProcessPendingEvents
#define PR_WaitForEvent PL_WaitForEvent
#define PR_EventLoop PL_EventLoop
#define PR_GetEventQueueSelectFD PL_GetEventQueueSelectFD
#define PRHandleEventProc PLHandleEventProc
#define PRDestroyEventProc PLDestroyEventProc
#define PR_InitEvent PL_InitEvent
#define PR_GetEventOwner PL_GetEventOwner
#define PR_HandleEvent PL_HandleEvent
#define PR_DestroyEvent PL_DestroyEvent
#define PR_DequeueEvent PL_DequeueEvent
#define PR_GetMainEventQueue PL_GetMainEventQueue
/* Re: prhash.h->plhash.h */
#define PRHashEntry PLHashEntry
#define PRHashTable PLHashTable
#define PRHashNumber PLHashNumber
#define PRHashFunction PLHashFunction
#define PRHashComparator PLHashComparator
#define PRHashEnumerator PLHashEnumerator
#define PRHashAllocOps PLHashAllocOps
#define PR_NewHashTable PL_NewHashTable
#define PR_HashTableDestroy PL_HashTableDestroy
#define PR_HashTableRawLookup PL_HashTableRawLookup
#define PR_HashTableRawAdd PL_HashTableRawAdd
#define PR_HashTableRawRemove PL_HashTableRawRemove
#define PR_HashTableAdd PL_HashTableAdd
#define PR_HashTableRemove PL_HashTableRemove
#define PR_HashTableEnumerateEntries PL_HashTableEnumerateEntries
#define PR_HashTableLookup PL_HashTableLookup
#define PR_HashTableDump PL_HashTableDump
#define PR_HashString PL_HashString
#define PR_CompareStrings PL_CompareStrings
#define PR_CompareValues PL_CompareValues
#if defined(XP_MAC)
#ifndef TRUE /* Mac standard is lower case true */
#define TRUE 1
#endif
#ifndef FALSE /* Mac standard is lower case false */
#define FALSE 0
#endif
#endif
#endif /* !defined(PROTYPES_H) */

1228
js/src/mininspr/prprf.c Normal file

Разница между файлами не показана из-за своего большого размера Загрузить разницу

137
js/src/mininspr/prprf.h Normal file
Просмотреть файл

@ -0,0 +1,137 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef prprf_h___
#define prprf_h___
/*
** API for PR printf like routines. Supports the following formats
** %d - decimal
** %u - unsigned decimal
** %x - unsigned hex
** %X - unsigned uppercase hex
** %o - unsigned octal
** %hd, %hu, %hx, %hX, %ho - 16-bit versions of above
** %ld, %lu, %lx, %lX, %lo - 32-bit versions of above
** %lld, %llu, %llx, %llX, %llo - 64 bit versions of above
** %s - string
** %c - character
** %p - pointer (deals with machine dependent pointer size)
** %f - float
** %g - float
*/
#include "prtypes.h"
#ifndef MINI_NSPR
#include "prio.h"
#endif
#include <stdio.h>
#include <stdarg.h>
PR_BEGIN_EXTERN_C
/*
** sprintf into a fixed size buffer. Guarantees that a NUL is at the end
** of the buffer. Returns the length of the written output, NOT including
** the NUL, or (PRUint32)-1 if an error occurs.
*/
PR_EXTERN(PRUint32) PR_snprintf(char *out, PRUint32 outlen, const char *fmt, ...);
/*
** sprintf into a PR_MALLOC'd buffer. Return a pointer to the malloc'd
** buffer on success, NULL on failure. Call "PR_smprintf_free" to release
** the memory returned.
*/
PR_EXTERN(char*) PR_smprintf(const char *fmt, ...);
/*
** Free the memory allocated, for the caller, by PR_smprintf
*/
PR_EXTERN(void) PR_smprintf_free(char *mem);
/*
** "append" sprintf into a PR_MALLOC'd buffer. "last" is the last value of
** the PR_MALLOC'd buffer. sprintf will append data to the end of last,
** growing it as necessary using realloc. If last is NULL, PR_sprintf_append
** will allocate the initial string. The return value is the new value of
** last for subsequent calls, or NULL if there is a malloc failure.
*/
PR_EXTERN(char*) PR_sprintf_append(char *last, const char *fmt, ...);
/*
** sprintf into a function. The function "f" is called with a string to
** place into the output. "arg" is an opaque pointer used by the stuff
** function to hold any state needed to do the storage of the output
** data. The return value is a count of the number of characters fed to
** the stuff function, or (PRUint32)-1 if an error occurs.
*/
typedef PRIntn (*PRStuffFunc)(void *arg, const char *s, PRUint32 slen);
PR_EXTERN(PRUint32) PR_sxprintf(PRStuffFunc f, void *arg, const char *fmt, ...);
/*
** fprintf to a PRFileDesc
*/
PR_EXTERN(PRUint32) PR_fprintf(struct PRFileDesc* fd, const char *fmt, ...);
/*
** va_list forms of the above.
*/
PR_EXTERN(PRUint32) PR_vsnprintf(char *out, PRUint32 outlen, const char *fmt, va_list ap);
PR_EXTERN(char*) PR_vsmprintf(const char *fmt, va_list ap);
PR_EXTERN(char*) PR_vsprintf_append(char *last, const char *fmt, va_list ap);
PR_EXTERN(PRUint32) PR_vsxprintf(PRStuffFunc f, void *arg, const char *fmt, va_list ap);
PR_EXTERN(PRUint32) PR_vfprintf(struct PRFileDesc* fd, const char *fmt, va_list ap);
/*
***************************************************************************
** FUNCTION: PR_sscanf
** DESCRIPTION:
** PR_sscanf() scans the input character string, performs data
** conversions, and stores the converted values in the data objects
** pointed to by its arguments according to the format control
** string.
**
** PR_sscanf() behaves the same way as the sscanf() function in the
** Standard C Library (stdio.h), with the following exceptions:
** - PR_sscanf() handles the NSPR integer and floating point types,
** such as PRInt16, PRInt32, PRInt64, and PRFloat64, whereas
** sscanf() handles the standard C types like short, int, long,
** and double.
** - PR_sscanf() has no multibyte character support, while sscanf()
** does.
** INPUTS:
** const char *buf
** a character string holding the input to scan
** const char *fmt
** the format control string for the conversions
** ...
** variable number of arguments, each of them is a pointer to
** a data object in which the converted value will be stored
** OUTPUTS: none
** RETURNS: PRInt32
** The number of values converted and stored.
** RESTRICTIONS:
** Multibyte characters in 'buf' or 'fmt' are not allowed.
***************************************************************************
*/
PR_EXTERN(PRInt32) PR_sscanf(const char *buf, const char *fmt, ...);
PR_END_EXTERN_C
#endif /* prprf_h___ */

15
js/src/mininspr/prstubs.c Normal file
Просмотреть файл

@ -0,0 +1,15 @@
#include "prstubs.h"
PR_IMPLEMENT(PRLock*) PR_NewLock(void) { return NULL; }
PR_IMPLEMENT(void) PR_DestroyLock(PRLock *lock) { }
PR_IMPLEMENT(void) PR_Lock(PRLock *lock) { }
PR_IMPLEMENT(PRStatus) PR_Unlock(PRLock *lock) { return PR_SUCCESS;}
PRBool _pr_initialized;
void _PR_ImplicitInitialization(void)
{
_pr_initialized = PR_TRUE;
}

22
js/src/mininspr/prstubs.h Normal file
Просмотреть файл

@ -0,0 +1,22 @@
#ifndef prstubs_h___
#define prstubs_h___
#include "prtypes.h"
PR_BEGIN_EXTERN_C
typedef struct PRLock {int dummy;} PRLock;
PR_EXTERN(PRLock*) PR_NewLock(void);
PR_EXTERN(void) PR_DestroyLock(PRLock *lock);
PR_EXTERN(void) PR_Lock(PRLock *lock);
PR_EXTERN(PRStatus) PR_Unlock(PRLock *lock);
extern PRBool _pr_initialized;
extern void _PR_ImplicitInitialization(void);
#define PR_SetError(x, y)
PR_END_EXTERN_C
#endif /* prstubs_h___ */

382
js/src/mininspr/prtypes.h Normal file
Просмотреть файл

@ -0,0 +1,382 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/*
** File: prtypes.h
** Description: Definitions of NSPR's basic types
**
** Prototypes and macros used to make up for deficiencies in ANSI environments
** that we have found.
**
** Since we do not wrap <stdlib.h> and all the other standard headers, authors
** of portable code will not know in general that they need these definitions.
** Instead of requiring these authors to find the dependent uses in their code
** and take the following steps only in those C files, we take steps once here
** for all C files.
**/
#ifndef prtypes_h___
#define prtypes_h___
#include "prcpucfg.h"
#include <stddef.h>
/***********************************************************************
** MACROS: PR_EXTERN
** PR_IMPLEMENT
** DESCRIPTION:
** These are only for externally visible routines and globals. For
** internal routines, just use "extern" for type checking and that
** will not export internal cross-file or forward-declared symbols.
** Define a macro for declaring procedures return types. We use this to
** deal with windoze specific type hackery for DLL definitions. Use
** PR_EXTERN when the prototype for the method is declared. Use
** PR_IMPLEMENT for the implementation of the method.
**
** Example:
** in dowhim.h
** PR_EXTERN( void ) DoWhatIMean( void );
** in dowhim.c
** PR_IMPLEMENT( void ) DoWhatIMean( void ) { return; }
**
**
***********************************************************************/
#if defined(WIN32)
#define PR_EXTERN(__type) extern _declspec(dllexport) __type
#define PR_IMPLEMENT(__type) _declspec(dllexport) __type
#define PR_EXTERN_DATA(__type) extern _declspec(dllexport) __type
#define PR_IMPLEMENT_DATA(__type) _declspec(dllexport) __type
#define PR_CALLBACK
#define PR_CALLBACK_DECL
#define PR_STATIC_CALLBACK(__x) static __x
#elif defined(WIN16)
#define PR_CALLBACK_DECL __cdecl
#if defined(_WINDLL)
#define PR_EXTERN(__type) extern __type _cdecl _export _loadds
#define PR_IMPLEMENT(__type) __type _cdecl _export _loadds
#define PR_EXTERN_DATA(__type) extern __type _export
#define PR_IMPLEMENT_DATA(__type) __type _export
#define PR_CALLBACK __cdecl __loadds
#define PR_STATIC_CALLBACK(__x) static __x PR_CALLBACK
#else /* this must be .EXE */
#define PR_EXTERN(__type) extern __type _cdecl _export
#define PR_IMPLEMENT(__type) __type _cdecl _export
#define PR_EXTERN_DATA(__type) extern __type _export
#define PR_IMPLEMENT_DATA(__type) __type _export
#define PR_CALLBACK __cdecl __loadds
#define PR_STATIC_CALLBACK(__x) __x PR_CALLBACK
#endif /* _WINDLL */
#elif defined(XP_MAC)
#define PR_EXTERN(__type) extern __declspec(export) __type
#define PR_IMPLEMENT(__type) __declspec(export) __type
#define PR_EXTERN_DATA(__type) extern __declspec(export) __type
#define PR_IMPLEMENT_DATA(__type) __declspec(export) __type
#define PR_CALLBACK
#define PR_CALLBACK_DECL
#define PR_STATIC_CALLBACK(__x) static __x
#elif defined(XP_OS2)
#define PR_EXTERN(__type) extern __type
#define PR_IMPLEMENT(__type) __type
#define PR_EXTERN_DATA(__type) extern __type
#define PR_IMPLEMENT_DATA(__type) __type
#define PR_CALLBACK
#define PR_CALLBACK_DECL
#define PR_STATIC_CALLBACK(__x) __x _Optlink
#else /* Unix */
#define PR_EXTERN(__type) extern __type
#define PR_IMPLEMENT(__type) __type
#define PR_EXTERN_DATA(__type) extern __type
#define PR_IMPLEMENT_DATA(__type) __type
#define PR_CALLBACK
#define PR_CALLBACK_DECL
#define PR_STATIC_CALLBACK(__x) static __x
#endif
#if !defined(NO_NSPR_10_SUPPORT)
#define PR_PUBLIC_API PR_IMPLEMENT
#endif
/***********************************************************************
** MACROS: PR_BEGIN_MACRO
** PR_END_MACRO
** DESCRIPTION:
** Macro body brackets so that macros with compound statement definitions
** behave syntactically more like functions when called.
***********************************************************************/
#define PR_BEGIN_MACRO do {
#define PR_END_MACRO } while (0)
/***********************************************************************
** MACROS: PR_BEGIN_EXTERN_C
** PR_END_EXTERN_C
** DESCRIPTION:
** Macro shorthands for conditional C++ extern block delimiters.
***********************************************************************/
#ifdef __cplusplus
#define PR_BEGIN_EXTERN_C extern "C" {
#define PR_END_EXTERN_C }
#else
#define PR_BEGIN_EXTERN_C
#define PR_END_EXTERN_C
#endif
/***********************************************************************
** MACROS: PR_BIT
** PR_BITMASK
** DESCRIPTION:
** Bit masking macros. XXX n must be <= 31 to be portable
***********************************************************************/
#define PR_BIT(n) ((PRUint32)1 << (n))
#define PR_BITMASK(n) (PR_BIT(n) - 1)
/***********************************************************************
** MACROS: PR_ROUNDUP
** PR_MIN
** PR_MAX
** DESCRIPTION:
** Commonly used macros for operations on compatible types.
***********************************************************************/
#define PR_ROUNDUP(x,y) ((((x)+((y)-1))/(y))*(y))
#define PR_MIN(x,y) ((x)<(y)?(x):(y))
#define PR_MAX(x,y) ((x)>(y)?(x):(y))
PR_BEGIN_EXTERN_C
/************************************************************************
** TYPES: PRUint8
** PRInt8
** DESCRIPTION:
** The int8 types are known to be 8 bits each. There is no type that
** is equivalent to a plain "char".
************************************************************************/
#if PR_BYTES_PER_BYTE == 1
typedef unsigned char PRUint8;
typedef signed char PRInt8;
#else
#error No suitable type for PRInt8/PRUint8
#endif
/************************************************************************
** TYPES: PRUint16
** PRInt16
** DESCRIPTION:
** The int16 types are known to be 16 bits each.
************************************************************************/
#if PR_BYTES_PER_SHORT == 2
typedef unsigned short PRUint16;
typedef short PRInt16;
#else
#error No suitable type for PRInt16/PRUint16
#endif
/************************************************************************
** TYPES: PRUint32
** PRInt32
** DESCRIPTION:
** The int32 types are known to be 32 bits each.
************************************************************************/
#if PR_BYTES_PER_INT == 4
typedef unsigned int PRUint32;
typedef int PRInt32;
#define PR_INT32(x) x
#define PR_UINT32(x) x ## U
#elif PR_BYTES_PER_LONG == 4
typedef unsigned long PRUint32;
typedef long PRInt32;
#define PR_INT32(x) x ## L
#define PR_UINT32(x) x ## UL
#else
#error No suitable type for PRInt32/PRUint32
#endif
/************************************************************************
** TYPES: PRUint64
** PRInt64
** DESCRIPTION:
** The int64 types are known to be 64 bits each. Care must be used when
** declaring variables of type PRUint64 or PRInt64. Different hardware
** architectures and even different compilers have varying support for
** 64 bit values. The only guaranteed portability requires the use of
** the LL_ macros (see prlong.h).
************************************************************************/
#ifdef HAVE_LONG_LONG
#if PR_BYTES_PER_LONG == 8
typedef long PRInt64;
typedef unsigned long PRUint64;
#elif defined(WIN16)
typedef __int64 PRInt64;
typedef unsigned __int64 PRUint64;
#elif defined(WIN32)
typedef __int64 PRInt64;
typedef unsigned __int64 PRUint64;
#else
typedef long long PRInt64;
typedef unsigned long long PRUint64;
#endif /* PR_BYTES_PER_LONG == 8 */
#else /* !HAVE_LONG_LONG */
typedef struct {
#ifdef IS_LITTLE_ENDIAN
PRUint32 lo, hi;
#else
PRUint32 hi, lo;
#endif
} PRInt64;
typedef PRInt64 PRUint64;
#endif /* !HAVE_LONG_LONG */
/************************************************************************
** TYPES: PRUintn
** PRIntn
** DESCRIPTION:
** The PRIntn types are most appropriate for automatic variables. They are
** guaranteed to be at least 16 bits, though various architectures may
** define them to be wider (e.g., 32 or even 64 bits). These types are
** never valid for fields of a structure.
************************************************************************/
#if PR_BYTES_PER_INT >= 2
typedef int PRIntn;
typedef unsigned int PRUintn;
#else
#error 'sizeof(int)' not sufficient for platform use
#endif
/************************************************************************
** TYPES: PRFloat64
** DESCRIPTION:
** NSPR's floating point type is always 64 bits.
************************************************************************/
typedef double PRFloat64;
/************************************************************************
** TYPES: PRSize
** DESCRIPTION:
** A type for representing the size of objects.
************************************************************************/
typedef size_t PRSize;
/************************************************************************
** TYPES: PRPtrDiff
** DESCRIPTION:
** A type for pointer difference. Variables of this type are suitable
** for storing a pointer or pointer sutraction.
************************************************************************/
typedef ptrdiff_t PRPtrdiff;
/************************************************************************
** TYPES: PRUptrdiff
** DESCRIPTION:
** A type for pointer difference. Variables of this type are suitable
** for storing a pointer or pointer sutraction.
************************************************************************/
typedef unsigned long PRUptrdiff;
/************************************************************************
** TYPES: PRBool
** DESCRIPTION:
** Use PRBool for variables and parameter types. Use PR_FALSE and PR_TRUE
** for clarity of target type in assignments and actual arguments. Use
** 'if (bool)', 'while (!bool)', '(bool) ? x : y' etc., to test booleans
** juast as you would C int-valued conditions.
************************************************************************/
typedef PRIntn PRBool;
#define PR_TRUE (PRIntn)1
#define PR_FALSE (PRIntn)0
/************************************************************************
** TYPES: PRPackedBool
** DESCRIPTION:
** Use PRPackedBOol within structs where bitfields are not desireable
** but minimum and consistant overhead matters.
************************************************************************/
typedef PRUint8 PRPackedBool;
/*
** Status code used by some routines that have a single point of failure or
** special status return.
*/
typedef enum { PR_FAILURE = -1, PR_SUCCESS = 0 } PRStatus;
#if defined(NO_NSPR_10_SUPPORT)
#else
/********* ???????????????? FIX ME ??????????????????????????? *****/
/********************** Some old definitions until pr=>ds transition is done ***/
/********************** Also, we are still using NSPR 1.0. GC ******************/
/*
** Fundamental NSPR macros, used nearly everywhere.
*/
/*
** Macro body brackets so that macros with compound statement definitions
** behave syntactically more like functions when called.
*/
#define NSPR_BEGIN_MACRO do {
#define NSPR_END_MACRO } while (0)
/*
** Macro shorthands for conditional C++ extern block delimiters.
*/
#ifdef NSPR_BEGIN_EXTERN_C
#undef NSPR_BEGIN_EXTERN_C
#endif
#ifdef NSPR_END_EXTERN_C
#undef NSPR_END_EXTERN_C
#endif
#ifdef __cplusplus
#define NSPR_BEGIN_EXTERN_C extern "C" {
#define NSPR_END_EXTERN_C }
#else
#define NSPR_BEGIN_EXTERN_C
#define NSPR_END_EXTERN_C
#endif
/*
** A PRWord is an integer that is the same size as a void*
*/
typedef long PRWord;
typedef unsigned long PRUword;
/********* ????????????? End Fix me ?????????????????????????????? *****/
#endif /* NO_NSPR_10_SUPPORT */
#if defined(XP_MAC) || defined(MINI_NSPR)
#include "protypes.h"
#ifndef NSPR20
#define NSPR20 1
#endif
#else
#include "obsolete/protypes.h"
#endif
PR_END_EXTERN_C
#endif /* prtypes_h___ */