Skip to content

Commit

Permalink
Do not use a header-file names endian.h, embed declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
eddelbuettel committed Jun 22, 2024
1 parent 6d5d746 commit e07137a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 29 deletions.
4 changes: 2 additions & 2 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

* DESCRIPTION (Version, Date): Roll micro version and date

* src/endian.h: Use endian-ness definition from Rconfig.h
* src/digest.c (is_big_endian): Define one-line helper
* src/digest.c (is_big_endian): Use endian-ness definition from
Rconfig.h and define one-line helper

* inst/tinytest/test_digest.R: Skip spookyhash test on big endian

Expand Down
23 changes: 22 additions & 1 deletion src/digest.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
#include "pmurhash.h"
#include "blake3.h"
#include "crc32c.h"
#include "endian.h"

#ifdef _WIN32
#include <Windows.h>
Expand Down Expand Up @@ -622,6 +621,28 @@ SEXP vdigest(SEXP Txt, SEXP Algo, SEXP Length, SEXP Skip, SEXP Leave_raw, SEXP S
return ans;
}


// Also already used in sha2.h
//
// We can rely on WORDS_BIGENDIAN only be defined on big endian systems thanks to Rconfig.
//
// A number of other #define based tests are in other source files here for different hash
// algorithm implementations notably crc32c, pmurhash, sha2 and xxhash
//
// A small and elegant test is also in package qs based on https://stackoverflow.com/a/1001373

// edd 02 Dec 2013 use Rconfig.h to define BYTE_ORDER, unless already defined
#ifndef BYTE_ORDER
// see sha2.c comments, and on the internet at large
#define LITTLE_ENDIAN 1234
#define BIG_ENDIAN 4321
#ifdef WORDS_BIGENDIAN
#define BYTE_ORDER BIG_ENDIAN
#else
#define BYTE_ORDER LITTLE_ENDIAN
#endif
#endif

SEXP is_big_endian() {
return Rf_ScalarLogical(BYTE_ORDER == BIG_ENDIAN);
}
26 changes: 0 additions & 26 deletions src/endian.h

This file was deleted.

0 comments on commit e07137a

Please sign in to comment.