ReactOS 0.4.16-dev-2207-geb15453
dict.c File Reference
#include "libxml.h"
#include <limits.h>
#include <string.h>
#include <time.h>
#include "private/dict.h"
#include "private/threads.h"
#include <libxml/parser.h>
#include <libxml/dict.h>
#include <libxml/xmlmemory.h>
#include <libxml/xmlstring.h>
Include dependency graph for dict.c:

Go to the source code of this file.

Classes

struct  _xmlDictStrings
 
struct  _xmlDict
 

Macros

#define IN_LIBXML
 
#define SIZE_MAX   ((size_t) -1)
 
#define MAX_FILL_NUM   7
 
#define MAX_FILL_DENOM   8
 
#define MIN_HASH_SIZE   8
 
#define MAX_HASH_SIZE   (1u << 31)
 
#define HASH_ROL31(x, n)   ((x) << (n) | ((x) & 0x7FFFFFFF) >> (31 - (n)))
 

Typedefs

typedef struct _xmlDictStrings xmlDictStrings
 
typedef xmlDictStringsxmlDictStringsPtr
 
typedef xmlHashedString xmlDictEntry
 

Functions

int xmlInitializeDict (void)
 
void xmlInitDictInternal (void)
 
void xmlDictCleanup (void)
 
void xmlCleanupDictInternal (void)
 
static const xmlCharxmlDictAddString (xmlDictPtr dict, const xmlChar *name, unsigned int namelen)
 
static const xmlCharxmlDictAddQString (xmlDictPtr dict, const xmlChar *prefix, unsigned int plen, const xmlChar *name, unsigned int namelen)
 
xmlDictPtr xmlDictCreate (void)
 
xmlDictPtr xmlDictCreateSub (xmlDictPtr sub)
 
int xmlDictReference (xmlDictPtr dict)
 
void xmlDictFree (xmlDictPtr dict)
 
int xmlDictOwns (xmlDictPtr dict, const xmlChar *str)
 
int xmlDictSize (xmlDictPtr dict)
 
size_t xmlDictSetLimit (xmlDictPtr dict, size_t limit)
 
size_t xmlDictGetUsage (xmlDictPtr dict)
 
static ATTRIBUTE_NO_SANITIZE_INTEGER unsigned xmlDictHashName (unsigned seed, const xmlChar *data, size_t maxLen, size_t *plen)
 
static ATTRIBUTE_NO_SANITIZE_INTEGER unsigned xmlDictHashQName (unsigned seed, const xmlChar *prefix, const xmlChar *name, size_t *pplen, size_t *plen)
 
unsigned xmlDictComputeHash (const xmlDict *dict, const xmlChar *string)
 
ATTRIBUTE_NO_SANITIZE_INTEGER unsigned xmlDictCombineHash (unsigned v1, unsigned v2)
 
: string

xmlDictLookupInternal: @dict: dict @prefix: optional QName prefix

@maybeLen: length of string or -1 if unknown @update: whether the string should be added

Internal lookup and update function.

static ATTRIBUTE_NO_SANITIZE_INTEGER xmlDictEntryxmlDictFindEntry (const xmlDict *dict, const xmlChar *prefix, const xmlChar *name, int len, unsigned hashValue, int *pfound)
 
static int xmlDictGrow (xmlDictPtr dict, unsigned size)
 
static ATTRIBUTE_NO_SANITIZE_INTEGER const xmlDictEntryxmlDictLookupInternal (xmlDictPtr dict, const xmlChar *prefix, const xmlChar *name, int maybeLen, int update)
 
: string key

xmlDictLookupHashed: @dict: dictionary

@len: length of the key, if -1 it is recomputed

Lookup a dictionary entry and add the string to the dictionary if it wasn't found.

Returns the dictionary entry.

const xmlCharxmlDictLookup (xmlDictPtr dict, const xmlChar *name, int len)
 
xmlHashedString xmlDictLookupHashed (xmlDictPtr dict, const xmlChar *name, int len)
 
: the name of the userdata

xmlDictExists: @dict: the dictionary

@len: the length of the name, if -1 it is recomputed

Check if a string exists in the dictionary.

Returns the internal copy of the name or NULL if not found.

const xmlCharxmlDictExists (xmlDictPtr dict, const xmlChar *name, int len)
 

Variables

static xmlMutex xmlDictMutex
 

and add it to the dictionary if

it wasn't found.

Returns the interned copy of the string or NULL if a memory allocation failed.

static xmlMutex xmlRngMutex
 
static unsigned globalRngState [2]
 
const xmlCharxmlDictQLookup (xmlDictPtr dict, const xmlChar *prefix, const xmlChar *name)
 
ATTRIBUTE_NO_SANITIZE_INTEGER void xmlInitRandom (void)
 
void xmlCleanupRandom (void)
 
