Skip to content

Commit

Permalink
expat 2017-07-13 (634015b4)
Browse files Browse the repository at this point in the history
Code extracted from:

    https://gitlab.kitware.com/third-party/expat.git

at commit 634015b4ebf908c8131020ab3e97dea33a9e0b19 (vtk/update-to-2.2.2).
  • Loading branch information
kwrobot authored and mathstuf committed Jul 13, 2017
1 parent d2e8b9d commit 3b4e3be
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 42 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ project(expat)
cmake_minimum_required(VERSION 2.6)
set(PACKAGE_BUGREPORT "[email protected]")
set(PACKAGE_NAME "expat")
set(PACKAGE_VERSION "2.2.1")
set(PACKAGE_VERSION "2.2.2")
set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
set(PACKAGE_TARNAME "${PACKAGE_NAME}")

Expand Down Expand Up @@ -99,7 +99,7 @@ if (FALSE) # XXX(kitware): Use VTK's build macros.
add_library(expat ${_SHARED} ${expat_SRCS})

set(LIBCURRENT 7) # sync
set(LIBREVISION 3) # with
set(LIBREVISION 4) # with
set(LIBAGE 6) # configure.ac!
math(EXPR LIBCURRENT_MINUS_AGE "${LIBCURRENT} - ${LIBAGE}")

Expand Down
3 changes: 3 additions & 0 deletions ConfigureChecks.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ check_include_file("sys/types.h" HAVE_SYS_TYPES_H)
check_include_file("unistd.h" HAVE_UNISTD_H)

check_function_exists("getpagesize" HAVE_GETPAGESIZE)
check_function_exists("getrandom" HAVE_GETRANDOM)
check_function_exists("SYS_getrandom" HAVE_SYSCALL_GETRANDOM)
check_function_exists("arc4random_buf" HAVE_ARC4RANDOM_BUF)
check_function_exists("bcopy" HAVE_BCOPY)
check_symbol_exists("memmove" "string.h" HAVE_MEMMOVE)
check_function_exists("mmap" HAVE_MMAP)
Expand Down
2 changes: 1 addition & 1 deletion README
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

Expat, Release 2.2.1
Expat, Release 2.2.2

This is Expat, a C library for parsing XML, written by James Clark.
Expat is a stream-oriented XML parser. This means that you register
Expand Down
12 changes: 12 additions & 0 deletions expat_config.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@
/* Define to 1 if you have the `memmove' function. */
#cmakedefine HAVE_MEMMOVE

/* Define to 1 if you have the `getrandom' function. */
#cmakedefine HAVE_GETRANDOM

/* Define to 1 if you have the `SYS_getrandom' function. */
#cmakedefine HAVE_SYSCALL_GETRANDOM

/* Define to 1 if you have the `arc4random_buf' function. */
#cmakedefine HAVE_ARC4RANDOM_BUF

/* XXX(kitware): VTK is fine with low entropy. */
#define XML_POOR_ENTROPY

/* Define to 1 if you have the <memory.h> header file. */
#cmakedefine HAVE_MEMORY_H

Expand Down
3 changes: 1 addition & 2 deletions lib/expat.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ extern "C" {
struct XML_ParserStruct;
typedef struct XML_ParserStruct *XML_Parser;

/* Should this be defined using stdbool.h when C99 is available? */
typedef unsigned char XML_Bool;
#define XML_TRUE ((XML_Bool) 1)
#define XML_FALSE ((XML_Bool) 0)
Expand Down Expand Up @@ -1051,7 +1050,7 @@ XML_GetFeatureList(void);
*/
#define XML_MAJOR_VERSION 2
#define XML_MINOR_VERSION 2
#define XML_MICRO_VERSION 1
#define XML_MICRO_VERSION 2

#ifdef __cplusplus
}
Expand Down
59 changes: 43 additions & 16 deletions lib/siphash.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,31 @@
* siphash.h - SipHash-2-4 in a single header file
* --------------------------------------------------------------------------
* Derived by William Ahern from the reference implementation[1] published[2]
* by Jean-Philippe Aumasson and Daniel J. Berstein. Licensed in kind.
* by Jean-Philippe Aumasson and Daniel J. Berstein.
* Minimal changes by Sebastian Pipping on top, details below.
* Minimal changes by Sebastian Pipping and Victor Stinner on top, see below.
* Licensed under the CC0 Public Domain Dedication license.
*
* 1. https://www.131002.net/siphash/siphash24.c
* 2. https://www.131002.net/siphash/
* --------------------------------------------------------------------------
* HISTORY:
*
* 2017-06-10 (Sebastian Pipping)
* 2017-07-05 (Sebastian Pipping)
* - Use _SIP_ULL macro to not require a C++11 compiler if compiled as C++
* - Add const qualifiers at two places
* - Ensure <=80 characters line length (assuming tab width 4)
*
* 2017-06-23 (Victor Stinner)
* - Address Win64 compile warnings
*
* 2017-06-18 (Sebastian Pipping)
* - Clarify license note in the header
* - Address C89 issues:
* - Stop using inline keyword (and let compiler decide)
* - Turn integer suffix ULL to UL
* - Replace _Bool by int
* - Turn macro siphash24 into a function
* - Address invalid conversion (void pointer) by explicit cast
* - Address lack of stdint.h for Visual Studio 2003 to 2008
* - Always expose sip24_valid (for self-tests)
*
* 2012-11-04 - Born. (William Ahern)
Expand Down Expand Up @@ -76,7 +83,23 @@
#define SIPHASH_H

