Changeset: f37c1b407967 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=f37c1b407967
Modified Files:
common/utils/mcrypt.c
common/utils/mutils.c
common/utils/mutils.h
common/utils/muuid.c
gdk/gdk.h
gdk/gdk_batop.c
gdk/gdk_logger.c
gdk/gdk_system.c
geom/lib/Makefile.ag
geom/monetdb5/Makefile.ag
monetdb5/extras/mal_optimizer_template/Makefile.ag
monetdb5/extras/rapi/Makefile.ag
monetdb5/mal/mal.c
monetdb5/mal/mal_linker.c
monetdb5/mal/mal_session.c
monetdb5/modules/atoms/uuid.c
monetdb5/modules/kernel/Makefile.ag
monetdb5/modules/kernel/microbenchmark.c
monetdb5/modules/mal/mal_mapi.c
monetdb5/modules/mal/orderidx.c
sql/backends/monet5/UDF/capi/Makefile.ag
sql/backends/monet5/UDF/capi/capi.c
sql/backends/monet5/UDF/pyapi/Makefile.ag
sql/backends/monet5/UDF/pyapi3/Makefile.ag
sql/backends/monet5/UDF/udf/Makefile.ag
sql/backends/monet5/vaults/bam/Makefile.ag
sql/common/Makefile.ag
sql/server/Makefile.ag
sql/storage/Makefile.ag
sql/storage/bat/Makefile.ag
tools/merovingian/daemon/discoveryrunner.c
tools/merovingian/daemon/merovingian.c
tools/merovingian/utils/utils.c
tools/mserver/mserver5.c
Branch: port-monetdblite
Log Message:
Continuing porting MonetDBLite features into MonetDB.
- Ported fsync implementation for MonetDBLite compilation on Windows.
- Added wrapper for rand and srand functions.
- Disabled unwanted features in mal_session for MonetDBLite compilation.
diffs (truncated from 900 to 300 lines):
diff --git a/common/utils/mcrypt.c b/common/utils/mcrypt.c
--- a/common/utils/mcrypt.c
+++ b/common/utils/mcrypt.c
@@ -10,7 +10,6 @@
#include "mcrypt.h"
#include <string.h>
-#ifndef HAVE_EMBEDDED
/* only provide digest functions if not embedded */
#ifdef HAVE_OPENSSL
#include <openssl/md5.h>
@@ -22,7 +21,6 @@
#include <CommonCrypto/CommonDigest.h>
#endif
#endif
-#endif
/**
* Returns a comma separated list of supported hash algorithms suitable
@@ -71,7 +69,7 @@ mcrypt_getHashAlgorithms(void)
char *
mcrypt_MD5Sum(const char *string, size_t len)
{
-#if !defined(HAVE_EMBEDDED) && defined(HAVE_MD5_UPDATE)
+#if defined(HAVE_MD5_UPDATE)
MD5_CTX c;
unsigned char md[MD5_DIGEST_LENGTH];
char *ret;
@@ -109,7 +107,7 @@ mcrypt_MD5Sum(const char *string, size_t
char *
mcrypt_SHA1Sum(const char *string, size_t len)
{
-#if !defined(HAVE_EMBEDDED) && defined(HAVE_SHA1_UPDATE)
+#if defined(HAVE_SHA1_UPDATE)
SHA_CTX c;
unsigned char md[SHA_DIGEST_LENGTH];
char *ret;
@@ -147,7 +145,7 @@ mcrypt_SHA1Sum(const char *string, size_
char *
mcrypt_SHA224Sum(const char *string, size_t len)
{
-#if !defined(HAVE_EMBEDDED) && defined(HAVE_SHA224_UPDATE)
+#if defined(HAVE_SHA224_UPDATE)
SHA256_CTX c;
unsigned char md[SHA224_DIGEST_LENGTH];
char *ret;
@@ -188,7 +186,7 @@ mcrypt_SHA224Sum(const char *string, siz
char *
mcrypt_SHA256Sum(const char *string, size_t len)
{
-#if !defined(HAVE_EMBEDDED) && defined(HAVE_SHA256_UPDATE)
+#if defined(HAVE_SHA256_UPDATE)
SHA256_CTX c;
unsigned char md[SHA256_DIGEST_LENGTH];
char *ret;
@@ -231,7 +229,7 @@ mcrypt_SHA256Sum(const char *string, siz
char *
mcrypt_SHA384Sum(const char *string, size_t len)
{
-#if !defined(HAVE_EMBEDDED) && defined(HAVE_SHA384_UPDATE)
+#if defined(HAVE_SHA384_UPDATE)
SHA512_CTX c;
unsigned char md[SHA384_DIGEST_LENGTH];
char *ret;
@@ -278,7 +276,7 @@ mcrypt_SHA384Sum(const char *string, siz
char *
mcrypt_SHA512Sum(const char *string, size_t len)
{
-#if !defined(HAVE_EMBEDDED) && defined(HAVE_SHA512_UPDATE)
+#if defined(HAVE_SHA512_UPDATE)
SHA512_CTX c;
unsigned char md[SHA512_DIGEST_LENGTH];
char *ret;
@@ -330,7 +328,7 @@ mcrypt_SHA512Sum(const char *string, siz
char *
mcrypt_RIPEMD160Sum(const char *string, size_t len)
{
-#if !defined(HAVE_EMBEDDED) && defined(HAVE_RIPEMD160_UPDATE)
+#if defined(HAVE_RIPEMD160_UPDATE)
RIPEMD160_CTX c;
unsigned char md[RIPEMD160_DIGEST_LENGTH];
char *ret;
@@ -370,7 +368,7 @@ mcrypt_RIPEMD160Sum(const char *string,
char *
mcrypt_BackendSum(const char *string, size_t len)
{
-#if !defined(HAVE_EMBEDDED) && (defined(HAVE_OPENSSL) ||
defined(HAVE_COMMONCRYPTO))
+#if defined(HAVE_OPENSSL) || defined(HAVE_COMMONCRYPTO)
return mcryptsum(MONETDB5_PASSWDHASH_TOKEN)(string, len);
#else
(void) string;
@@ -394,7 +392,7 @@ mcrypt_hashPassword(
const char *password,
const char *challenge)
{
-#if !defined(HAVE_EMBEDDED) && (defined(HAVE_OPENSSL) ||
defined(HAVE_COMMONCRYPTO))
+#if defined(HAVE_OPENSSL) || defined(HAVE_COMMONCRYPTO)
unsigned char md[64]; /* should be SHA512_DIGEST_LENGTH */
char ret[sizeof(md) * 2 + 1];
int len;
@@ -496,7 +494,7 @@ mcrypt_hashPassword(
return NULL;
}
-#if !defined(HAVE_EMBEDDED) && (defined(HAVE_OPENSSL) ||
defined(HAVE_COMMONCRYPTO))
+#if defined(HAVE_OPENSSL) || defined(HAVE_COMMONCRYPTO)
snprintf(ret, sizeof(ret),
"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"
"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"
diff --git a/common/utils/mutils.c b/common/utils/mutils.c
--- a/common/utils/mutils.c
+++ b/common/utils/mutils.c
@@ -10,7 +10,9 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
+#ifdef HAVE_UNISTD_H
#include <unistd.h>
+#endif
#include <string.h>
#include "mutils.h"
@@ -38,13 +40,49 @@
#ifdef NATIVE_WIN32
-/* Some definitions that we need to compile on Windows.
- * Note that Windows only runs on little endian architectures. */
-typedef unsigned int u_int32_t;
-typedef int int32_t;
-#define BIG_ENDIAN 4321
-#define LITTLE_ENDIAN 1234
-#define BYTE_ORDER LITTLE_ENDIAN
+#ifndef WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN
+#endif
+#include <windows.h>
+#include <errno.h>
+#include <io.h>
+
+int
+fsync(int fd)
+{
+ HANDLE h = (HANDLE) _get_osfhandle (fd);
+ DWORD err;
+
+ if (h == INVALID_HANDLE_VALUE) {
+ errno = EBADF;
+ return -1;
+ }
+
+ if (!FlushFileBuffers (h)) {
+ /* Translate some Windows errors into rough approximations of Unix
+ * errors. MSDN is useless as usual - in this case it doesn't
+ * document the full range of errors.
+ */
+ err = GetLastError ();
+ switch (err) {
+ case ERROR_ACCESS_DENIED:
+ /* For a read-only handle, fsync should
succeed, even though we have
+ no way to sync the access-time changes. */
+ return 0;
+
+ /* eg. Trying to fsync a tty. */
+ case ERROR_INVALID_HANDLE:
+ errno = EINVAL;
+ break;
+
+ default:
+ errno = EIO;
+ }
+ return -1;
+ }
+
+ return 0;
+}
/* translate Windows error code (GetLastError()) to Unix-style error */
int
@@ -435,6 +473,7 @@ MT_lockf(char *filename, int mode, off_t
#endif
+#ifndef HAVE_EMBEDDED
#ifndef PATH_MAX
# define PATH_MAX 1024
#endif
@@ -488,3 +527,28 @@ get_bin_path(void)
* that's a lot of work and unreliable */
return NULL;
}
+#endif /* HAVE_EMBEDDED */
+
+#ifdef HAVE_EMBEDDED_R
+extern int embedded_r_rand(void);
+#endif
+
+int
+MT_rand(void)
+{
+#ifdef HAVE_EMBEDDED_R
+ return embedded_r_rand();
+#else
+ return rand();
+#endif
+}
+
+void
+MT_srand(unsigned int seed)
+{
+#ifdef HAVE_EMBEDDED_R
+ (void) seed;
+#else
+ srand(seed);
+#endif
+}
diff --git a/common/utils/mutils.h b/common/utils/mutils.h
--- a/common/utils/mutils.h
+++ b/common/utils/mutils.h
@@ -42,6 +42,8 @@ mutils_export int closedir(DIR *dir);
mutils_export char *dirname(char *path);
+mutils_export int fsync(int fd);
+mutils_export int winerror(int e);
#endif
#ifndef S_IWGRP
@@ -66,17 +68,18 @@ mutils_export char *dirname(char *path);
#define F_LOCK 1 /* lock a region for exclusive use */
mutils_export int MT_lockf(char *filename, int mode, off_t off, off_t len);
+mutils_export int MT_rand(void);
+mutils_export void MT_srand(unsigned int seed);
-mutils_export void print_trace(void);
-
+#ifndef HAVE_EMBEDDED
/* Retrieves the absolute path to the executable being run, with no
* extra /, /./, or /../ sequences. On Darwin and Solaris this function
* needs to be called before any chdirs are performed. Returns a
* pointer to a static buffer that is overwritten by subsequent calls to
* this function. */
mutils_export char *get_bin_path(void);
-
/* Returns the Mercurial changeset of the current checkout, if available */
mutils_export const char *mercurial_revision(void);
+#endif
#endif /* _MUTILS_H_ */
diff --git a/common/utils/muuid.c b/common/utils/muuid.c
--- a/common/utils/muuid.c
+++ b/common/utils/muuid.c
@@ -77,10 +77,10 @@ generateUUID(void)
* ("%08x-%04x-%04x-%04x-%012x") */
snprintf(out, sizeof(out),
"%04x%04x-%04x-%04x-%04x-%04x%04x%04x",
- rand() % 65536, rand() % 65536,
- rand() % 65536, rand() % 65536,
- rand() % 65536, rand() % 65536,
- rand() % 65536, rand() % 65536);
+ MT_rand() % 65536, MT_rand() % 65536,
+ MT_rand() % 65536, MT_rand() % 65536,
+ MT_rand() % 65536, MT_rand() % 65536,
+ MT_rand() % 65536, MT_rand() % 65536);
#endif
return strdup(out);
}
diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -331,6 +331,7 @@
#include <limits.h> /* for *_MIN and *_MAX */
#include <float.h> /* for FLT_MAX and DBL_MAX */
+#include "mutils.h"
#include "gdk_system.h"
#include "gdk_posix.h"
#include "stream.h"
diff --git a/gdk/gdk_batop.c b/gdk/gdk_batop.c
--- a/gdk/gdk_batop.c
+++ b/gdk/gdk_batop.c
@@ -16,6 +16,7 @@
*/
#include "monetdb_config.h"
#include "gdk.h"
+#include "mutils.h"
#include "gdk_private.h"
#include "gdk_cand.h"
@@ -143,7 +144,7 @@ insert_string_bat(BAT *b, BAT *n, BAT *s
int match = 0, i;
size_t len = b->tvheap->hashash ? 1024 * EXTRALEN : 0;
for (i = 0; i < 1024; i++) {
- p = (BUN) (((double) rand() / RAND_MAX) * (cnt
- 1));
+ p = (BUN) (((double) MT_rand() / RAND_MAX) *
(cnt - 1));
if (cand)
p = cand[p] - n->hseqbase;
else
diff --git a/gdk/gdk_logger.c b/gdk/gdk_logger.c
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list