static ATTRIBUTE_NO_SANITIZE_INTEGER unsigned xoroshiro64ss (unsigned *s)
 
unsigned xmlRandom (void)
 

Macro Definition Documentation

◆ HASH_ROL31

#define HASH_ROL31 (   x,
  n 
)    ((x) << (n) | ((x) & 0x7FFFFFFF) >> (31 - (n)))

Definition at line 517 of file dict.c.

◆ IN_LIBXML

#define IN_LIBXML

Definition at line 19 of file dict.c.

◆ MAX_FILL_DENOM

#define MAX_FILL_DENOM   8

Definition at line 39 of file dict.c.

◆ MAX_FILL_NUM

#define MAX_FILL_NUM   7

Definition at line 38 of file dict.c.

◆ MAX_HASH_SIZE

#define MAX_HASH_SIZE   (1u << 31)

Definition at line 41 of file dict.c.

◆ MIN_HASH_SIZE

#define MIN_HASH_SIZE   8

Definition at line 40 of file dict.c.

◆ SIZE_MAX

#define SIZE_MAX   ((size_t) -1)

Definition at line 35 of file dict.c.

Typedef Documentation

◆ xmlDictEntry

Definition at line 54 of file dict.c.

◆ xmlDictStrings

Definition at line 43 of file dict.c.

◆ xmlDictStringsPtr

Definition at line 44 of file dict.c.

Function Documentation

◆ xmlCleanupDictInternal()

void xmlCleanupDictInternal ( void  )

xmlCleanupDictInternal:

Free the dictionary mutex.

Definition at line 121 of file dict.c.

121 {
123}
XML_HIDDEN void xmlCleanupMutex(xmlMutexPtr mutex)
Definition: threads.c:166
static xmlMutex xmlDictMutex
Definition: dict.c:78

Referenced by xmlCleanupParser().

◆ xmlCleanupRandom()

void xmlCleanupRandom ( void  )

Definition at line 932 of file dict.c.

932 {
934}
static xmlMutex xmlRngMutex
Definition: dict.c:907

Referenced by xmlCleanupParser().

◆ xmlDictAddQString()

static const xmlChar * xmlDictAddQString ( xmlDictPtr  dict,
const xmlChar prefix,
unsigned int  plen,
const xmlChar name,
unsigned int  namelen 
)
static

Definition at line 204 of file dict.c.

206{
208 const xmlChar *ret;
209 size_t size = 0; /* + sizeof(_xmlDictStrings) == 1024 */
210 size_t limit = 0;
211
212 pool = dict->strings;
213 while (pool != NULL) {
214 if ((size_t)(pool->end - pool->free) > namelen + plen + 1)
215 goto found_pool;
216 if (pool->size > size) size = pool->size;
217 limit += pool->size;
218 pool = pool->next;
219 }
220 /*
221 * Not found, need to allocate
222 */
223 if (pool == NULL) {
224 if ((dict->limit > 0) && (limit > dict->limit)) {
225 return(NULL);
226 }
227
228 if (size == 0) size = 1000;
229 else size *= 4; /* exponential growth */
230 if (size < 4 * (namelen + plen + 1))
231 size = 4 * (namelen + plen + 1); /* just in case ! */
233 if (pool == NULL)
234 return(NULL);
235 pool->size = size;
236 pool->nbStrings = 0;
237 pool->free = &pool->array[0];
238 pool->end = &pool->array[size];
239 pool->next = dict->strings;
240 dict->strings = pool;
241 }
242found_pool:
243 ret = pool->free;
244 memcpy(pool->free, prefix, plen);
245 pool->free += plen;
246 *(pool->free++) = ':';
247 memcpy(pool->free, name, namelen);
248 pool->free += namelen;
249 *(pool->free++) = 0;
250 pool->nbStrings++;
251 return(ret);
252}
#define NULL
Definition: types.h:112
return ret
Definition: mutex.c:146
GLsizeiptr size
Definition: glext.h:5919
GLint namelen
Definition: glext.h:7232
GLint limit
Definition: glext.h:10326
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
xmlDictStrings * xmlDictStringsPtr
Definition: dict.c:44
xmlMallocFunc xmlMalloc
Definition: globals.c:193
size_t limit
Definition: dict.c:71
xmlDictStringsPtr strings
Definition: dict.c:65
Definition: name.c:39
Character const *const prefix
Definition: tempnam.cpp:195
unsigned char xmlChar
Definition: xmlstring.h:28

Referenced by xmlDictLookupInternal().

◆ xmlDictAddString()

static const xmlChar * xmlDictAddString ( xmlDictPtr  dict,
const xmlChar name,
unsigned int  namelen 
)
static

Definition at line 136 of file dict.c.