#include <stddef.h> /* size_t */
#include <stdint.h> /* uint64_t uint32_t uint8_t */

#if defined(_WIN32) && defined(_MSC_VER) && (_MSC_VER < 1600)
/* For vs2003/7.1 up to vs2008/9.0; _MSC_VER 1600 is vs2010/10.0 */
typedef unsigned __int8 uint8_t;
typedef unsigned __int32 uint32_t;
typedef unsigned __int64 uint64_t;
#else
#include <stdint.h> /* uint64_t uint32_t uint8_t */
#endif


/*
* Workaround to not require a C++11 compiler for using ULL suffix
* if this code is included and compiled as C++; related GCC warning is:
* warning: use of C++11 long long integer constant [-Wlong-long]
*/
#define _SIP_ULL(high, low) (((uint64_t)high << 32) | low)


#define SIP_ROTL(x, b) (uint64_t)(((x) << (b)) | ( (x) >> (64 - (b))))
Expand Down Expand Up @@ -158,11 +181,12 @@ static void sip_round(struct siphash *H, const int rounds) {
} /* sip_round() */


static struct siphash *sip24_init(struct siphash *H, const struct sipkey *key) {
H->v0 = 0x736f6d6570736575UL ^ key->k[0];
H->v1 = 0x646f72616e646f6dUL ^ key->k[1];
H->v2 = 0x6c7967656e657261UL ^ key->k[0];
H->v3 = 0x7465646279746573UL ^ key->k[1];
static struct siphash *sip24_init(struct siphash *H,
const struct sipkey *key) {
H->v0 = _SIP_ULL(0x736f6d65U, 0x70736575U) ^ key->k[0];
H->v1 = _SIP_ULL(0x646f7261U, 0x6e646f6dU) ^ key->k[1];
H->v2 = _SIP_ULL(0x6c796765U, 0x6e657261U) ^ key->k[0];
H->v3 = _SIP_ULL(0x74656462U, 0x79746573U) ^ key->k[1];

H->p = H->buf;
H->c = 0;
Expand All @@ -173,7 +197,8 @@ static struct siphash *sip24_init(struct siphash *H, const struct sipkey *key) {

#define sip_endof(a) (&(a)[sizeof (a) / sizeof *(a)])

static struct siphash *sip24_update(struct siphash *H, const void *src, size_t len) {
static struct siphash *sip24_update(struct siphash *H, const void *src,
size_t len) {
const unsigned char *p = (const unsigned char *)src, *pe = p + len;
uint64_t m;

Expand All @@ -198,7 +223,7 @@ static struct siphash *sip24_update(struct siphash *H, const void *src, size_t l


static uint64_t sip24_final(struct siphash *H) {
char left = H->p - H->buf;
const char left = (char)(H->p - H->buf);
uint64_t b = (H->c + left) << 56;

switch (left) {
Expand All @@ -222,7 +247,8 @@ static uint64_t sip24_final(struct siphash *H) {
} /* sip24_final() */


static uint64_t siphash24(const void *src, size_t len, const struct sipkey *key) {
static uint64_t siphash24(const void *src, size_t len,
const struct sipkey *key) {
struct siphash state = SIPHASH_INITIALIZER;
return sip24_final(sip24_update(sip24_init(&state, key), src, len));
} /* siphash24() */
Expand Down Expand Up @@ -310,10 +336,11 @@ static int sip24_valid(void) {
struct sipkey k;
size_t i;

sip_tokey(&k, "\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017");
sip_tokey(&k, "\000\001\002\003\004\005\006\007\010\011"
"\012\013\014\015\016\017");

for (i = 0; i < sizeof in; ++i) {
in[i] = i;
in[i] = (unsigned char)i;

if (siphash24(in, i, &k) != SIP_U8TO64_LE(vectors[i]))
return 0;
Expand All @@ -328,7 +355,7 @@ static int sip24_valid(void) {
#include <stdio.h>

int main(void) {
int ok = sip24_valid();
const int ok = sip24_valid();

if (ok)
puts("OK");
Expand Down
Loading

0 comments on commit 3b4e3be

Please sign in to comment.