summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2017-09-22 13:05:36 (GMT)
committerdgp <dgp@users.sourceforge.net>2017-09-22 13:05:36 (GMT)
commit0fc1d4225210820f1dfbe0e608918c67f867812c (patch)
tree9a6b0c18e62db82af8c9d27b82e6682d9686a200
parent31f0eaa75ab8ee3bd166256576acd5d93e36dbb6 (diff)
parentdecba31378095b56c8854968f0c9595761c68ed9 (diff)
downloadtcl-0fc1d4225210820f1dfbe0e608918c67f867812c.zip
tcl-0fc1d4225210820f1dfbe0e608918c67f867812c.tar.gz
tcl-0fc1d4225210820f1dfbe0e608918c67f867812c.tar.bz2
merge trunk
-rw-r--r--libtommath/bn_mp_div_d.c22
-rw-r--r--libtommath/tommath.h4
-rw-r--r--win/tclWinLoad.c30
3 files changed, 36 insertions, 20 deletions
diff --git a/libtommath/bn_mp_div_d.c b/libtommath/bn_mp_div_d.c
index d0131c3..c408602 100644
--- a/libtommath/bn_mp_div_d.c
+++ b/libtommath/bn_mp_div_d.c
@@ -15,21 +15,6 @@
* Tom St Denis, tstdenis82@gmail.com, http://libtom.org
*/
-static int s_is_power_of_two(mp_digit b, int *p)
-{
- int x;
-
- /* Gives the wrong result for b==1, but this function
- * is never called for this value anyway. */
- for (x = 1; x < DIGIT_BIT; x++) {
- if (b == (((mp_digit)1)<<x)) {
- *p = x;
- return 1;
- }
- }
- return 0;
-}
-
/* single digit division (based on routine from MPI) */
int mp_div_d(const mp_int *a, mp_digit b, mp_int *c, mp_digit *d)
{
@@ -55,7 +40,12 @@ int mp_div_d(const mp_int *a, mp_digit b, mp_int *c, mp_digit *d)
}
/* power of two ? */
- if (((b & (b-1)) == 0) && s_is_power_of_two(b, &ix)) {
+ if (((b & (b-1)) == 0)) {
+ for (ix = 1; ix < DIGIT_BIT; ix++) {
+ if (b == (((mp_digit)1)<<ix)) {
+ break;
+ }
+ }
if (d != NULL) {
*d = a->dp[0] & ((((mp_digit)1)<<ix) - 1);
}
diff --git a/libtommath/tommath.h b/libtommath/tommath.h
index dee7ab5..e067cb4 100644
--- a/libtommath/tommath.h
+++ b/libtommath/tommath.h
@@ -33,11 +33,13 @@ extern "C" {
defined(__sparcv9) || defined(__sparc_v9__) || defined(__sparc64__) || \
defined(__ia64) || defined(__ia64__) || defined(__itanium__) || defined(_M_IA64) || \
defined(__LP64__) || defined(_LP64) || defined(__64BIT__)
-# if !(defined(MP_32BIT) || defined(MP_16BIT) || defined(MP_8BIT))
+# if !(defined(MP_32BIT) || defined(MP_16BIT) || defined(MP_8BIT) || defined(_MSC_VER))
# define MP_64BIT
# endif
#endif
+typedef unsigned long long Tcl_WideUInt;
+
/* some default configurations.
*
* A "mp_digit" must be able to hold DIGIT_BIT + 1 bits
diff --git a/win/tclWinLoad.c b/win/tclWinLoad.c
index 26512b1..3ad6328 100644
--- a/win/tclWinLoad.c
+++ b/win/tclWinLoad.c
@@ -66,6 +66,7 @@ TclpDlopen(
HINSTANCE hInstance;
const TCHAR *nativeName;
Tcl_LoadHandle handlePtr;
+ DWORD firstError;
/*
* First try the full path the user gave us. This is particularly
@@ -84,6 +85,12 @@ TclpDlopen(
Tcl_DString ds;
+ /*
+ * Remember the first error on load attempt to be used if the
+ * second load attempt below also fails.
+ */
+ firstError = GetLastError();
+
nativeName = Tcl_WinUtfToTChar(Tcl_GetString(pathPtr), -1, &ds);
hInstance = LoadLibraryEx(nativeName, NULL,
LOAD_WITH_ALTERED_SEARCH_PATH);
@@ -91,8 +98,21 @@ TclpDlopen(
}
if (hInstance == NULL) {
- DWORD lastError = GetLastError();
- Tcl_Obj *errMsg = Tcl_ObjPrintf("couldn't load library \"%s\": ",
+ DWORD lastError;
+ Tcl_Obj *errMsg;
+
+ /*
+ * We choose to only use the error from the second call if the first
+ * call failed due to the file not being found. Else stick to the
+ * first error for reporting purposes.
+ */
+ if (firstError == ERROR_MOD_NOT_FOUND ||
+ firstError == ERROR_DLL_NOT_FOUND)
+ lastError = GetLastError();
+ else
+ lastError = firstError;
+
+ errMsg = Tcl_ObjPrintf("couldn't load library \"%s\": ",
Tcl_GetString(pathPtr));
/*
@@ -129,7 +149,11 @@ TclpDlopen(
Tcl_AppendToObj(errMsg, "the library initialization"
" routine failed", -1);
break;
- default:
+ case ERROR_BAD_EXE_FORMAT:
+ Tcl_SetErrorCode(interp, "WIN_LOAD", "BAD_EXE_FORMAT", NULL);
+ Tcl_AppendToObj(errMsg, "Bad exe format. Possibly a 32/64-bit mismatch.", -1);
+ break;
+ default:
TclWinConvertError(lastError);
Tcl_AppendToObj(errMsg, Tcl_PosixError(interp), -1);
}