136 {
138 const xmlChar *ret;
139 size_t size = 0; /* + sizeof(_xmlDictStrings) == 1024 */
140 size_t limit = 0;
141
142 pool = dict->strings;
143 while (pool != NULL) {
144 if ((size_t)(pool->end - pool->free) > namelen)
145 goto found_pool;
146 if (pool->size > size) size = pool->size;
147 limit += pool->size;
148 pool = pool->next;
149 }
150 /*
151 * Not found, need to allocate
152 */
153 if (pool == NULL) {
154 if ((dict->limit > 0) && (limit > dict->limit)) {
155 return(NULL);
156 }
157
158 if (size == 0) {
159 size = 1000;
160 } else {
161 if (size < (SIZE_MAX - sizeof(xmlDictStrings)) / 4)
162 size *= 4; /* exponential growth */
163 else
164 size = SIZE_MAX - sizeof(xmlDictStrings);
165 }
166 if (size / 4 < namelen) {
167 if ((size_t) namelen + 0 < (SIZE_MAX - sizeof(xmlDictStrings)) / 4)
168 size = 4 * (size_t) namelen; /* just in case ! */
169 else
170 return(NULL);
171 }
173 if (pool == NULL)
174 return(NULL);
175 pool->size = size;
176 pool->nbStrings = 0;
177 pool->free = &pool->array[0];
178 pool->end = &pool->array[size];
179 pool->next = dict->strings;
180 dict->strings = pool;
181 }
182found_pool:
183 ret = pool->free;
184 memcpy(pool->free, name, namelen);
185 pool->free += namelen;
186 *(pool->free++) = 0;
187 pool->nbStrings++;
188 return(ret);
189}
#define SIZE_MAX
Definition: dict.c:35
struct _xmlDictStrings xmlDictStrings
Definition: dict.c:43

Referenced by xmlDictLookupInternal().

◆ xmlDictCleanup()

void xmlDictCleanup ( void  )

xmlDictCleanup:

DEPRECATED: This function is a no-op. Call xmlCleanupParser to free global state but see the warnings there. xmlCleanupParser should be only called once at program exit. In most cases, you don't have call cleanup functions at all.

Definition at line 112 of file dict.c.

112 {
113}

◆ xmlDictCombineHash()

ATTRIBUTE_NO_SANITIZE_INTEGER unsigned xmlDictCombineHash ( unsigned  v1,
unsigned  v2 
)

Definition at line 521 of file dict.c.

521 {
522 /*
523 * The upper bit of hash values is always set, so we have to operate on
524 * 31-bit hashes here.
525 */
526 v1 ^= v2;
527 v1 += HASH_ROL31(v2, 5);
528
529 return((v1 & 0xFFFFFFFF) | 0x80000000);
530}
GLfloat GLfloat v1
Definition: glext.h:6062
GLfloat GLfloat GLfloat v2
Definition: glext.h:6063
#define HASH_ROL31(x, n)
Definition: dict.c:517

Referenced by xmlParseStartTag2().

◆ xmlDictComputeHash()

unsigned xmlDictComputeHash ( const xmlDict dict,
const xmlChar string 
)

Definition at line 512 of file dict.c.

512 {
513 size_t len;
514 return(xmlDictHashName(dict->seed, string, SIZE_MAX, &len));
515}
GLenum GLsizei len
Definition: glext.h:6722
static ATTRIBUTE_NO_SANITIZE_INTEGER unsigned xmlDictHashName(unsigned seed, const xmlChar *data, size_t maxLen, size_t *plen)
Definition: dict.c:464
unsigned seed
Definition: dict.c:69

Referenced by xmlParserNsLookupSax(), and xmlParserNsUpdateSax().

◆ xmlDictCreate()

xmlDictPtr xmlDictCreate ( void  )

xmlDictCreate:

Create a new dictionary

Returns the newly created dictionary, or NULL if an error occurred.

Definition at line 262 of file dict.c.

262 {
263 xmlDictPtr dict;
264
266
267 dict = xmlMalloc(sizeof(xmlDict));
268 if (dict == NULL)
269 return(NULL);
270 dict->ref_counter = 1;
271 dict->limit = 0;
272
273 dict->size = 0;
274 dict->nbElems = 0;
275 dict->table = NULL;
276 dict->strings = NULL;
277 dict->subdict = NULL;
278 dict->seed = xmlRandom();
279#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
280 dict->seed = 0;
281#endif
282 return(dict);
283}
unsigned xmlRandom(void)
Definition: dict.c:951
XML_GLOBALS_PARSER XMLPUBFUN void xmlInitParser(void)
Definition: threads.c:569
Definition: dict.c:59
struct _xmlDict * subdict
Definition: dict.c:67
int ref_counter
Definition: dict.c:60
unsigned int nbElems
Definition: dict.c:64
size_t size
Definition: dict.c:63
xmlDictEntry * table
Definition: dict.c:62

Referenced by xmlDictCreateSub(), xmlInitSAXParserCtxt(), and xsltNewStylesheetInternal().

◆ xmlDictCreateSub()

xmlDictPtr xmlDictCreateSub ( xmlDictPtr  sub)

xmlDictCreateSub: @sub: an existing dictionary

Create a new dictionary, inheriting strings from the read-only dictionary @sub. On lookup, strings are first searched in the new dictionary, then in @sub, and if not found are created in the new dictionary.

Returns the newly created dictionary, or NULL if an error occurred.

Definition at line 297 of file dict.c.

297 {
298 xmlDictPtr dict = xmlDictCreate();
299
300 if ((dict != NULL) && (sub != NULL)) {
301 dict->seed = sub->seed;
302 dict->subdict = sub;
304 }
305 return(dict);
306}
int xmlDictReference(xmlDictPtr dict)
Definition: dict.c:317
xmlDictPtr xmlDictCreate(void)
Definition: dict.c:262

Referenced by xsltNewTransformContext().

◆ xmlDictExists()

const xmlChar * xmlDictExists ( xmlDictPtr  dict,
const xmlChar name,
int  len 
)

Definition at line 872 of file dict.c.

872 {
873 const xmlDictEntry *entry;
874
876 if (entry == NULL)
877 return(NULL);
878 return(entry->name);
879}
uint32_t entry
Definition: isohybrid.c:63
static ATTRIBUTE_NO_SANITIZE_INTEGER const xmlDictEntry * xmlDictLookupInternal(xmlDictPtr dict, const xmlChar *prefix, const xmlChar *name, int maybeLen, int update)
Definition: dict.c:678

◆ xmlDictFindEntry()

static ATTRIBUTE_NO_SANITIZE_INTEGER xmlDictEntry * xmlDictFindEntry ( const xmlDict dict,
const xmlChar prefix,
const xmlChar name,
int  len,
unsigned  hashValue,
int pfound 
)
static

Definition at line 547 of file dict.c.

549 {
551 unsigned mask, pos, displ;
552 int found = 0;
553
554 mask = dict->size - 1;
555 pos = hashValue & mask;
556 entry = &dict->table[pos];
557
558 if (entry->hashValue != 0) {
559 /*
560 * Robin hood hashing: abort if the displacement of the entry
561 * is smaller than the displacement of the key we look for.
562 * This also stops at the correct position when inserting.
563 */
564 displ = 0;
565
566 do {
567 if (entry->hashValue == hashValue) {
568 if (prefix == NULL) {
569 /*
570 * name is not necessarily null-terminated.
571 */
572 if ((strncmp((const char *) entry->name,
573 (const char *) name, len) == 0) &&
574 (entry->name[len] == 0)) {
575 found = 1;
576 break;
577 }
578 } else {
579 if (xmlStrQEqual(prefix, name, entry->name)) {
580 found = 1;
581 break;
582 }
583 }
584 }
585
586 displ++;
587 pos++;
588 entry++;
589 if ((pos & mask) == 0)
590 entry = dict->table;
591 } while ((entry->hashValue != 0) &&
592 (((pos - entry->hashValue) & mask) >= displ));
593 }
594
595 *pfound = found;
596 return(entry);
597}
_ACRTIMP int __cdecl strncmp(const char *, const char *, size_t)
Definition: string.c:3330
GLenum GLint GLuint mask
Definition: glext.h:6028
XMLPUBFUN int xmlStrQEqual(const xmlChar *pref, const xmlChar *name, const xmlChar *str)
Definition: xmlstring.c:188

Referenced by xmlDictLookupInternal().

◆ xmlDictFree()

void xmlDictFree ( xmlDictPtr  dict)

xmlDictFree: @dict: the dictionary

Free the hash @dict and its contents. The userdata is deallocated with @f if provided.

Definition at line 333 of file dict.c.

333 {
334 xmlDictStringsPtr pool, nextp;
335
336 if (dict == NULL)
337 return;
338
339 /* decrement the counter, it may be shared by a parser and docs */
341 dict->ref_counter--;
342 if (dict->ref_counter > 0) {
344 return;
345 }
346
348
349 if (dict->subdict != NULL) {
350 xmlDictFree(dict->subdict);
351 }
352
353 if (dict->table) {
354 xmlFree(dict->table);
355 }
356 pool = dict->strings;
357 while (pool != NULL) {
358 nextp = pool->next;
359 xmlFree(pool);
360 pool = nextp;
361 }
362 xmlFree(dict);
363}
XMLPUBFUN void xmlMutexLock(xmlMutexPtr tok)
Definition: threads.c:201
XMLPUBFUN void xmlMutexUnlock(xmlMutexPtr tok)
Definition: threads.c:225
void xmlDictFree(xmlDictPtr dict)
Definition: dict.c:333
xmlFreeFunc xmlFree
Definition: globals.c:184

Referenced by xmlDictFree(), xmlFreeParserCtxt(), xmlHashFree(), xmlParseBalancedChunkMemoryInternal(), xmlParseExternalEntityPrivate(), xmlParseInNodeContext(), xslt_doc_default_loader(), xsltDocDefaultLoaderFunc(), xsltFreeStylesheet(), xsltFreeTransformContext(), and xsltParseStylesheetUser().

◆ xmlDictGetUsage()

size_t xmlDictGetUsage ( xmlDictPtr  dict)

xmlDictGetUsage: @dict: the dictionary

Get how much memory is used by a dictionary for strings Added in 2.9.0

Returns the amount of strings allocated

Definition at line 441 of file dict.c.

441 {
443 size_t limit = 0;
444
445 if (dict == NULL)
446 return(0);
447 pool = dict->strings;
448 while (pool != NULL) {
449 limit += pool->size;
450 pool = pool->next;
451 }
452 return(limit);
453}

◆ xmlDictGrow()

static int xmlDictGrow ( xmlDictPtr  dict,
unsigned  size 
)
static

xmlDictGrow: @dict: dictionary @size: new size of the dictionary

Resize the dictionary hash table.

Returns 0 in case of success, -1 if a memory allocation failed.

Definition at line 609 of file dict.c.

609 {
610 const xmlDictEntry *oldentry, *oldend, *end;
612 unsigned oldsize, i;
613
614 /* Add 0 to avoid spurious -Wtype-limits warning on 64-bit GCC */
615 if ((size_t) size + 0 > SIZE_MAX / sizeof(table[0]))
616 return(-1);
617 table = xmlMalloc(size * sizeof(table[0]));
618 if (table == NULL)
619 return(-1);
620 memset(table, 0, size * sizeof(table[0]));
621
622 oldsize = dict->size;
623 if (oldsize == 0)
624 goto done;
625
626 oldend = &dict->table[oldsize];
627 end = &table[size];
628
629 /*
630 * Robin Hood sorting order is maintained if we
631 *
632 * - compute dict indices with modulo
633 * - resize by an integer factor
634 * - start to copy from the beginning of a probe sequence
635 */
636 oldentry = dict->table;
637 while (oldentry->hashValue != 0) {
638 if (++oldentry >= oldend)
639 oldentry = dict->table;
640 }
641
642 for (i = 0; i < oldsize; i++) {
643 if (oldentry->hashValue != 0) {
644 xmlDictEntry *entry = &table[oldentry->hashValue & (size - 1)];
645
646 while (entry->hashValue != 0) {
647 if (++entry >= end)
648 entry = table;
649 }
650 *entry = *oldentry;
651 }
652
653 if (++oldentry >= oldend)
654 oldentry = dict->table;
655 }
656
657 xmlFree(dict->table);
658
659done:
660 dict->table = table;
661 dict->size = size;
662
663 return(0);
664}
GLuint GLuint end
Definition: gl.h:1545
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define memset(x, y, z)
Definition: compat.h:39
unsigned hashValue
Definition: dict.h:49

Referenced by xmlDictLookupInternal().

◆ xmlDictHashName()

static ATTRIBUTE_NO_SANITIZE_INTEGER unsigned xmlDictHashName ( unsigned  seed,
const xmlChar data,
size_t  maxLen,
size_t plen 
)
static

Definition at line 464 of file dict.c.

465 {
466 unsigned h1, h2;
467 size_t i;
468
469 HASH_INIT(h1, h2, seed);
470
471 for (i = 0; i < maxLen && data[i]; i++) {
472 HASH_UPDATE(h1, h2, data[i]);
473 }
474
475 HASH_FINISH(h1, h2);
476
477 *plen = i;
478 return(h2 | MAX_HASH_SIZE);
479}
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define MAX_HASH_SIZE
Definition: dict.c:41
#define HASH_UPDATE(h1, h2, ch)
Definition: dict.h:28
#define HASH_FINISH(h1, h2)
Definition: dict.h:38
#define HASH_INIT(h1, h2, seed)
Definition: dict.h:22

Referenced by xmlDictComputeHash(), and xmlDictLookupInternal().

◆ xmlDictHashQName()

static ATTRIBUTE_NO_SANITIZE_INTEGER unsigned xmlDictHashQName ( unsigned  seed,
const xmlChar prefix,
const xmlChar name,
size_t pplen,
size_t plen 
)
static

Definition at line 483 of file dict.c.

484 {
485 unsigned h1, h2;
486 size_t i;
487
488 HASH_INIT(h1, h2, seed);
489
490 for (i = 0; prefix[i] != 0; i++) {
491 HASH_UPDATE(h1, h2, prefix[i]);
492 }
493 *pplen = i;
494
495 HASH_UPDATE(h1, h2, ':');
496
497 for (i = 0; name[i] != 0; i++) {
498 HASH_UPDATE(h1, h2, name[i]);
499 }
500 *plen = i;
501
502 HASH_FINISH(h1, h2);
503
504 /*
505 * Always set the upper bit of hash values since 0 means an unoccupied
506 * bucket.
507 */
508 return(h2 | MAX_HASH_SIZE);
509}

Referenced by xmlDictLookupInternal().

◆ xmlDictLookup()

◆ xmlDictLookupHashed()

xmlHashedString xmlDictLookupHashed ( xmlDictPtr  dict,
const xmlChar name,
int  len 
)

Definition at line 845 of file dict.c.

845 {
846 const xmlDictEntry *entry;
848
850
851 if (entry == NULL) {
852 ret.name = NULL;
853 ret.hashValue = 0;
854 } else {
855 ret = *entry;
856 }
857
858 return(ret);
859}

Referenced by xmlAddDefAttrs(), xmlParseInNodeContext(), xmlParseNCName(), xmlParseNCNameComplex(), xmlParseQNameHashed(), and xmlParseStartTag2().

◆ xmlDictLookupInternal()

static ATTRIBUTE_NO_SANITIZE_INTEGER const xmlDictEntry * xmlDictLookupInternal ( xmlDictPtr  dict,
const xmlChar prefix,
const xmlChar name,
int  maybeLen,
int  update 
)
static

Definition at line 678 of file dict.c.

679 {
681 const xmlChar *ret;
682 unsigned hashValue;
683 size_t maxLen, len, plen, klen;
684 int found = 0;
685
686 if ((dict == NULL) || (name == NULL))
687 return(NULL);
688
689 maxLen = (maybeLen < 0) ? SIZE_MAX : (size_t) maybeLen;
690
691 if (prefix == NULL) {
692 hashValue = xmlDictHashName(dict->seed, name, maxLen, &len);
693 if (len > INT_MAX / 2)
694 return(NULL);
695 klen = len;
696 } else {
697 hashValue = xmlDictHashQName(dict->seed, prefix, name, &plen, &len);
698 if ((len > INT_MAX / 2) || (plen >= INT_MAX / 2 - len))
699 return(NULL);
700 klen = plen + 1 + len;
701 }
702
703 if ((dict->limit > 0) && (klen >= dict->limit))
704 return(NULL);
705
706 /*
707 * Check for an existing entry
708 */
709 if (dict->size > 0)
710 entry = xmlDictFindEntry(dict, prefix, name, klen, hashValue, &found);
711 if (found)
712 return(entry);
713
714 if ((dict->subdict != NULL) && (dict->subdict->size > 0)) {
715 xmlDictEntry *subEntry;
716 unsigned subHashValue;
717
718 if (prefix == NULL)
719 subHashValue = xmlDictHashName(dict->subdict->seed, name, len,
720 &len);
721 else
722 subHashValue = xmlDictHashQName(dict->subdict->seed, prefix, name,
723 &plen, &len);
724 subEntry = xmlDictFindEntry(dict->subdict, prefix, name, klen,
725 subHashValue, &found);
726 if (found)
727 return(subEntry);
728 }
729
730 if (!update)
731 return(NULL);
732
733 /*
734 * Grow the hash table if needed
735 */
736 if (dict->nbElems + 1 > dict->size / MAX_FILL_DENOM * MAX_FILL_NUM) {
737 unsigned newSize, mask, displ, pos;
738
739 if (dict->size == 0) {
740 newSize = MIN_HASH_SIZE;
741 } else {
742 if (dict->size >= MAX_HASH_SIZE)
743 return(NULL);
744 newSize = dict->size * 2;
745 }
746 if (xmlDictGrow(dict, newSize) != 0)
747 return(NULL);
748
749 /*
750 * Find new entry
751 */
752 mask = dict->size - 1;
753 displ = 0;
754 pos = hashValue & mask;
755 entry = &dict->table[pos];
756
757 while ((entry->hashValue != 0) &&
758 ((pos - entry->hashValue) & mask) >= displ) {
759 displ++;
760 pos++;
761 entry++;
762 if ((pos & mask) == 0)
763 entry = dict->table;
764 }
765 }
766
767 if (prefix == NULL)
768 ret = xmlDictAddString(dict, name, len);
769 else
770 ret = xmlDictAddQString(dict, prefix, plen, name, len);
771 if (ret == NULL)
772 return(NULL);
773
774 /*
775 * Shift the remainder of the probe sequence to the right
776 */
777 if (entry->hashValue != 0) {
778 const xmlDictEntry *end = &dict->table[dict->size];
779 const xmlDictEntry *cur = entry;
780
781 do {
782 cur++;
783 if (cur >= end)
784 cur = dict->table;
785 } while (cur->hashValue != 0);
786
787 if (cur < entry) {
788 /*
789 * If we traversed the end of the buffer, handle the part
790 * at the start of the buffer.
791 */
792 memmove(&dict->table[1], dict->table,
793 (char *) cur - (char *) dict->table);
794 cur = end - 1;
795 dict->table[0] = *cur;
796 }
797
798 memmove(&entry[1], entry, (char *) cur - (char *) entry);
799 }
800
801 /*
802 * Populate entry
803 */
804 entry->hashValue = hashValue;
805 entry->name = ret;
806
807 dict->nbElems++;
808
809 return(entry);
810}
#define INT_MAX
Definition: limits.h:26
FxCollectionEntry * cur
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
static const xmlChar * xmlDictAddQString(xmlDictPtr dict, const xmlChar *prefix, unsigned int plen, const xmlChar *name, unsigned int namelen)
Definition: dict.c:204
#define MIN_HASH_SIZE
Definition: dict.c:40
static ATTRIBUTE_NO_SANITIZE_INTEGER unsigned xmlDictHashQName(unsigned seed, const xmlChar *prefix, const xmlChar *name, size_t *pplen, size_t *plen)
Definition: dict.c:483
#define MAX_FILL_DENOM
Definition: dict.c:39
static int xmlDictGrow(xmlDictPtr dict, unsigned size)
Definition: dict.c:609
static const xmlChar * xmlDictAddString(xmlDictPtr dict, const xmlChar *name, unsigned int namelen)
Definition: dict.c:136
static ATTRIBUTE_NO_SANITIZE_INTEGER xmlDictEntry * xmlDictFindEntry(const xmlDict *dict, const xmlChar *prefix, const xmlChar *name, int len, unsigned hashValue, int *pfound)
Definition: dict.c:547
#define MAX_FILL_NUM
Definition: dict.c:38

Referenced by xmlDictExists(), xmlDictLookup(), xmlDictLookupHashed(), and xmlDictQLookup().

◆ xmlDictOwns()

int xmlDictOwns ( xmlDictPtr  dict,
const xmlChar str 
)

xmlDictOwns: @dict: the dictionary @str: the string

check if a string is owned by the dictionary

Returns 1 if true, 0 if false and -1 in case of error -1 in case of error

Definition at line 376 of file dict.c.

376 {
378
379 if ((dict == NULL) || (str == NULL))
380 return(-1);
381 pool = dict->strings;
382 while (pool != NULL) {
383 if ((str >= &pool->array[0]) && (str <= pool->free))
384 return(1);
385 pool = pool->next;
386 }
387 if (dict->subdict)
388 return(xmlDictOwns(dict->subdict, str));
389 return(0);
390}
#define free
Definition: debug_ros.c:5
const WCHAR * str
int xmlDictOwns(xmlDictPtr dict, const xmlChar *str)
Definition: dict.c:376

Referenced by xmlDictOwns(), xmlFreeAttribute(), xmlFreeDocElementContent(), xmlHashUpdateInternal(), xmlParseEnumerationType(), xmlParseNotationType(), xmlSAX2ExternalSubset(), xmlSAX2Text(), xsltAttrListTemplateProcess(), xsltAttrTemplateProcess(), xsltCopyText(), xsltParseTemplateContent(), and xsltPreprocessStylesheet().

◆ xmlDictQLookup()

const xmlChar * xmlDictQLookup ( xmlDictPtr  dict,
const xmlChar prefix,
const xmlChar name 
)

Definition at line 894 of file dict.c.

894 {
895 const xmlDictEntry *entry;
896
897 entry = xmlDictLookupInternal(dict, prefix, name, -1, 1);
898 if (entry == NULL)
899 return(NULL);
900 return(entry->name);
901}

Referenced by xmlSAX2StartElementNs(), xsltApplyStylesheetInternal(), and xsltDocumentElem().

◆ xmlDictReference()

int xmlDictReference ( xmlDictPtr  dict)

xmlDictReference: @dict: the dictionary

Increment the reference counter of a dictionary

Returns 0 in case of success and -1 in case of error

Definition at line 317 of file dict.c.

317 {
318 if (dict == NULL) return -1;
320 dict->ref_counter++;
322 return(0);
323}

Referenced by xmlDictCreateSub(), xmlHashCreateDict(), xmlParseBalancedChunkMemoryInternal(), xmlParseExternalEntityPrivate(), xmlSAX2StartDocument(), xslt_doc_default_loader(), xsltApplyStylesheetInternal(), xsltCreateRVT(), xsltDocDefaultLoaderFunc(), xsltDocumentElem(), xsltLoadStylesheetPI(), and xsltParseStylesheetUser().

◆ xmlDictSetLimit()

size_t xmlDictSetLimit ( xmlDictPtr  dict,
size_t  limit 
)

xmlDictSetLimit: @dict: the dictionary @limit: the limit in bytes

Set a size limit for the dictionary Added in 2.9.0

Returns the previous limit of the dictionary or 0

Definition at line 421 of file dict.c.

421 {
422 size_t ret;
423
424 if (dict == NULL)
425 return(0);
426 ret = dict->limit;
427 dict->limit = limit;
428 return(ret);
429}

Referenced by xmlCtxtUseOptionsInternal(), and xmlInitSAXParserCtxt().

◆ xmlDictSize()

int xmlDictSize ( xmlDictPtr  dict)

xmlDictSize: @dict: the dictionary

Query the number of elements installed in the hash @dict.

Returns the number of elements in the dictionary or -1 in case of error

Definition at line 402 of file dict.c.

402 {
403 if (dict == NULL)
404 return(-1);
405 if (dict->subdict)
406 return(dict->nbElems + dict->subdict->nbElems);
407 return(dict->nbElems);
408}

◆ xmlInitDictInternal()

void xmlInitDictInternal ( void  )

xmlInitDictInternal:

Initialize mutex.

Definition at line 99 of file dict.c.

99 {
101}
XML_HIDDEN void xmlInitMutex(xmlMutexPtr mutex)
Definition: threads.c:128

Referenced by xmlInitParser().

◆ xmlInitializeDict()

int xmlInitializeDict ( void  )

xmlInitializeDict:

DEPRECATED: Alias for xmlInitParser.

Returns 0.

Definition at line 88 of file dict.c.

88 {
90 return(0);
91}

◆ xmlInitRandom()

Definition at line 918 of file dict.c.

918 {
919 int var;
920
922
923 /* TODO: Get seed values from system PRNG */
924
926 HASH_ROL((unsigned) (size_t) &xmlInitRandom, 8);
927 globalRngState[1] = HASH_ROL((unsigned) (size_t) &xmlRngMutex, 16) ^
928 HASH_ROL((unsigned) (size_t) &var, 24);
929}
__u16 time
Definition: mkdosfs.c:8
const char * var
Definition: shader.c:5666
static unsigned(__cdecl *hash_bstr)(bstr_t s)
ATTRIBUTE_NO_SANITIZE_INTEGER void xmlInitRandom(void)
Definition: dict.c:918
static unsigned globalRngState[2]
Definition: dict.c:909
#define HASH_ROL(x, n)
Definition: dict.h:12

Referenced by xmlInitParser(), and xmlInitRandom().

◆ xmlRandom()

unsigned xmlRandom ( void  )

Definition at line 951 of file dict.c.

951 {
952#ifdef XML_THREAD_LOCAL
953 if (!localRngInitialized) {
955 localRngState[0] = xoroshiro64ss(globalRngState);
956 localRngState[1] = xoroshiro64ss(globalRngState);
957 localRngInitialized = 1;
959 }
960
961 return(xoroshiro64ss(localRngState));
962#else
963 unsigned ret;
964
968
969 return(ret);
970#endif
971}
static ATTRIBUTE_NO_SANITIZE_INTEGER unsigned xoroshiro64ss(unsigned *s)
Definition: dict.c:938

Referenced by xmlDictCreate(), and xmlHashCreate().

◆ xoroshiro64ss()

static ATTRIBUTE_NO_SANITIZE_INTEGER unsigned xoroshiro64ss ( unsigned s)
static

Definition at line 938 of file dict.c.

938 {
939 unsigned s0 = s[0];
940 unsigned s1 = s[1];
941 unsigned result = HASH_ROL(s0 * 0x9E3779BB, 5) * 5;
942
943 s1 ^= s0;
944 s[0] = HASH_ROL(s0, 26) ^ s1 ^ (s1 << 9);
945 s[1] = HASH_ROL(s1, 13);
946
947 return(result & 0xFFFFFFFF);
948}
GLdouble s
Definition: gl.h:2039
GLuint64EXT * result
Definition: glext.h:11304
struct S1 s1

Referenced by xmlRandom().

Variable Documentation

◆ globalRngState

unsigned globalRngState[2]
static

Definition at line 909 of file dict.c.

Referenced by xmlInitRandom(), and xmlRandom().

◆ xmlDictMutex

xmlMutex xmlDictMutex
static

Definition at line 78 of file dict.c.

Referenced by xmlCleanupDictInternal(), xmlDictFree(), xmlDictReference(), and xmlInitDictInternal().

◆ xmlRngMutex

xmlMutex xmlRngMutex
static

Definition at line 907 of file dict.c.

Referenced by xmlCleanupRandom(), xmlInitRandom(), and xmlRandom().