From e0209e39ea32294ee016d240fd1dfe9411469832 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Wed, 17 Oct 2018 19:51:47 +0000 Subject: Fix test-cases running on Windows 10: [string index $tcl_platform(osVersion) 0] doesn't give the correct answer then (it gives "1", but "10" was expected) --- tests/cmdAH.test | 2 +- tests/fCmd.test | 18 +++++++++--------- tests/fileName.test | 2 +- tests/winFCmd.test | 5 ++--- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/tests/cmdAH.test b/tests/cmdAH.test index 45a867a..6cc8c0f 100644 --- a/tests/cmdAH.test +++ b/tests/cmdAH.test @@ -20,7 +20,7 @@ testConstraint testsetplatform [llength [info commands testsetplatform]] testConstraint testvolumetype [llength [info commands testvolumetype]] testConstraint linkDirectory [expr { ![testConstraint win] || - ([string index $tcl_platform(osVersion) 0] >= 5 + ($::tcl_platform(osVersion) >= 5.0 && [lindex [file system [temporaryDirectory]] 1] eq "NTFS") }] diff --git a/tests/fCmd.test b/tests/fCmd.test index 2860001..f53128d 100644 --- a/tests/fCmd.test +++ b/tests/fCmd.test @@ -50,11 +50,10 @@ if {[testConstraint unix]} { # Also used in winFCmd... if {[testConstraint winOnly]} { - set major [string index $tcl_platform(osVersion) 0] - if {[testConstraint nt] && $major > 4} { - if {$major > 5} { + if {[testConstraint nt] && $::tcl_platform(osVersion) >= 5.0} { + if {$::tcl_platform(osVersion) >= 6.0} { testConstraint winVista 1 - } elseif {$major == 5} { + } else { testConstraint win2000orXP 1 } } else { @@ -62,10 +61,11 @@ if {[testConstraint winOnly]} { } } -testConstraint darwin9 [expr {[testConstraint unix] && - $tcl_platform(os) eq "Darwin" && - int([string range $tcl_platform(osVersion) 0 \ - [string first . $tcl_platform(osVersion)]]) >= 9}] +testConstraint darwin9 [expr { + [testConstraint unix] + && $tcl_platform(os) eq "Darwin" + && [package vsatisfies 1.$::tcl_platform(osVersion) 1.9] +}] testConstraint notDarwin9 [expr {![testConstraint darwin9]}] testConstraint fileSharing 0 @@ -2282,7 +2282,7 @@ test fCmd-27.6 {TclFileAttrsCmd - setting more than one option} -setup { if { [testConstraint win] && - ([string index $tcl_platform(osVersion) 0] < 5 + ($::tcl_platform(osVersion) < 5.0 || [lindex [file system [temporaryDirectory]] 1] ne "NTFS") } then { testConstraint linkDirectory 0 diff --git a/tests/fileName.test b/tests/fileName.test index 0851e94..a4c8efe 100644 --- a/tests/fileName.test +++ b/tests/fileName.test @@ -20,7 +20,7 @@ testConstraint testtranslatefilename [llength [info commands testtranslatefilena testConstraint linkDirectory 1 testConstraint symbolicLinkFile 1 if {[testConstraint win]} { - if {[string index $tcl_platform(osVersion) 0] < 5 \ + if {$::tcl_platform(osVersion) < 5.0 \ || [lindex [file system [temporaryDirectory]] 1] ne "NTFS"} { testConstraint linkDirectory 0 } diff --git a/tests/winFCmd.test b/tests/winFCmd.test index f1f2afa..f93f225 100644 --- a/tests/winFCmd.test +++ b/tests/winFCmd.test @@ -53,10 +53,9 @@ proc cleanup {args} { } if {[testConstraint win]} { - set major [string index $tcl_platform(osVersion) 0] - if {$major > 5} { + if {$::tcl_platform(osVersion) >= 5.0} { testConstraint winVista 1 - } elseif {$major == 5} { + } elseif {$::tcl_platform(osVersion) >= 4.0} { testConstraint winXP 1 } } -- cgit v0.12 From 49ebd1264d9cff42e9e5963f2a2f3c0eb732f375 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Wed, 17 Oct 2018 22:37:43 +0000 Subject: Add -Wpointer-arith compiler flag to gcc --- unix/configure | 2 +- unix/tcl.m4 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/unix/configure b/unix/configure index 2af5144..013a8b3 100755 --- a/unix/configure +++ b/unix/configure @@ -4947,7 +4947,7 @@ fi if test "$GCC" = yes; then : CFLAGS_OPTIMIZE=-O2 - CFLAGS_WARNING="-Wall -Wwrite-strings -Wsign-compare -Wdeclaration-after-statement" + CFLAGS_WARNING="-Wall -Wwrite-strings -Wsign-compare -Wdeclaration-after-statement -Wpointer-arith" else diff --git a/unix/tcl.m4 b/unix/tcl.m4 index b77387a..e27cc2c 100644 --- a/unix/tcl.m4 +++ b/unix/tcl.m4 @@ -986,7 +986,7 @@ AC_DEFUN([SC_CONFIG_CFLAGS], [ CFLAGS_DEBUG=-g AS_IF([test "$GCC" = yes], [ CFLAGS_OPTIMIZE=-O2 - CFLAGS_WARNING="-Wall -Wwrite-strings -Wsign-compare -Wdeclaration-after-statement" + CFLAGS_WARNING="-Wall -Wwrite-strings -Wsign-compare -Wdeclaration-after-statement -Wpointer-arith" ], [ CFLAGS_OPTIMIZE=-O CFLAGS_WARNING="" -- cgit v0.12 From e0064189465e2ea63ca9e2dd531928a14c968f52 Mon Sep 17 00:00:00 2001 From: dkf Date: Thu, 18 Oct 2018 14:58:28 +0000 Subject: Tests for advanced object mutation issues. --- generic/tclOODefineCmds.c | 22 +++++++++++++- tests/oo.test | 77 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+), 1 deletion(-) diff --git a/generic/tclOODefineCmds.c b/generic/tclOODefineCmds.c index c924d2b..f5fe676 100644 --- a/generic/tclOODefineCmds.c +++ b/generic/tclOODefineCmds.c @@ -1083,6 +1083,8 @@ TclOODefineClassObjCmd( { Object *oPtr; Class *clsPtr; + Foundation *fPtr = TclOOGetFoundation(interp); + int wasClass, willBeClass; /* * Parse the context to get the object to operate on. @@ -1118,12 +1120,20 @@ TclOODefineClassObjCmd( if (clsPtr == NULL) { return TCL_ERROR; } - + if (oPtr == clsPtr->thisPtr) { + Tcl_SetObjResult(interp, Tcl_NewStringObj( + "may not change classes into an instance of themselves", -1)); + Tcl_SetErrorCode(interp, "TCL", "OO", "MONKEY_BUSINESS", NULL); + return TCL_ERROR; + } /* * Set the object's class. */ + wasClass = (oPtr->classPtr != NULL); + willBeClass = (TclOOIsReachable(fPtr->classCls, clsPtr)); + if (oPtr->selfCls != clsPtr) { TclOORemoveFromInstances(oPtr, oPtr->selfCls); TclOODecrRefCount(oPtr->selfCls->thisPtr); @@ -1131,6 +1141,16 @@ TclOODefineClassObjCmd( AddRef(oPtr->selfCls->thisPtr); TclOOAddToInstances(oPtr, oPtr->selfCls); + /* + * Create or delete the class guts if necessary. + */ + + if (wasClass && !willBeClass) { + /* TODO: DELETE THE STRUCTURE */ + } else if (!wasClass && willBeClass) { + /* TODO: CREATE THE STRUCTURE */ + } + if (oPtr->classPtr != NULL) { BumpGlobalEpoch(interp, oPtr->classPtr); } else { diff --git a/tests/oo.test b/tests/oo.test index 024f890..7f0de4a 100644 --- a/tests/oo.test +++ b/tests/oo.test @@ -1804,6 +1804,83 @@ test oo-13.4 {OO: changing an object's class} -body { foo destroy bar destroy } -result {::foo ::foo ::foo ::bar} +test oo-13.5 {OO: changing an object's class} -setup { + oo::object create fooObj +} -body { + oo::objdefine fooObj { + class oo::class + } + oo::define fooObj { + method x {} {expr 1+2+3} + } + [fooObj new] x +} -cleanup { + fooObj destroy +} -result 6 +test oo-13.6 {OO: changing an object's class} -setup { + oo::class create foo +} -body { + oo::define foo { + method x {} {expr 1+2+3} + } + foo create bar + oo::objdefine foo { + class oo::object + } + list [catch {bar x} msg] $msg +} -cleanup { + catch {bar destroy} + foo destroy +} -result {1 {}} +test oo-13.7 {OO: changing an object's class} -setup { + oo::class create foo + oo::class create bar + unset -nocomplain result +} -body { + oo::define bar method x {} {return ok} + oo::define foo { + method x {} {expr 1+2+3} + self mixin foo + } + lappend result [foo x] + oo::objdefine foo class bar + lappend result [foo x] +} -cleanup { + foo destroy + bar destroy +} -result {6 ok} +test oo-13.7 {OO: changing an object's class to itself} -setup { + oo::class create foo +} -body { + oo::define foo { + method x {} {expr 1+2+3} + } + oo::objdefine foo class foo +} -cleanup { + foo destroy +} -returnCodes error -result {may not change classes into an instance of themselves} +test oo-13.9 {OO: changing an object's class: roots are special} -setup { + set i [interp create] +} -body { + $i eval { + oo::objdefine oo::object { + class oo::class + } + } +} -cleanup { + interp delete $i +} -returnCodes error -result {may not modify the class of the root object class} +test oo-13.10 {OO: changing an object's class: roots are special} -setup { + set i [interp create] +} -body { + $i eval { + oo::objdefine oo::class { + class oo::object + } + } +} -cleanup { + interp delete $i +} -returnCodes error -result {may not modify the class of the class of classes} # todo: changing a class subtype (metaclass) to another class subtype test oo-14.1 {OO: mixins} { -- cgit v0.12 From 6b0dccd9d531ae246fd34f9b4dc3c24ff4d06945 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Ignacio=20Mar=C3=ADn?= Date: Thu, 18 Oct 2018 18:23:50 +0000 Subject: Update TZ info to tzdata2018f. --- library/tzdata/Africa/Ceuta | 1 + library/tzdata/America/Santiago | 324 ++++++++++++++++++++-------------------- library/tzdata/Asia/Macau | 68 ++++++--- library/tzdata/Asia/Manila | 18 +-- library/tzdata/Asia/Pyongyang | 2 +- library/tzdata/Asia/Shanghai | 43 +++--- library/tzdata/Asia/Tokyo | 8 +- library/tzdata/Europe/Volgograd | 1 + library/tzdata/Pacific/Easter | 324 ++++++++++++++++++++-------------------- library/tzdata/Pacific/Fiji | 24 +-- 10 files changed, 427 insertions(+), 386 deletions(-) diff --git a/library/tzdata/Africa/Ceuta b/library/tzdata/Africa/Ceuta index 057ca22..18af8c1 100644 --- a/library/tzdata/Africa/Ceuta +++ b/library/tzdata/Africa/Ceuta @@ -15,6 +15,7 @@ set TZData(:Africa/Ceuta) { {-1316390400 3600 1 WEST} {-1301270400 0 0 WET} {-1293840000 0 0 WET} + {-94694400 0 0 WET} {-81432000 3600 1 WEST} {-71110800 0 0 WET} {141264000 3600 1 WEST} diff --git a/library/tzdata/America/Santiago b/library/tzdata/America/Santiago index 67d5b5c..55212b9 100644 --- a/library/tzdata/America/Santiago +++ b/library/tzdata/America/Santiago @@ -124,166 +124,166 @@ set TZData(:America/Santiago) { {1502596800 -10800 1 -04} {1526180400 -14400 0 -04} {1534046400 -10800 1 -04} - {1557630000 -14400 0 -04} - {1565496000 -10800 1 -04} - {1589079600 -14400 0 -04} - {1596945600 -10800 1 -04} - {1620529200 -14400 0 -04} - {1629000000 -10800 1 -04} - {1652583600 -14400 0 -04} - {1660449600 -10800 1 -04} - {1684033200 -14400 0 -04} - {1691899200 -10800 1 -04} - {1715482800 -14400 0 -04} - {1723348800 -10800 1 -04} - {1746932400 -14400 0 -04} - {1754798400 -10800 1 -04} - {1778382000 -14400 0 -04} - {1786248000 -10800 1 -04} - {1809831600 -14400 0 -04} - {1818302400 -10800 1 -04} - {1841886000 -14400 0 -04} - {1849752000 -10800 1 -04} - {1873335600 -14400 0 -04} - {1881201600 -10800 1 -04} - {1904785200 -14400 0 -04} - {1912651200 -10800 1 -04} - {1936234800 -14400 0 -04} - {1944100800 -10800 1 -04} - {1967684400 -14400 0 -04} - {1976155200 -10800 1 -04} - {1999738800 -14400 0 -04} - {2007604800 -10800 1 -04} - {2031188400 -14400 0 -04} - {2039054400 -10800 1 -04} - {2062638000 -14400 0 -04} - {2070504000 -10800 1 -04} - {2094087600 -14400 0 -04} - {2101953600 -10800 1 -04} - {2125537200 -14400 0 -04} - {2133403200 -10800 1 -04} - {2156986800 -14400 0 -04} - {2165457600 -10800 1 -04} - {2189041200 -14400 0 -04} - {2196907200 -10800 1 -04} - {2220490800 -14400 0 -04} - {2228356800 -10800 1 -04} - {2251940400 -14400 0 -04} - {2259806400 -10800 1 -04} - {2283390000 -14400 0 -04} - {2291256000 -10800 1 -04} - {2314839600 -14400 0 -04} - {2322705600 -10800 1 -04} - {2346894000 -14400 0 -04} - {2354760000 -10800 1 -04} - {2378343600 -14400 0 -04} - {2386209600 -10800 1 -04} - {2409793200 -14400 0 -04} - {2417659200 -10800 1 -04} - {2441242800 -14400 0 -04} - {2449108800 -10800 1 -04} - {2472692400 -14400 0 -04} - {2480558400 -10800 1 -04} - {2504142000 -14400 0 -04} - {2512612800 -10800 1 -04} - {2536196400 -14400 0 -04} - {2544062400 -10800 1 -04} - {2567646000 -14400 0 -04} - {2575512000 -10800 1 -04} - {2599095600 -14400 0 -04} - {2606961600 -10800 1 -04} - {2630545200 -14400 0 -04} - {2638411200 -10800 1 -04} - {2661994800 -14400 0 -04} - {2669860800 -10800 1 -04} - {2693444400 -14400 0 -04} - {2701915200 -10800 1 -04} - {2725498800 -14400 0 -04} - {2733364800 -10800 1 -04} - {2756948400 -14400 0 -04} - {2764814400 -10800 1 -04} - {2788398000 -14400 0 -04} - {2796264000 -10800 1 -04} - {2819847600 -14400 0 -04} - {2827713600 -10800 1 -04} - {2851297200 -14400 0 -04} - {2859768000 -10800 1 -04} - {2883351600 -14400 0 -04} - {2891217600 -10800 1 -04} - {2914801200 -14400 0 -04} - {2922667200 -10800 1 -04} - {2946250800 -14400 0 -04} - {2954116800 -10800 1 -04} - {2977700400 -14400 0 -04} - {2985566400 -10800 1 -04} - {3009150000 -14400 0 -04} - {3017016000 -10800 1 -04} - {3040599600 -14400 0 -04} - {3049070400 -10800 1 -04} - {3072654000 -14400 0 -04} - {3080520000 -10800 1 -04} - {3104103600 -14400 0 -04} - {3111969600 -10800 1 -04} - {3135553200 -14400 0 -04} - {3143419200 -10800 1 -04} - {3167002800 -14400 0 -04} - {3174868800 -10800 1 -04} - {3198452400 -14400 0 -04} - {3206318400 -10800 1 -04} - {3230506800 -14400 0 -04} - {3238372800 -10800 1 -04} - {3261956400 -14400 0 -04} - {3269822400 -10800 1 -04} - {3293406000 -14400 0 -04} - {3301272000 -10800 1 -04} - {3324855600 -14400 0 -04} - {3332721600 -10800 1 -04} - {3356305200 -14400 0 -04} - {3364171200 -10800 1 -04} - {3387754800 -14400 0 -04} - {3396225600 -10800 1 -04} - {3419809200 -14400 0 -04} - {3427675200 -10800 1 -04} - {3451258800 -14400 0 -04} - {3459124800 -10800 1 -04} - {3482708400 -14400 0 -04} - {3490574400 -10800 1 -04} - {3514158000 -14400 0 -04} - {3522024000 -10800 1 -04} - {3545607600 -14400 0 -04} - {3553473600 -10800 1 -04} - {3577057200 -14400 0 -04} - {3585528000 -10800 1 -04} - {3609111600 -14400 0 -04} - {3616977600 -10800 1 -04} - {3640561200 -14400 0 -04} - {3648427200 -10800 1 -04} - {3672010800 -14400 0 -04} - {3679876800 -10800 1 -04} - {3703460400 -14400 0 -04} - {3711326400 -10800 1 -04} - {3734910000 -14400 0 -04} - {3743380800 -10800 1 -04} - {3766964400 -14400 0 -04} - {3774830400 -10800 1 -04} - {3798414000 -14400 0 -04} - {3806280000 -10800 1 -04} - {3829863600 -14400 0 -04} - {3837729600 -10800 1 -04} - {3861313200 -14400 0 -04} - {3869179200 -10800 1 -04} - {3892762800 -14400 0 -04} - {3900628800 -10800 1 -04} - {3924212400 -14400 0 -04} - {3932683200 -10800 1 -04} - {3956266800 -14400 0 -04} - {3964132800 -10800 1 -04} - {3987716400 -14400 0 -04} - {3995582400 -10800 1 -04} - {4019166000 -14400 0 -04} - {4027032000 -10800 1 -04} - {4050615600 -14400 0 -04} - {4058481600 -10800 1 -04} - {4082065200 -14400 0 -04} - {4089931200 -10800 1 -04} + {1554606000 -14400 0 -04} + {1567915200 -10800 1 -04} + {1586055600 -14400 0 -04} + {1599364800 -10800 1 -04} + {1617505200 -14400 0 -04} + {1630814400 -10800 1 -04} + {1648954800 -14400 0 -04} + {1662264000 -10800 1 -04} + {1680404400 -14400 0 -04} + {1693713600 -10800 1 -04} + {1712458800 -14400 0 -04} + {1725768000 -10800 1 -04} + {1743908400 -14400 0 -04} + {1757217600 -10800 1 -04} + {1775358000 -14400 0 -04} + {1788667200 -10800 1 -04} + {1806807600 -14400 0 -04} + {1820116800 -10800 1 -04} + {1838257200 -14400 0 -04} + {1851566400 -10800 1 -04} + {1870311600 -14400 0 -04} + {1883016000 -10800 1 -04} + {1901761200 -14400 0 -04} + {1915070400 -10800 1 -04} + {1933210800 -14400 0 -04} + {1946520000 -10800 1 -04} + {1964660400 -14400 0 -04} + {1977969600 -10800 1 -04} + {1996110000 -14400 0 -04} + {2009419200 -10800 1 -04} + {2027559600 -14400 0 -04} + {2040868800 -10800 1 -04} + {2059614000 -14400 0 -04} + {2072318400 -10800 1 -04} + {2091063600 -14400 0 -04} + {2104372800 -10800 1 -04} + {2122513200 -14400 0 -04} + {2135822400 -10800 1 -04} + {2153962800 -14400 0 -04} + {2167272000 -10800 1 -04} + {2185412400 -14400 0 -04} + {2198721600 -10800 1 -04} + {2217466800 -14400 0 -04} + {2230171200 -10800 1 -04} + {2248916400 -14400 0 -04} + {2262225600 -10800 1 -04} + {2280366000 -14400 0 -04} + {2293675200 -10800 1 -04} + {2311815600 -14400 0 -04} + {2325124800 -10800 1 -04} + {2343265200 -14400 0 -04} + {2356574400 -10800 1 -04} + {2374714800 -14400 0 -04} + {2388024000 -10800 1 -04} + {2406769200 -14400 0 -04} + {2419473600 -10800 1 -04} + {2438218800 -14400 0 -04} + {2451528000 -10800 1 -04} + {2469668400 -14400 0 -04} + {2482977600 -10800 1 -04} + {2501118000 -14400 0 -04} + {2514427200 -10800 1 -04} + {2532567600 -14400 0 -04} + {2545876800 -10800 1 -04} + {2564017200 -14400 0 -04} + {2577326400 -10800 1 -04} + {2596071600 -14400 0 -04} + {2609380800 -10800 1 -04} + {2627521200 -14400 0 -04} + {2640830400 -10800 1 -04} + {2658970800 -14400 0 -04} + {2672280000 -10800 1 -04} + {2690420400 -14400 0 -04} + {2703729600 -10800 1 -04} + {2721870000 -14400 0 -04} + {2735179200 -10800 1 -04} + {2753924400 -14400 0 -04} + {2766628800 -10800 1 -04} + {2785374000 -14400 0 -04} + {2798683200 -10800 1 -04} + {2816823600 -14400 0 -04} + {2830132800 -10800 1 -04} + {2848273200 -14400 0 -04} + {2861582400 -10800 1 -04} + {2879722800 -14400 0 -04} + {2893032000 -10800 1 -04} + {2911172400 -14400 0 -04} + {2924481600 -10800 1 -04} + {2943226800 -14400 0 -04} + {2955931200 -10800 1 -04} + {2974676400 -14400 0 -04} + {2987985600 -10800 1 -04} + {3006126000 -14400 0 -04} + {3019435200 -10800 1 -04} + {3037575600 -14400 0 -04} + {3050884800 -10800 1 -04} + {3069025200 -14400 0 -04} + {3082334400 -10800 1 -04} + {3101079600 -14400 0 -04} + {3113784000 -10800 1 -04} + {3132529200 -14400 0 -04} + {3145838400 -10800 1 -04} + {3163978800 -14400 0 -04} + {3177288000 -10800 1 -04} + {3195428400 -14400 0 -04} + {3208737600 -10800 1 -04} + {3226878000 -14400 0 -04} + {3240187200 -10800 1 -04} + {3258327600 -14400 0 -04} + {3271636800 -10800 1 -04} + {3290382000 -14400 0 -04} + {3303086400 -10800 1 -04} + {3321831600 -14400 0 -04} + {3335140800 -10800 1 -04} + {3353281200 -14400 0 -04} + {3366590400 -10800 1 -04} + {3384730800 -14400 0 -04} + {3398040000 -10800 1 -04} + {3416180400 -14400 0 -04} + {3429489600 -10800 1 -04} + {3447630000 -14400 0 -04} + {3460939200 -10800 1 -04} + {3479684400 -14400 0 -04} + {3492993600 -10800 1 -04} + {3511134000 -14400 0 -04} + {3524443200 -10800 1 -04} + {3542583600 -14400 0 -04} + {3555892800 -10800 1 -04} + {3574033200 -14400 0 -04} + {3587342400 -10800 1 -04} + {3605482800 -14400 0 -04} + {3618792000 -10800 1 -04} + {3637537200 -14400 0 -04} + {3650241600 -10800 1 -04} + {3668986800 -14400 0 -04} + {3682296000 -10800 1 -04} + {3700436400 -14400 0 -04} + {3713745600 -10800 1 -04} + {3731886000 -14400 0 -04} + {3745195200 -10800 1 -04} + {3763335600 -14400 0 -04} + {3776644800 -10800 1 -04} + {3794785200 -14400 0 -04} + {3808094400 -10800 1 -04} + {3826839600 -14400 0 -04} + {3839544000 -10800 1 -04} + {3858289200 -14400 0 -04} + {3871598400 -10800 1 -04} + {3889738800 -14400 0 -04} + {3903048000 -10800 1 -04} + {3921188400 -14400 0 -04} + {3934497600 -10800 1 -04} + {3952638000 -14400 0 -04} + {3965947200 -10800 1 -04} + {3984692400 -14400 0 -04} + {3997396800 -10800 1 -04} + {4016142000 -14400 0 -04} + {4029451200 -10800 1 -04} + {4047591600 -14400 0 -04} + {4060900800 -10800 1 -04} + {4079041200 -14400 0 -04} + {4092350400 -10800 1 -04} } diff --git a/library/tzdata/Asia/Macau b/library/tzdata/Asia/Macau index 76a00aa..cbafd0e 100644 --- a/library/tzdata/Asia/Macau +++ b/library/tzdata/Asia/Macau @@ -1,20 +1,56 @@ # created by tools/tclZIC.tcl - do not edit set TZData(:Asia/Macau) { - {-9223372036854775808 27260 0 LMT} - {-1830412800 28800 0 CST} + {-9223372036854775808 27250 0 LMT} + {-2056692850 28800 0 CST} + {-884509200 32400 0 +09} + {-873280800 36000 1 +09} + {-855918000 32400 0 +09} + {-841744800 36000 1 +09} + {-828529200 32400 0 +10} + {-765363600 28800 0 CT} + {-747046800 32400 1 CDT} + {-733827600 28800 0 CST} + {-716461200 32400 1 CDT} + {-697021200 28800 0 CST} + {-683715600 32400 1 CDT} + {-667990800 28800 0 CST} + {-654771600 32400 1 CDT} + {-636627600 28800 0 CST} + {-623322000 32400 1 CDT} + {-605178000 28800 0 CST} + {-591872400 32400 1 CDT} + {-573642000 28800 0 CST} + {-559818000 32400 1 CDT} + {-541674000 28800 0 CST} + {-528368400 32400 1 CDT} + {-510224400 28800 0 CST} + {-498128400 32400 1 CDT} + {-478774800 28800 0 CST} + {-466678800 32400 1 CDT} + {-446720400 28800 0 CST} + {-435229200 32400 1 CDT} + {-415258200 28800 0 CST} + {-403158600 32400 1 CDT} + {-383808600 28800 0 CST} + {-371709000 32400 1 CDT} + {-352359000 28800 0 CST} + {-340259400 32400 1 CDT} + {-320909400 28800 0 CST} + {-308809800 32400 1 CDT} + {-288855000 28800 0 CST} {-277360200 32400 1 CDT} {-257405400 28800 0 CST} {-245910600 32400 1 CDT} {-225955800 28800 0 CST} - {-214473600 32400 1 CDT} + {-213856200 32400 1 CDT} {-194506200 28800 0 CST} {-182406600 32400 1 CDT} {-163056600 28800 0 CST} - {-150969600 32400 1 CDT} - {-131619600 28800 0 CST} + {-148537800 32400 1 CDT} + {-132820200 28800 0 CST} {-117088200 32400 1 CDT} - {-101367000 28800 0 CST} + {-101370600 28800 0 CST} {-85638600 32400 1 CDT} {-69312600 28800 0 CST} {-53584200 32400 1 CDT} @@ -25,22 +61,16 @@ set TZData(:Asia/Macau) { {25036200 28800 0 CST} {40764600 32400 1 CDT} {56485800 28800 0 CST} - {72201600 32400 1 CDT} - {87922800 28800 0 CST} - {103651200 32400 1 CDT} - {119977200 28800 0 CST} - {135705600 32400 1 CDT} + {72214200 32400 1 CDT} + {88540200 28800 0 CST} + {104268600 32400 1 CDT} + {119989800 28800 0 CST} + {126041400 32400 1 CDT} {151439400 28800 0 CST} {167167800 32400 1 CDT} {182889000 28800 0 CST} {198617400 32400 1 CDT} {214338600 28800 0 CST} - {230067000 32400 1 CDT} - {245788200 28800 0 CST} - {261504000 32400 1 CDT} - {277225200 28800 0 CST} - {292953600 32400 1 CDT} - {309279600 28800 0 CST} - {325008000 32400 1 CDT} - {340729200 28800 0 CST} + {295385400 32400 1 CDT} + {309292200 28800 0 CST} } diff --git a/library/tzdata/Asia/Manila b/library/tzdata/Asia/Manila index b7ffa7a..6eb1db3 100644 --- a/library/tzdata/Asia/Manila +++ b/library/tzdata/Asia/Manila @@ -3,13 +3,13 @@ set TZData(:Asia/Manila) { {-9223372036854775808 -57360 0 LMT} {-3944621040 29040 0 LMT} - {-2229321840 28800 0 +08} - {-1046678400 32400 1 +08} - {-1038733200 28800 0 +08} - {-873273600 32400 0 +09} - {-794221200 28800 0 +08} - {-496224000 32400 1 +08} - {-489315600 28800 0 +08} - {259344000 32400 1 +08} - {275151600 28800 0 +08} + {-2229321840 28800 0 PST} + {-1046678400 32400 1 PDT} + {-1038733200 28800 0 PST} + {-873273600 32400 0 JST} + {-794221200 28800 0 PST} + {-496224000 32400 1 PDT} + {-489315600 28800 0 PST} + {259344000 32400 1 PDT} + {275151600 28800 0 PST} } diff --git a/library/tzdata/Asia/Pyongyang b/library/tzdata/Asia/Pyongyang index 5746472..5351736 100644 --- a/library/tzdata/Asia/Pyongyang +++ b/library/tzdata/Asia/Pyongyang @@ -6,5 +6,5 @@ set TZData(:Asia/Pyongyang) { {-1830414600 32400 0 JST} {-768646800 32400 0 KST} {1439564400 30600 0 KST} - {1525447800 32400 0 KST} + {1525446000 32400 0 KST} } diff --git a/library/tzdata/Asia/Shanghai b/library/tzdata/Asia/Shanghai index ff2d2b5..66bc4339 100644 --- a/library/tzdata/Asia/Shanghai +++ b/library/tzdata/Asia/Shanghai @@ -3,21 +3,30 @@ set TZData(:Asia/Shanghai) { {-9223372036854775808 29143 0 LMT} {-2177481943 28800 0 CST} - {-933494400 32400 1 CDT} - {-923130000 28800 0 CST} - {-908784000 32400 1 CDT} - {-891594000 28800 0 CST} - {-662716800 28800 0 CST} - {515520000 32400 1 CDT} - {527007600 28800 0 CST} - {545155200 32400 1 CDT} - {558457200 28800 0 CST} - {576604800 32400 1 CDT} - {589906800 28800 0 CST} - {608659200 32400 1 CDT} - {621961200 28800 0 CST} - {640108800 32400 1 CDT} - {653410800 28800 0 CST} - {671558400 32400 1 CDT} - {684860400 28800 0 CST} + {-933667200 32400 1 CDT} + {-922093200 28800 0 CST} + {-908870400 32400 1 CDT} + {-888829200 28800 0 CST} + {-881049600 32400 1 CDT} + {-767869200 28800 0 CST} + {-745833600 32400 1 CDT} + {-733827600 28800 0 CST} + {-716889600 32400 1 CDT} + {-699613200 28800 0 CST} + {-683884800 32400 1 CDT} + {-670669200 28800 0 CST} + {-652348800 32400 1 CDT} + {-650016000 28800 0 CST} + {515527200 32400 1 CDT} + {527014800 28800 0 CST} + {545162400 32400 1 CDT} + {558464400 28800 0 CST} + {577216800 32400 1 CDT} + {589914000 28800 0 CST} + {608666400 32400 1 CDT} + {621968400 28800 0 CST} + {640116000 32400 1 CDT} + {653418000 28800 0 CST} + {671565600 32400 1 CDT} + {684867600 28800 0 CST} } diff --git a/library/tzdata/Asia/Tokyo b/library/tzdata/Asia/Tokyo index 790df0a..cc7a857 100644 --- a/library/tzdata/Asia/Tokyo +++ b/library/tzdata/Asia/Tokyo @@ -4,11 +4,11 @@ set TZData(:Asia/Tokyo) { {-9223372036854775808 33539 0 LMT} {-2587712400 32400 0 JST} {-683802000 36000 1 JDT} - {-672314400 32400 0 JST} + {-672310800 32400 0 JST} {-654771600 36000 1 JDT} - {-640864800 32400 0 JST} + {-640861200 32400 0 JST} {-620298000 36000 1 JDT} - {-609415200 32400 0 JST} + {-609411600 32400 0 JST} {-588848400 36000 1 JDT} - {-577965600 32400 0 JST} + {-577962000 32400 0 JST} } diff --git a/library/tzdata/Europe/Volgograd b/library/tzdata/Europe/Volgograd index 05e1044..3938683 100644 --- a/library/tzdata/Europe/Volgograd +++ b/library/tzdata/Europe/Volgograd @@ -68,4 +68,5 @@ set TZData(:Europe/Volgograd) { {1288479600 10800 0 +03} {1301180400 14400 0 +04} {1414274400 10800 0 +03} + {1540681200 14400 0 +04} } diff --git a/library/tzdata/Pacific/Easter b/library/tzdata/Pacific/Easter index a087cd0..7a8d525 100644 --- a/library/tzdata/Pacific/Easter +++ b/library/tzdata/Pacific/Easter @@ -103,166 +103,166 @@ set TZData(:Pacific/Easter) { {1502596800 -18000 1 -06} {1526180400 -21600 0 -06} {1534046400 -18000 1 -06} - {1557630000 -21600 0 -06} - {1565496000 -18000 1 -06} - {1589079600 -21600 0 -06} - {1596945600 -18000 1 -06} - {1620529200 -21600 0 -06} - {1629000000 -18000 1 -06} - {1652583600 -21600 0 -06} - {1660449600 -18000 1 -06} - {1684033200 -21600 0 -06} - {1691899200 -18000 1 -06} - {1715482800 -21600 0 -06} - {1723348800 -18000 1 -06} - {1746932400 -21600 0 -06} - {1754798400 -18000 1 -06} - {1778382000 -21600 0 -06} - {1786248000 -18000 1 -06} - {1809831600 -21600 0 -06} - {1818302400 -18000 1 -06} - {1841886000 -21600 0 -06} - {1849752000 -18000 1 -06} - {1873335600 -21600 0 -06} - {1881201600 -18000 1 -06} - {1904785200 -21600 0 -06} - {1912651200 -18000 1 -06} - {1936234800 -21600 0 -06} - {1944100800 -18000 1 -06} - {1967684400 -21600 0 -06} - {1976155200 -18000 1 -06} - {1999738800 -21600 0 -06} - {2007604800 -18000 1 -06} - {2031188400 -21600 0 -06} - {2039054400 -18000 1 -06} - {2062638000 -21600 0 -06} - {2070504000 -18000 1 -06} - {2094087600 -21600 0 -06} - {2101953600 -18000 1 -06} - {2125537200 -21600 0 -06} - {2133403200 -18000 1 -06} - {2156986800 -21600 0 -06} - {2165457600 -18000 1 -06} - {2189041200 -21600 0 -06} - {2196907200 -18000 1 -06} - {2220490800 -21600 0 -06} - {2228356800 -18000 1 -06} - {2251940400 -21600 0 -06} - {2259806400 -18000 1 -06} - {2283390000 -21600 0 -06} - {2291256000 -18000 1 -06} - {2314839600 -21600 0 -06} - {2322705600 -18000 1 -06} - {2346894000 -21600 0 -06} - {2354760000 -18000 1 -06} - {2378343600 -21600 0 -06} - {2386209600 -18000 1 -06} - {2409793200 -21600 0 -06} - {2417659200 -18000 1 -06} - {2441242800 -21600 0 -06} - {2449108800 -18000 1 -06} - {2472692400 -21600 0 -06} - {2480558400 -18000 1 -06} - {2504142000 -21600 0 -06} - {2512612800 -18000 1 -06} - {2536196400 -21600 0 -06} - {2544062400 -18000 1 -06} - {2567646000 -21600 0 -06} - {2575512000 -18000 1 -06} - {2599095600 -21600 0 -06} - {2606961600 -18000 1 -06} - {2630545200 -21600 0 -06} - {2638411200 -18000 1 -06} - {2661994800 -21600 0 -06} - {2669860800 -18000 1 -06} - {2693444400 -21600 0 -06} - {2701915200 -18000 1 -06} - {2725498800 -21600 0 -06} - {2733364800 -18000 1 -06} - {2756948400 -21600 0 -06} - {2764814400 -18000 1 -06} - {2788398000 -21600 0 -06} - {2796264000 -18000 1 -06} - {2819847600 -21600 0 -06} - {2827713600 -18000 1 -06} - {2851297200 -21600 0 -06} - {2859768000 -18000 1 -06} - {2883351600 -21600 0 -06} - {2891217600 -18000 1 -06} - {2914801200 -21600 0 -06} - {2922667200 -18000 1 -06} - {2946250800 -21600 0 -06} - {2954116800 -18000 1 -06} - {2977700400 -21600 0 -06} - {2985566400 -18000 1 -06} - {3009150000 -21600 0 -06} - {3017016000 -18000 1 -06} - {3040599600 -21600 0 -06} - {3049070400 -18000 1 -06} - {3072654000 -21600 0 -06} - {3080520000 -18000 1 -06} - {3104103600 -21600 0 -06} - {3111969600 -18000 1 -06} - {3135553200 -21600 0 -06} - {3143419200 -18000 1 -06} - {3167002800 -21600 0 -06} - {3174868800 -18000 1 -06} - {3198452400 -21600 0 -06} - {3206318400 -18000 1 -06} - {3230506800 -21600 0 -06} - {3238372800 -18000 1 -06} - {3261956400 -21600 0 -06} - {3269822400 -18000 1 -06} - {3293406000 -21600 0 -06} - {3301272000 -18000 1 -06} - {3324855600 -21600 0 -06} - {3332721600 -18000 1 -06} - {3356305200 -21600 0 -06} - {3364171200 -18000 1 -06} - {3387754800 -21600 0 -06} - {3396225600 -18000 1 -06} - {3419809200 -21600 0 -06} - {3427675200 -18000 1 -06} - {3451258800 -21600 0 -06} - {3459124800 -18000 1 -06} - {3482708400 -21600 0 -06} - {3490574400 -18000 1 -06} - {3514158000 -21600 0 -06} - {3522024000 -18000 1 -06} - {3545607600 -21600 0 -06} - {3553473600 -18000 1 -06} - {3577057200 -21600 0 -06} - {3585528000 -18000 1 -06} - {3609111600 -21600 0 -06} - {3616977600 -18000 1 -06} - {3640561200 -21600 0 -06} - {3648427200 -18000 1 -06} - {3672010800 -21600 0 -06} - {3679876800 -18000 1 -06} - {3703460400 -21600 0 -06} - {3711326400 -18000 1 -06} - {3734910000 -21600 0 -06} - {3743380800 -18000 1 -06} - {3766964400 -21600 0 -06} - {3774830400 -18000 1 -06} - {3798414000 -21600 0 -06} - {3806280000 -18000 1 -06} - {3829863600 -21600 0 -06} - {3837729600 -18000 1 -06} - {3861313200 -21600 0 -06} - {3869179200 -18000 1 -06} - {3892762800 -21600 0 -06} - {3900628800 -18000 1 -06} - {3924212400 -21600 0 -06} - {3932683200 -18000 1 -06} - {3956266800 -21600 0 -06} - {3964132800 -18000 1 -06} - {3987716400 -21600 0 -06} - {3995582400 -18000 1 -06} - {4019166000 -21600 0 -06} - {4027032000 -18000 1 -06} - {4050615600 -21600 0 -06} - {4058481600 -18000 1 -06} - {4082065200 -21600 0 -06} - {4089931200 -18000 1 -06} + {1554606000 -21600 0 -06} + {1567915200 -18000 1 -06} + {1586055600 -21600 0 -06} + {1599364800 -18000 1 -06} + {1617505200 -21600 0 -06} + {1630814400 -18000 1 -06} + {1648954800 -21600 0 -06} + {1662264000 -18000 1 -06} + {1680404400 -21600 0 -06} + {1693713600 -18000 1 -06} + {1712458800 -21600 0 -06} + {1725768000 -18000 1 -06} + {1743908400 -21600 0 -06} + {1757217600 -18000 1 -06} + {1775358000 -21600 0 -06} + {1788667200 -18000 1 -06} + {1806807600 -21600 0 -06} + {1820116800 -18000 1 -06} + {1838257200 -21600 0 -06} + {1851566400 -18000 1 -06} + {1870311600 -21600 0 -06} + {1883016000 -18000 1 -06} + {1901761200 -21600 0 -06} + {1915070400 -18000 1 -06} + {1933210800 -21600 0 -06} + {1946520000 -18000 1 -06} + {1964660400 -21600 0 -06} + {1977969600 -18000 1 -06} + {1996110000 -21600 0 -06} + {2009419200 -18000 1 -06} + {2027559600 -21600 0 -06} + {2040868800 -18000 1 -06} + {2059614000 -21600 0 -06} + {2072318400 -18000 1 -06} + {2091063600 -21600 0 -06} + {2104372800 -18000 1 -06} + {2122513200 -21600 0 -06} + {2135822400 -18000 1 -06} + {2153962800 -21600 0 -06} + {2167272000 -18000 1 -06} + {2185412400 -21600 0 -06} + {2198721600 -18000 1 -06} + {2217466800 -21600 0 -06} + {2230171200 -18000 1 -06} + {2248916400 -21600 0 -06} + {2262225600 -18000 1 -06} + {2280366000 -21600 0 -06} + {2293675200 -18000 1 -06} + {2311815600 -21600 0 -06} + {2325124800 -18000 1 -06} + {2343265200 -21600 0 -06} + {2356574400 -18000 1 -06} + {2374714800 -21600 0 -06} + {2388024000 -18000 1 -06} + {2406769200 -21600 0 -06} + {2419473600 -18000 1 -06} + {2438218800 -21600 0 -06} + {2451528000 -18000 1 -06} + {2469668400 -21600 0 -06} + {2482977600 -18000 1 -06} + {2501118000 -21600 0 -06} + {2514427200 -18000 1 -06} + {2532567600 -21600 0 -06} + {2545876800 -18000 1 -06} + {2564017200 -21600 0 -06} + {2577326400 -18000 1 -06} + {2596071600 -21600 0 -06} + {2609380800 -18000 1 -06} + {2627521200 -21600 0 -06} + {2640830400 -18000 1 -06} + {2658970800 -21600 0 -06} + {2672280000 -18000 1 -06} + {2690420400 -21600 0 -06} + {2703729600 -18000 1 -06} + {2721870000 -21600 0 -06} + {2735179200 -18000 1 -06} + {2753924400 -21600 0 -06} + {2766628800 -18000 1 -06} + {2785374000 -21600 0 -06} + {2798683200 -18000 1 -06} + {2816823600 -21600 0 -06} + {2830132800 -18000 1 -06} + {2848273200 -21600 0 -06} + {2861582400 -18000 1 -06} + {2879722800 -21600 0 -06} + {2893032000 -18000 1 -06} + {2911172400 -21600 0 -06} + {2924481600 -18000 1 -06} + {2943226800 -21600 0 -06} + {2955931200 -18000 1 -06} + {2974676400 -21600 0 -06} + {2987985600 -18000 1 -06} + {3006126000 -21600 0 -06} + {3019435200 -18000 1 -06} + {3037575600 -21600 0 -06} + {3050884800 -18000 1 -06} + {3069025200 -21600 0 -06} + {3082334400 -18000 1 -06} + {3101079600 -21600 0 -06} + {3113784000 -18000 1 -06} + {3132529200 -21600 0 -06} + {3145838400 -18000 1 -06} + {3163978800 -21600 0 -06} + {3177288000 -18000 1 -06} + {3195428400 -21600 0 -06} + {3208737600 -18000 1 -06} + {3226878000 -21600 0 -06} + {3240187200 -18000 1 -06} + {3258327600 -21600 0 -06} + {3271636800 -18000 1 -06} + {3290382000 -21600 0 -06} + {3303086400 -18000 1 -06} + {3321831600 -21600 0 -06} + {3335140800 -18000 1 -06} + {3353281200 -21600 0 -06} + {3366590400 -18000 1 -06} + {3384730800 -21600 0 -06} + {3398040000 -18000 1 -06} + {3416180400 -21600 0 -06} + {3429489600 -18000 1 -06} + {3447630000 -21600 0 -06} + {3460939200 -18000 1 -06} + {3479684400 -21600 0 -06} + {3492993600 -18000 1 -06} + {3511134000 -21600 0 -06} + {3524443200 -18000 1 -06} + {3542583600 -21600 0 -06} + {3555892800 -18000 1 -06} + {3574033200 -21600 0 -06} + {3587342400 -18000 1 -06} + {3605482800 -21600 0 -06} + {3618792000 -18000 1 -06} + {3637537200 -21600 0 -06} + {3650241600 -18000 1 -06} + {3668986800 -21600 0 -06} + {3682296000 -18000 1 -06} + {3700436400 -21600 0 -06} + {3713745600 -18000 1 -06} + {3731886000 -21600 0 -06} + {3745195200 -18000 1 -06} + {3763335600 -21600 0 -06} + {3776644800 -18000 1 -06} + {3794785200 -21600 0 -06} + {3808094400 -18000 1 -06} + {3826839600 -21600 0 -06} + {3839544000 -18000 1 -06} + {3858289200 -21600 0 -06} + {3871598400 -18000 1 -06} + {3889738800 -21600 0 -06} + {3903048000 -18000 1 -06} + {3921188400 -21600 0 -06} + {3934497600 -18000 1 -06} + {3952638000 -21600 0 -06} + {3965947200 -18000 1 -06} + {3984692400 -21600 0 -06} + {3997396800 -18000 1 -06} + {4016142000 -21600 0 -06} + {4029451200 -18000 1 -06} + {4047591600 -21600 0 -06} + {4060900800 -18000 1 -06} + {4079041200 -21600 0 -06} + {4092350400 -18000 1 -06} } diff --git a/library/tzdata/Pacific/Fiji b/library/tzdata/Pacific/Fiji index 610c191..b05985c 100644 --- a/library/tzdata/Pacific/Fiji +++ b/library/tzdata/Pacific/Fiji @@ -26,7 +26,7 @@ set TZData(:Pacific/Fiji) { {1509804000 46800 1 +12} {1515852000 43200 0 +12} {1541253600 46800 1 +12} - {1547906400 43200 0 +12} + {1547301600 43200 0 +12} {1572703200 46800 1 +12} {1579356000 43200 0 +12} {1604152800 46800 1 +12} @@ -48,7 +48,7 @@ set TZData(:Pacific/Fiji) { {1856959200 46800 1 +12} {1863007200 43200 0 +12} {1888408800 46800 1 +12} - {1895061600 43200 0 +12} + {1894456800 43200 0 +12} {1919858400 46800 1 +12} {1926511200 43200 0 +12} {1951308000 46800 1 +12} @@ -60,7 +60,7 @@ set TZData(:Pacific/Fiji) { {2046261600 46800 1 +12} {2052309600 43200 0 +12} {2077711200 46800 1 +12} - {2084364000 43200 0 +12} + {2083759200 43200 0 +12} {2109160800 46800 1 +12} {2115813600 43200 0 +12} {2140610400 46800 1 +12} @@ -70,7 +70,7 @@ set TZData(:Pacific/Fiji) { {2204114400 46800 1 +12} {2210162400 43200 0 +12} {2235564000 46800 1 +12} - {2242216800 43200 0 +12} + {2241612000 43200 0 +12} {2267013600 46800 1 +12} {2273666400 43200 0 +12} {2298463200 46800 1 +12} @@ -82,7 +82,7 @@ set TZData(:Pacific/Fiji) { {2393416800 46800 1 +12} {2399464800 43200 0 +12} {2424866400 46800 1 +12} - {2431519200 43200 0 +12} + {2430914400 43200 0 +12} {2456316000 46800 1 +12} {2462968800 43200 0 +12} {2487765600 46800 1 +12} @@ -104,7 +104,7 @@ set TZData(:Pacific/Fiji) { {2740572000 46800 1 +12} {2746620000 43200 0 +12} {2772021600 46800 1 +12} - {2778674400 43200 0 +12} + {2778069600 43200 0 +12} {2803471200 46800 1 +12} {2810124000 43200 0 +12} {2834920800 46800 1 +12} @@ -116,7 +116,7 @@ set TZData(:Pacific/Fiji) { {2929874400 46800 1 +12} {2935922400 43200 0 +12} {2961324000 46800 1 +12} - {2967976800 43200 0 +12} + {2967372000 43200 0 +12} {2992773600 46800 1 +12} {2999426400 43200 0 +12} {3024223200 46800 1 +12} @@ -126,7 +126,7 @@ set TZData(:Pacific/Fiji) { {3087727200 46800 1 +12} {3093775200 43200 0 +12} {3119176800 46800 1 +12} - {3125829600 43200 0 +12} + {3125224800 43200 0 +12} {3150626400 46800 1 +12} {3157279200 43200 0 +12} {3182076000 46800 1 +12} @@ -138,7 +138,7 @@ set TZData(:Pacific/Fiji) { {3277029600 46800 1 +12} {3283077600 43200 0 +12} {3308479200 46800 1 +12} - {3315132000 43200 0 +12} + {3314527200 43200 0 +12} {3339928800 46800 1 +12} {3346581600 43200 0 +12} {3371378400 46800 1 +12} @@ -160,7 +160,7 @@ set TZData(:Pacific/Fiji) { {3624184800 46800 1 +12} {3630232800 43200 0 +12} {3655634400 46800 1 +12} - {3662287200 43200 0 +12} + {3661682400 43200 0 +12} {3687084000 46800 1 +12} {3693736800 43200 0 +12} {3718533600 46800 1 +12} @@ -172,7 +172,7 @@ set TZData(:Pacific/Fiji) { {3813487200 46800 1 +12} {3819535200 43200 0 +12} {3844936800 46800 1 +12} - {3851589600 43200 0 +12} + {3850984800 43200 0 +12} {3876386400 46800 1 +12} {3883039200 43200 0 +12} {3907836000 46800 1 +12} @@ -182,7 +182,7 @@ set TZData(:Pacific/Fiji) { {3971340000 46800 1 +12} {3977388000 43200 0 +12} {4002789600 46800 1 +12} - {4009442400 43200 0 +12} + {4008837600 43200 0 +12} {4034239200 46800 1 +12} {4040892000 43200 0 +12} {4065688800 46800 1 +12} -- cgit v0.12 From 20213492498c729f4a953da797793ba5471607d8 Mon Sep 17 00:00:00 2001 From: dkf Date: Thu, 18 Oct 2018 21:38:08 +0000 Subject: Make fundamental mutation work. MAGICAL MAGIC MAGICS MAGIC. Abracadabra. --- generic/tclOO.c | 109 +++++++++++++++++++++++++++++----------------- generic/tclOOCall.c | 1 - generic/tclOODefineCmds.c | 14 +++++- generic/tclOOInt.h | 8 ++++ tests/oo.test | 17 +++++--- 5 files changed, 101 insertions(+), 48 deletions(-) diff --git a/generic/tclOO.c b/generic/tclOO.c index 83646a8..573df3e 100644 --- a/generic/tclOO.c +++ b/generic/tclOO.c @@ -56,7 +56,6 @@ static const struct { * Function declarations for things defined in this file. */ -static Class * AllocClass(Tcl_Interp *interp, Object *useThisObj); static Object * AllocObject(Tcl_Interp *interp, const char *nameStr, Namespace *nsPtr, const char *nsNameStr); static int CloneClassMethod(Tcl_Interp *interp, Class *clsPtr, @@ -79,8 +78,6 @@ static void ObjectNamespaceDeleted(ClientData clientData); static void ObjectRenamedTrace(ClientData clientData, Tcl_Interp *interp, const char *oldName, const char *newName, int flags); -static void ReleaseClassContents(Tcl_Interp *interp,Object *oPtr); -static void DeleteDescendants(Tcl_Interp *interp,Object *oPtr); static inline void SquelchCachedName(Object *oPtr); static int PublicObjectCmd(ClientData clientData, @@ -392,10 +389,10 @@ InitFoundation( /* Stand up a phony class for bootstrapping. */ fPtr->objectCls = &fakeCls; - /* referenced in AllocClass to increment the refCount. */ + /* referenced in TclOOAllocClass to increment the refCount. */ fakeCls.thisPtr = &fakeObject; - fPtr->objectCls = AllocClass(interp, + fPtr->objectCls = TclOOAllocClass(interp, AllocObject(interp, "object", (Namespace *)fPtr->ooNs, NULL)); /* Corresponding TclOODecrRefCount in KillFoudation */ AddRef(fPtr->objectCls->thisPtr); @@ -411,7 +408,7 @@ InitFoundation( fPtr->objectCls->thisPtr->flags |= ROOT_OBJECT; fPtr->objectCls->flags |= ROOT_OBJECT; - fPtr->classCls = AllocClass(interp, + fPtr->classCls = TclOOAllocClass(interp, AllocObject(interp, "class", (Namespace *)fPtr->ooNs, NULL)); /* Corresponding TclOODecrRefCount in KillFoudation */ AddRef(fPtr->classCls->thisPtr); @@ -829,15 +826,15 @@ ObjectRenamedTrace( /* * ---------------------------------------------------------------------- * - * DeleteDescendants -- + * TclOODeleteDescendants -- * * Delete all descendants of a particular class. * * ---------------------------------------------------------------------- */ -static void -DeleteDescendants( +void +TclOODeleteDescendants( Tcl_Interp *interp, /* The interpreter containing the class. */ Object *oPtr) /* The object representing the class. */ { @@ -854,7 +851,8 @@ DeleteDescendants( /* This condition also covers the case where mixinSubclassPtr == * clsPtr */ - if (!Deleted(mixinSubclassPtr->thisPtr)) { + if (!Deleted(mixinSubclassPtr->thisPtr) + && !(mixinSubclassPtr->thisPtr->flags & DONT_DELETE)) { Tcl_DeleteCommandFromToken(interp, mixinSubclassPtr->thisPtr->command); } @@ -872,8 +870,10 @@ DeleteDescendants( if (clsPtr->subclasses.num > 0) { while (clsPtr->subclasses.num > 0) { subclassPtr = clsPtr->subclasses.list[clsPtr->subclasses.num-1]; - if (!Deleted(subclassPtr->thisPtr) && !IsRoot(subclassPtr)) { - Tcl_DeleteCommandFromToken(interp, subclassPtr->thisPtr->command); + if (!Deleted(subclassPtr->thisPtr) && !IsRoot(subclassPtr) + && !(subclassPtr->thisPtr->flags & DONT_DELETE)) { + Tcl_DeleteCommandFromToken(interp, + subclassPtr->thisPtr->command); } TclOORemoveFromSubclasses(subclassPtr, clsPtr); } @@ -892,7 +892,8 @@ DeleteDescendants( while (clsPtr->instances.num > 0) { instancePtr = clsPtr->instances.list[clsPtr->instances.num-1]; /* This condition also covers the case where instancePtr == oPtr */ - if (!Deleted(instancePtr) && !IsRoot(instancePtr)) { + if (!Deleted(instancePtr) && !IsRoot(instancePtr) && + !(instancePtr->flags & DONT_DELETE)) { Tcl_DeleteCommandFromToken(interp, instancePtr->command); } TclOORemoveFromInstances(instancePtr, clsPtr); @@ -909,7 +910,7 @@ DeleteDescendants( /* * ---------------------------------------------------------------------- * - * ReleaseClassContents -- + * TclOOReleaseClassContents -- * * Tear down the special class data structure, including deleting all * dependent classes and objects. @@ -917,8 +918,8 @@ DeleteDescendants( * ---------------------------------------------------------------------- */ -static void -ReleaseClassContents( +void +TclOOReleaseClassContents( Tcl_Interp *interp, /* The interpreter containing the class. */ Object *oPtr) /* The object representing the class. */ { @@ -940,9 +941,6 @@ ReleaseClassContents( } else if (IsRootObject(oPtr)) { Tcl_Panic("deleting class structure for non-deleted %s", "::oo::object"); - } else { - Tcl_Panic("deleting class structure for non-deleted %s", - "general object"); } } @@ -1037,6 +1035,7 @@ ReleaseClassContents( if (IsRootClass(oPtr) && !Deleted(fPtr->objectCls->thisPtr)) { Tcl_DeleteCommandFromToken(interp, fPtr->objectCls->thisPtr->command); } + oPtr->classPtr = NULL; } /* @@ -1082,7 +1081,7 @@ ObjectNamespaceDeleted( /* Let the dominoes fall */ if (oPtr->classPtr) { - DeleteDescendants(interp, oPtr); + TclOODeleteDescendants(interp, oPtr); } /* @@ -1194,27 +1193,25 @@ ObjectNamespaceDeleted( } /* - * Because an object can be a class that is an instance of itself, the - * A class object's class structure should only be cleaned after most of - * the cleanup on the object is done. - */ - - - /* + * Because an object can be a class that is an instance of itself, the + * class object's class structure should only be cleaned after most of + * the cleanup on the object is done. + * * The class of objects needs some special care; if it is deleted (and * we're not killing the whole interpreter) we force the delete of the * class of classes now as well. Due to the incestuous nature of those two * classes, if one goes the other must too and yet the tangle can * sometimes not go away automatically; we force it here. [Bug 2962664] */ + if (IsRootObject(oPtr) && !Deleted(fPtr->classCls->thisPtr) - && !Tcl_InterpDeleted(interp)) { + && !Tcl_InterpDeleted(interp)) { Tcl_DeleteCommandFromToken(interp, fPtr->classCls->thisPtr->command); } if (oPtr->classPtr != NULL) { - ReleaseClassContents(interp, oPtr); + TclOOReleaseClassContents(interp, oPtr); } /* @@ -1328,6 +1325,37 @@ TclOOAddToInstances( /* * ---------------------------------------------------------------------- * + * TclOORemoveFromMixins -- + * + * Utility function to remove a class from the list of mixins within an + * object. + * + * ---------------------------------------------------------------------- + */ + +int +TclOORemoveFromMixins( + Class *mixinPtr, /* The mixin to remove. */ + Object *oPtr) /* The object (possibly) containing the + * reference to the mixin. */ +{ + int i, res = 0; + Class *mixPtr; + + FOREACH(mixPtr, oPtr->mixins) { + if (mixinPtr == mixPtr) { + RemoveItem(Class, oPtr->mixins, i); + TclOODecrRefCount(mixPtr->thisPtr); + res++; + break; + } + } + return res; +} + +/* + * ---------------------------------------------------------------------- + * * TclOORemoveFromSubclasses -- * * Utility function to remove a class from the list of subclasses within @@ -1381,7 +1409,8 @@ TclOOAddToSubclasses( if (superPtr->subclasses.size == ALLOC_CHUNK) { superPtr->subclasses.list = ckalloc(sizeof(Class *) * ALLOC_CHUNK); } else { - superPtr->subclasses.list = ckrealloc(superPtr->subclasses.list, sizeof(Class *) * superPtr->subclasses.size); + superPtr->subclasses.list = ckrealloc(superPtr->subclasses.list, + sizeof(Class *) * superPtr->subclasses.size); } } superPtr->subclasses.list[superPtr->subclasses.num++] = subPtr; @@ -1456,16 +1485,16 @@ TclOOAddToMixinSubs( /* * ---------------------------------------------------------------------- * - * AllocClass -- + * TclOOAllocClass -- * - * Allocate a basic class. Does not add class to its - * class's instance list. + * Allocate a basic class. Does not add class to its class's instance + * list. * * ---------------------------------------------------------------------- */ -static Class * -AllocClass( +Class * +TclOOAllocClass( Tcl_Interp *interp, /* Interpreter within which to allocate the * class. */ Object *useThisObj) /* Object that is to act as the class @@ -1709,13 +1738,13 @@ TclNewObjectInstanceCommon( if (TclOOIsReachable(fPtr->classCls, classPtr)) { /* - * Is a class, so attach a class structure. Note that the AllocClass - * function splices the structure into the object, so we don't have - * to. Once that's done, we need to repatch the object to have the - * right class since AllocClass interferes with that. + * Is a class, so attach a class structure. Note that the + * TclOOAllocClass function splices the structure into the object, so + * we don't have to. Once that's done, we need to repatch the object + * to have the right class since TclOOAllocClass interferes with that. */ - AllocClass(interp, oPtr); + TclOOAllocClass(interp, oPtr); TclOOAddToSubclasses(oPtr->classPtr, fPtr->objectCls); } else { oPtr->classPtr = NULL; diff --git a/generic/tclOOCall.c b/generic/tclOOCall.c index c71425b..a46b8bc 100644 --- a/generic/tclOOCall.c +++ b/generic/tclOOCall.c @@ -1444,7 +1444,6 @@ AddSimpleClassChainToCallContext( if (flags & CONSTRUCTOR) { AddMethodToCallChain(classPtr->constructorPtr, cbPtr, doneFilters, filterDecl, flags); - } else if (flags & DESTRUCTOR) { AddMethodToCallChain(classPtr->destructorPtr, cbPtr, doneFilters, filterDecl, flags); diff --git a/generic/tclOODefineCmds.c b/generic/tclOODefineCmds.c index f5fe676..d5f4878 100644 --- a/generic/tclOODefineCmds.c +++ b/generic/tclOODefineCmds.c @@ -1146,9 +1146,19 @@ TclOODefineClassObjCmd( */ if (wasClass && !willBeClass) { - /* TODO: DELETE THE STRUCTURE */ + /* + * This is the most global of all epochs. Bump it! No cache can be + * trusted! + */ + + TclOORemoveFromMixins(oPtr->classPtr, oPtr); + oPtr->fPtr->epoch++; + oPtr->flags |= DONT_DELETE; + TclOODeleteDescendants(interp, oPtr); + oPtr->flags &= ~DONT_DELETE; + TclOOReleaseClassContents(interp, oPtr); } else if (!wasClass && willBeClass) { - /* TODO: CREATE THE STRUCTURE */ + TclOOAllocClass(interp, oPtr); } if (oPtr->classPtr != NULL) { diff --git a/generic/tclOOInt.h b/generic/tclOOInt.h index 61ead01..e59fe8a 100644 --- a/generic/tclOOInt.h +++ b/generic/tclOOInt.h @@ -214,6 +214,7 @@ typedef struct Object { * other spots). */ #define FORCE_UNKNOWN 0x10000 /* States that we are *really* looking up the * unknown method handler at that point. */ +#define DONT_DELETE 0x20000 /* Inhibit deletion of this object. */ /* * And the definition of a class. Note that every class also has an associated @@ -484,6 +485,8 @@ MODULE_SCOPE int TclOO_Object_VarName(ClientData clientData, MODULE_SCOPE void TclOOAddToInstances(Object *oPtr, Class *clsPtr); MODULE_SCOPE void TclOOAddToMixinSubs(Class *subPtr, Class *mixinPtr); MODULE_SCOPE void TclOOAddToSubclasses(Class *subPtr, Class *superPtr); +MODULE_SCOPE Class * TclOOAllocClass(Tcl_Interp *interp, + Object *useThisObj); MODULE_SCOPE int TclNRNewObjectInstance(Tcl_Interp *interp, Tcl_Class cls, const char *nameStr, const char *nsNameStr, int objc, @@ -498,6 +501,8 @@ MODULE_SCOPE int TclOODefineSlots(Foundation *fPtr); MODULE_SCOPE void TclOODeleteChain(CallChain *callPtr); MODULE_SCOPE void TclOODeleteChainCache(Tcl_HashTable *tablePtr); MODULE_SCOPE void TclOODeleteContext(CallContext *contextPtr); +MODULE_SCOPE void TclOODeleteDescendants(Tcl_Interp *interp, + Object *oPtr); MODULE_SCOPE void TclOODelMethodRef(Method *method); MODULE_SCOPE CallContext *TclOOGetCallContext(Object *oPtr, Tcl_Obj *methodNameObj, int flags, @@ -523,7 +528,10 @@ MODULE_SCOPE int TclNRObjectContextInvokeNext(Tcl_Interp *interp, MODULE_SCOPE void TclOONewBasicMethod(Tcl_Interp *interp, Class *clsPtr, const DeclaredClassMethod *dcm); MODULE_SCOPE Tcl_Obj * TclOOObjectName(Tcl_Interp *interp, Object *oPtr); +MODULE_SCOPE void TclOOReleaseClassContents(Tcl_Interp *interp, + Object *oPtr); MODULE_SCOPE int TclOORemoveFromInstances(Object *oPtr, Class *clsPtr); +MODULE_SCOPE int TclOORemoveFromMixins(Class *mixinPtr, Object *oPtr); MODULE_SCOPE int TclOORemoveFromMixinSubs(Class *subPtr, Class *mixinPtr); MODULE_SCOPE int TclOORemoveFromSubclasses(Class *subPtr, diff --git a/tests/oo.test b/tests/oo.test index 7f0de4a..0558746 100644 --- a/tests/oo.test +++ b/tests/oo.test @@ -1804,7 +1804,7 @@ test oo-13.4 {OO: changing an object's class} -body { foo destroy bar destroy } -result {::foo ::foo ::foo ::bar} -test oo-13.5 {OO: changing an object's class} -setup { +test oo-13.5 {OO: changing an object's class: non-class to class} -setup { oo::object create fooObj } -body { oo::objdefine fooObj { @@ -1817,21 +1817,28 @@ test oo-13.5 {OO: changing an object's class} -setup { } -cleanup { fooObj destroy } -result 6 -test oo-13.6 {OO: changing an object's class} -setup { +test oo-13.6 {OO: changing an object's class: class to non-class} -setup { oo::class create foo + unset -nocomplain ::result } -body { + set result dangling oo::define foo { method x {} {expr 1+2+3} } + oo::class create boo { + superclass foo + destructor {set ::result "ok"} + } + boo new foo create bar oo::objdefine foo { class oo::object } - list [catch {bar x} msg] $msg + list $result [catch {bar x} msg] $msg } -cleanup { catch {bar destroy} foo destroy -} -result {1 {}} +} -result {ok 1 {invalid command name "bar"}} test oo-13.7 {OO: changing an object's class} -setup { oo::class create foo oo::class create bar @@ -1849,7 +1856,7 @@ test oo-13.7 {OO: changing an object's class} -setup { foo destroy bar destroy } -result {6 ok} -test oo-13.7 {OO: changing an object's class to itself} -setup { +test oo-13.8 {OO: changing an object's class to itself} -setup { oo::class create foo } -body { oo::define foo { -- cgit v0.12 From 09446c7544e32d0eca9c0c68d7917729e6c33ee8 Mon Sep 17 00:00:00 2001 From: dkf Date: Fri, 19 Oct 2018 09:59:14 +0000 Subject: Added another test case. This one is OK. --- tests/oo.test | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/oo.test b/tests/oo.test index 0558746..db5c14f 100644 --- a/tests/oo.test +++ b/tests/oo.test @@ -1888,6 +1888,22 @@ test oo-13.10 {OO: changing an object's class: roots are special} -setup { } -cleanup { interp delete $i } -returnCodes error -result {may not modify the class of the class of classes} +test oo-13.11 {OO: changing an object's class in a tricky place} -setup { + oo::class create cls + unset -nocomplain result +} -body { + set result gorp + list [catch { + oo::define cls { + method x {} {return} + self class oo::object + ::set ::result ok + method y {} {return}; # I'm sorry, Dave. I'm afraid I can't do that. + } + } msg] $msg $result +} -cleanup { + cls destroy +} -result {1 {attempt to misuse API} ok} # todo: changing a class subtype (metaclass) to another class subtype test oo-14.1 {OO: mixins} { -- cgit v0.12 From 49aba3d99eb7035ee260003ddc27728b26962d43 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Fri, 19 Oct 2018 15:51:36 +0000 Subject: Add support for "nostub" in genStubs.tcl. Not used by Tcl 8.6, but might be used by Tk 8.7 when linked against Tcl 8.6 --- tools/genStubs.tcl | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tools/genStubs.tcl b/tools/genStubs.tcl index 830ba2b..f2f410f 100644 --- a/tools/genStubs.tcl +++ b/tools/genStubs.tcl @@ -198,6 +198,13 @@ proc genStubs::declare {args} { || ($index > $stubs($curName,generic,lastNum))} { set stubs($curName,generic,lastNum) $index } + } elseif {([lindex $platformList 0] eq "nostub")} { + set stubs($curName,nostub,$index) [lindex $platformList 1] + set stubs($curName,generic,$index) $decl + if {![info exists stubs($curName,generic,lastNum)] \ + || ($index > $stubs($curName,generic,lastNum))} { + set stubs($curName,generic,lastNum) $index + } } else { foreach platform $platformList { if {$decl ne ""} { @@ -593,6 +600,8 @@ proc genStubs::makeSlot {name decl index} { set text " " if {[info exists stubs($name,deprecated,$index)]} { append text "TCL_DEPRECATED_API(\"$stubs($name,deprecated,$index)\") " + } elseif {[info exists stubs($name,nostub,$index)]} { + append text "TCL_DEPRECATED_API(\"$stubs($name,nostub,$index)\") " } if {$args eq ""} { append text $rtype " *" $lfname "; /* $index */\n" @@ -705,6 +714,9 @@ proc genStubs::forAllStubs {name slotProc onAll textVar if {[info exists stubs($name,deprecated,$i)]} { append text [$slotProc $name $stubs($name,generic,$i) $i] set emit 1 + } elseif {[info exists stubs($name,nostub,$i)]} { + append text [$slotProc $name $stubs($name,generic,$i) $i] + set emit 1 } elseif {[info exists stubs($name,generic,$i)]} { if {[llength $slots] > 1} { puts stderr "conflicting generic and platform entries:\ -- cgit v0.12 From 50ae8fdcf6340dd85f832fb31b363e767f9430f8 Mon Sep 17 00:00:00 2001 From: dgp Date: Fri, 19 Oct 2018 19:18:30 +0000 Subject: [d1d05d1c7a] Tests and fix for bignums in end-offset index value parsing. --- generic/tclUtil.c | 46 ++++++++++++++++++++++++---------------------- tests/util.test | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 22 deletions(-) diff --git a/generic/tclUtil.c b/generic/tclUtil.c index 4ea9c2e..d3136e2 100644 --- a/generic/tclUtil.c +++ b/generic/tclUtil.c @@ -3660,10 +3660,12 @@ TclFormatInt( * GetWideForIndex -- * * This function produces a wide integer value corresponding to the - * list index held in *objPtr. The parsing supports all values + * index value held in *objPtr. The parsing supports all values * recognized as any size of integer, and the syntaxes end[-+]$integer * and $integer[-+]$integer. The argument endValue is used to give - * the meaning of the literal index value "end". + * the meaning of the literal index value "end". Index arithmetic + * on arguments outside the wide integer range are only accepted + * when interp is a working interpreter, not NULL. * * Results: * When parsing of *objPtr successfully recognizes an index value, @@ -3994,6 +3996,8 @@ SetEndOffsetFromAny( bytes = TclGetStringFromObj(objPtr, &length); if ((*bytes != 'e') || (strncmp(bytes, "end", (size_t)((length > 3) ? 3 : length)) != 0)) { + + badIndexFormat: if (interp != NULL) { Tcl_SetObjResult(interp, Tcl_ObjPrintf( "bad index \"%s\": must be end?[+-]integer?", bytes)); @@ -4013,35 +4017,33 @@ SetEndOffsetFromAny( * This is our limited string expression evaluator. Pass everything * after "end-" to TclParseNumber. */ + ClientData cd; + int t; if (TclIsSpaceProc(bytes[4])) { goto badIndexFormat; } if (TclParseNumber(NULL, objPtr, NULL, bytes+4, length-4, NULL, TCL_PARSE_INTEGER_ONLY) != TCL_OK) { - return TCL_ERROR; - } - if (objPtr->typePtr != &tclIntType) { - goto badIndexFormat; + goto badIndexFormat; } - offset = objPtr->internalRep.wideValue; - if (bytes[3] == '-') { - - /* TODO: Review overflow concerns here! */ - offset = -offset; + TclGetNumberFromObj(NULL, objPtr, &cd, &t); + if (t == TCL_NUMBER_BIG) { + /* Truncate to the signed wide range. */ + if (mp_isneg((mp_int *)cd)) { + offset = (bytes[3] == '-') ? LLONG_MAX : LLONG_MIN; + } else { + offset = (bytes[3] == '-') ? LLONG_MIN : LLONG_MAX; + } + } else { + /* assert (t == TCL_NUMBER_INT); */ + offset = (*(Tcl_WideInt *)cd); + if (bytes[3] == '-') { + offset = (offset == LLONG_MIN) ? LLONG_MAX : -offset; + } } } else { - /* - * Conversion failed. Report the error. - */ - - badIndexFormat: - if (interp != NULL) { - Tcl_SetObjResult(interp, Tcl_ObjPrintf( - "bad index \"%s\": must be end?[+-]integer?", bytes)); - Tcl_SetErrorCode(interp, "TCL", "VALUE", "INDEX", NULL); - } - return TCL_ERROR; + goto badIndexFormat; } /* diff --git a/tests/util.test b/tests/util.test index 34113c0..9422fc3 100644 --- a/tests/util.test +++ b/tests/util.test @@ -735,6 +735,43 @@ test util-9.45 {TclGetIntForIndex} { test util-9.46 {TclGetIntForIndex} { string index abcd end+4294967294 } {} +# TIP 502 +test util-9.47 {TclGetIntForIndex} { + string index abcd 0x10000000000000000 +} {} +test util-9.48 {TclGetIntForIndex} { + string index abcd -0x10000000000000000 +} {} +test util-9.49 {TclGetIntForIndex} -body { + string index abcd end*1 +} -returnCodes error -match glob -result * +test util-9.50 {TclGetIntForIndex} -body { + string index abcd {end- 1} +} -returnCodes error -match glob -result * +test util-9.51 {TclGetIntForIndex} -body { + string index abcd end-end +} -returnCodes error -match glob -result * +test util-9.52 {TclGetIntForIndex} -body { + string index abcd end-x +} -returnCodes error -match glob -result * +test util-9.53 {TclGetIntForIndex} -body { + string index abcd end-0.1 +} -returnCodes error -match glob -result * +test util-9.54 {TclGetIntForIndex} { + string index abcd end-0x10000000000000000 +} {} +test util-9.55 {TclGetIntForIndex} { + string index abcd end+0x10000000000000000 +} {} +test util-9.56 {TclGetIntForIndex} { + string index abcd end--0x10000000000000000 +} {} +test util-9.57 {TclGetIntForIndex} { + string index abcd end+-0x10000000000000000 +} {} +test util-9.58 {TclGetIntForIndex} { + string index abcd end--0x8000000000000000 +} {} test util-10.1 {Tcl_PrintDouble - rounding} {ieeeFloatingPoint} { convertDouble 0x0000000000000000 -- cgit v0.12 From 7c2e55d3fd36b023222fe729d58855327f13c589 Mon Sep 17 00:00:00 2001 From: dkf Date: Sun, 21 Oct 2018 10:50:21 +0000 Subject: Squash warnings in the OSX notifier --- macosx/tclMacOSXNotify.c | 101 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 87 insertions(+), 14 deletions(-) diff --git a/macosx/tclMacOSXNotify.c b/macosx/tclMacOSXNotify.c index 1af73de..b21130b 100644 --- a/macosx/tclMacOSXNotify.c +++ b/macosx/tclMacOSXNotify.c @@ -31,6 +31,9 @@ */ #if defined(HAVE_LIBKERN_OSATOMIC_H) && defined(HAVE_OSSPINLOCKLOCK) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#pragma GCC diagnostic ignored "-Wunused-function" /* * Use OSSpinLock API where available (Tiger or later). */ @@ -42,14 +45,17 @@ * Support for weakly importing spinlock API. */ #define WEAK_IMPORT_SPINLOCKLOCK + #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1050 #define VOLATILE volatile #else #define VOLATILE #endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 1050 */ + #ifndef bool #define bool int #endif + extern void OSSpinLockLock(VOLATILE OSSpinLock *lock) WEAK_IMPORT_ATTRIBUTE; extern void OSSpinLockUnlock(VOLATILE OSSpinLock *lock) @@ -77,13 +83,54 @@ SpinLockLockInit(void) Tcl_Panic("SpinLockLockInit: no spinlock API available"); } } -#define SpinLockLock(p) lockLock(p) -#define SpinLockUnlock(p) lockUnlock(p) -#define SpinLockTry(p) lockTry(p) -#else -#define SpinLockLock(p) OSSpinLockLock(p) -#define SpinLockUnlock(p) OSSpinLockUnlock(p) -#define SpinLockTry(p) OSSpinLockTry(p) + +/* + * Wrappers so that we get warnings in just one small part of this file. + */ + +static inline void +SpinLockLock( + VOLATILE OSSpinLock *lock) +{ + lockLock(lock); +} +static inline void +SpinLockUnlock( + VOLATILE OSSpinLock *lock) +{ + lockUnlock(lock); +} +static inline bool +SpinLockTry( + VOLATILE OSSpinLock *lock) +{ + return lockTry(lock); +} + +#else /* !HAVE_WEAK_IMPORT */ + +/* + * Wrappers so that we get warnings in just one small part of this file. + */ + +static inline void +SpinLockLock( + OSSpinLock *lock) +{ + OSSpinLockLock(lock); +} +static inline void +SpinLockUnlock( + OSSpinLock *lock) +{ + OSSpinLockUnlock(lock); +} +static inline bool +SpinLockTry( + OSSpinLock *lock) +{ + return OSSpinLockTry(lock); +} #endif /* HAVE_WEAK_IMPORT */ #define SPINLOCK_INIT OS_SPINLOCK_INIT @@ -93,14 +140,37 @@ SpinLockLockInit(void) */ typedef uint32_t OSSpinLock; -extern void _spin_lock(OSSpinLock *lock); -extern void _spin_unlock(OSSpinLock *lock); -extern int _spin_lock_try(OSSpinLock *lock); -#define SpinLockLock(p) _spin_lock(p) -#define SpinLockUnlock(p) _spin_unlock(p) -#define SpinLockTry(p) _spin_lock_try(p) + +static inline void +SpinLockLock( + OSSpinLock *lock) +{ + extern void _spin_lock(OSSpinLock *lock); + + _spin_lock(lock); +} + +static inline void +SpinLockUnlock( + OSSpinLock *lock) +{ + extern void _spin_unlock(OSSpinLock *lock); + + _spin_unlock(lock); +} + +static inline int +SpinLockTry( + OSSpinLock *lock) +{ + extern int _spin_lock_try(OSSpinLock *lock); + + return _spin_lock_try(lock); +} + #define SPINLOCK_INIT 0 +#pragma GCC diagnostic pop #endif /* HAVE_LIBKERN_OSATOMIC_H && HAVE_OSSPINLOCKLOCK */ /* @@ -1411,7 +1481,10 @@ UpdateWaitingListAndServiceEvents( (tsdPtr->runLoopNestingLevel > 1 || !tsdPtr->runLoopRunning)) { tsdPtr->runLoopServicingEvents = 1; - /* This call seems to simply force event processing through and prevents hangups that have long been observed with Tk-Cocoa. */ + /* + * This call seems to simply force event processing through and + * prevents hangups that have long been observed with Tk-Cocoa. + */ Tcl_ServiceAll(); tsdPtr->runLoopServicingEvents = 0; } -- cgit v0.12 From d2c82fc45af53738344500a542ebe0333d5c89ac Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Sun, 21 Oct 2018 20:38:02 +0000 Subject: Change PTR2INT and PTR2UINT macros's so they can handle long's and Tcl_WideInt's too, so no longer restricted to the "int" range. --- generic/tclDisassemble.c | 2 +- generic/tclInt.h | 8 ++++---- generic/tclScan.c | 3 +-- generic/tclTest.c | 4 ++-- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/generic/tclDisassemble.c b/generic/tclDisassemble.c index a0d1258..6580d59 100644 --- a/generic/tclDisassemble.c +++ b/generic/tclDisassemble.c @@ -1610,7 +1610,7 @@ Tcl_DisassembleObjCmd( "BYTECODE", NULL); return TCL_ERROR; } - if (PTR2INT(clientData)) { + if (clientData) { Tcl_SetObjResult(interp, DisassembleByteCodeAsDicts(interp, codeObjPtr)); } else { diff --git a/generic/tclInt.h b/generic/tclInt.h index 1823c70..abf6c83 100644 --- a/generic/tclInt.h +++ b/generic/tclInt.h @@ -120,19 +120,19 @@ typedef int ptrdiff_t; #if !defined(INT2PTR) && !defined(PTR2INT) # if defined(HAVE_INTPTR_T) || defined(intptr_t) # define INT2PTR(p) ((void *)(intptr_t)(p)) -# define PTR2INT(p) ((int)(intptr_t)(p)) +# define PTR2INT(p) ((intptr_t)(p)) # else # define INT2PTR(p) ((void *)(p)) -# define PTR2INT(p) ((int)(p)) +# define PTR2INT(p) ((long)(p)) # endif #endif #if !defined(UINT2PTR) && !defined(PTR2UINT) # if defined(HAVE_UINTPTR_T) || defined(uintptr_t) # define UINT2PTR(p) ((void *)(uintptr_t)(p)) -# define PTR2UINT(p) ((unsigned int)(uintptr_t)(p)) +# define PTR2UINT(p) ((uintptr_t)(p)) # else # define UINT2PTR(p) ((void *)(p)) -# define PTR2UINT(p) ((unsigned int)(p)) +# define PTR2UINT(p) ((unsigned long)(p)) # endif #endif diff --git a/generic/tclScan.c b/generic/tclScan.c index 733409e..6a1311f 100644 --- a/generic/tclScan.c +++ b/generic/tclScan.c @@ -932,8 +932,7 @@ Tcl_ScanObjCmd( } } if ((flags & SCAN_UNSIGNED) && (wideValue < 0)) { - sprintf(buf, "%" TCL_LL_MODIFIER "u", - (Tcl_WideUInt)wideValue); + sprintf(buf, "%" TCL_LL_MODIFIER "u", wideValue); Tcl_SetStringObj(objPtr, buf, -1); } else { TclSetIntObj(objPtr, wideValue); diff --git a/generic/tclTest.c b/generic/tclTest.c index 18bfc1b..2cdd356 100644 --- a/generic/tclTest.c +++ b/generic/tclTest.c @@ -2394,7 +2394,7 @@ ExitProcOdd( char buf[16 + TCL_INTEGER_SPACE]; size_t len; - sprintf(buf, "odd %d\n", PTR2INT(clientData)); + sprintf(buf, "odd %" TCL_Z_MODIFIER "d\n", (size_t)PTR2INT(clientData)); len = strlen(buf); if (len != (size_t) write(1, buf, len)) { Tcl_Panic("ExitProcOdd: unable to write to stdout"); @@ -2408,7 +2408,7 @@ ExitProcEven( char buf[16 + TCL_INTEGER_SPACE]; size_t len; - sprintf(buf, "even %d\n", PTR2INT(clientData)); + sprintf(buf, "even %" TCL_Z_MODIFIER "d\n", (size_t)PTR2INT(clientData)); len = strlen(buf); if (len != (size_t) write(1, buf, len)) { Tcl_Panic("ExitProcEven: unable to write to stdout"); -- cgit v0.12 From e4c108f3d733e6bb21a26541c394fa36df135f5a Mon Sep 17 00:00:00 2001 From: dkf Date: Mon, 22 Oct 2018 04:30:24 +0000 Subject: Make new notifier code match Engineering Manual guidelines better --- unix/tclEpollNotfy.c | 225 ++++++++++++++++++++++++++---------------------- unix/tclKqueueNotfy.c | 231 ++++++++++++++++++++++++++------------------------ unix/tclSelectNotfy.c | 125 +++++++++++++-------------- unix/tclUnixNotfy.c | 52 ++++++------ 4 files changed, 332 insertions(+), 301 deletions(-) diff --git a/unix/tclEpollNotfy.c b/unix/tclEpollNotfy.c index 2abfd47..7a5e09d 100644 --- a/unix/tclEpollNotfy.c +++ b/unix/tclEpollNotfy.c @@ -2,8 +2,8 @@ * tclEpollNotfy.c -- * * This file contains the implementation of the epoll()-based - * Linux-specific notifier, which is the lowest-level part of the - * Tcl event loop. This file works together with generic/tclNotify.c. + * Linux-specific notifier, which is the lowest-level part of the Tcl + * event loop. This file works together with generic/tclNotify.c. * * Copyright (c) 1995-1997 Sun Microsystems, Inc. * Copyright (c) 2016 Lucio Andrés Illanes Albornoz @@ -13,11 +13,10 @@ */ #include "tclInt.h" -#if defined(NOTIFIER_EPOLL) && TCL_THREADS - -#define _GNU_SOURCE /* For pipe2(2) */ #ifndef HAVE_COREFOUNDATION /* Darwin/Mac OS X CoreFoundation notifier is * in tclMacOSXNotify.c */ +#if defined(NOTIFIER_EPOLL) && TCL_THREADS +#define _GNU_SOURCE /* For pipe2(2) */ #include #include #include @@ -54,9 +53,9 @@ typedef struct FileHandler { } FileHandler; /* - * The following structure associates a FileHandler and the thread that owns it - * with the file descriptors of interest and their event masks passed to epoll_ctl(2) - * and their corresponding event(s) returned by epoll_wait(2). + * The following structure associates a FileHandler and the thread that owns + * it with the file descriptors of interest and their event masks passed to + * epoll_ctl(2) and their corresponding event(s) returned by epoll_wait(2). */ struct ThreadSpecificData; @@ -105,7 +104,8 @@ typedef struct ThreadSpecificData { int triggerPipe[2]; /* pipe(2) used by other threads to wake * up this thread for inter-thread IPC. */ #endif /* HAVE_EVENTFD */ - int eventsFd; /* epoll(7) file descriptor used to wait for fds */ + int eventsFd; /* epoll(7) file descriptor used to wait for + * fds */ struct epoll_event *readyEvents; /* Pointer to at most maxReadyEvents events * returned by epoll_wait(2). */ @@ -113,13 +113,23 @@ typedef struct ThreadSpecificData { } ThreadSpecificData; static Tcl_ThreadDataKey dataKey; - -static void PlatformEventsControl(FileHandler *filePtr, ThreadSpecificData *tsdPtr, int op, int isNew); -static void PlatformEventsFinalize(void); -static void PlatformEventsInit(void); -static int PlatformEventsTranslate(struct epoll_event *event); -static int PlatformEventsWait(struct epoll_event *events, size_t numEvents, struct timeval *timePtr); - + +/* + * Forward declarations. + */ + +static void PlatformEventsControl(FileHandler *filePtr, + ThreadSpecificData *tsdPtr, int op, int isNew); +static void PlatformEventsFinalize(void); +static void PlatformEventsInit(void); +static int PlatformEventsTranslate(struct epoll_event *event); +static int PlatformEventsWait(struct epoll_event *events, + size_t numEvents, struct timeval *timePtr); + +/* + * Incorporate the base notifier API. + */ + #include "tclUnixNotfy.c" /* @@ -190,31 +200,32 @@ Tcl_FinalizeNotifier( * This function registers interest for the file descriptor and the mask * of TCL_* bits associated with filePtr on the epoll file descriptor * associated with tsdPtr. - * Future calls to epoll_wait will return filePtr and tsdPtr alongside with - * the event registered here via the PlatformEventData struct. + * + * Future calls to epoll_wait will return filePtr and tsdPtr alongside + * with the event registered here via the PlatformEventData struct. * * Results: * None. * * Side effects: - * If adding a new file descriptor, a PlatformEventData struct will be - * allocated and associated with filePtr. - * fstat is called on the file descriptor; if it is associated with - * a regular file (S_IFREG,) filePtr is considered to be ready for I/O - * and added to or deleted from the corresponding list in tsdPtr. - * If it is not associated with a regular file, the file descriptor is - * added, modified concerning its mask of events of interest, or deleted - * from the epoll file descriptor of the calling thread. + * - If adding a new file descriptor, a PlatformEventData struct will be + * allocated and associated with filePtr. + * - fstat is called on the file descriptor; if it is associated with a + * regular file (S_IFREG,) filePtr is considered to be ready for I/O + * and added to or deleted from the corresponding list in tsdPtr. + * - If it is not associated with a regular file, the file descriptor is + * added, modified concerning its mask of events of interest, or + * deleted from the epoll file descriptor of the calling thread. * *---------------------------------------------------------------------- */ void PlatformEventsControl( - FileHandler *filePtr, - ThreadSpecificData *tsdPtr, - int op, - int isNew) + FileHandler *filePtr, + ThreadSpecificData *tsdPtr, + int op, + int isNew) { struct epoll_event newEvent; struct PlatformEventData *newPedPtr; @@ -236,10 +247,10 @@ PlatformEventsControl( newEvent.data.ptr = filePtr->pedPtr; /* - * N.B. As discussed in Tcl_WaitForEvent(), epoll(7) does not sup- - * port regular files (S_IFREG.) Therefore, filePtr is in these - * cases simply added or deleted from the list of FileHandlers - * associated with regular files belonging to tsdPtr. + * N.B. As discussed in Tcl_WaitForEvent(), epoll(7) does not support + * regular files (S_IFREG.) Therefore, filePtr is in these cases simply + * added or deleted from the list of FileHandlers associated with regular + * files belonging to tsdPtr. */ if (fstat(filePtr->fd, &fdStat) == -1) { @@ -248,7 +259,8 @@ PlatformEventsControl( switch (op) { case EPOLL_CTL_ADD: if (isNew) { - LIST_INSERT_HEAD(&tsdPtr->firstReadyFileHandlerPtr, filePtr, readyNode); + LIST_INSERT_HEAD(&tsdPtr->firstReadyFileHandlerPtr, filePtr, + readyNode); } break; case EPOLL_CTL_DEL: @@ -267,18 +279,18 @@ PlatformEventsControl( * PlatformEventsFinalize -- * * This function closes the eventfd and the epoll file descriptor and - * frees the epoll_event structs owned by the thread of the caller. - * The above operations are protected by tsdPtr->notifierMutex, which - * is destroyed thereafter. + * frees the epoll_event structs owned by the thread of the caller. The + * above operations are protected by tsdPtr->notifierMutex, which is + * destroyed thereafter. * * Results: * None. * * Side effects: * While tsdPtr->notifierMutex is held: - * The per-thread eventfd(2) is closed, if non-zero, and set to -1. - * The per-thread epoll(7) fd is closed, if non-zero, and set to 0. - * The per-thread epoll_event structs are freed, if any, and set to 0. + * - The per-thread eventfd(2) is closed, if non-zero, and set to -1. + * - The per-thread epoll(7) fd is closed, if non-zero, and set to 0. + * - The per-thread epoll_event structs are freed, if any, and set to 0. * * tsdPtr->notifierMutex is destroyed. * @@ -297,7 +309,7 @@ PlatformEventsFinalize( close(tsdPtr->triggerEventFd); tsdPtr->triggerEventFd = -1; } -#else +#else /* !HAVE_EVENTFD */ if (tsdPtr->triggerPipe[0]) { close(tsdPtr->triggerPipe[0]); tsdPtr->triggerPipe[0] = -1; @@ -337,20 +349,20 @@ PlatformEventsFinalize( * * Side effects: * The following per-thread entities are initialised: - * notifierMutex is initialised. - * The eventfd(2) is created w/ EFD_CLOEXEC and EFD_NONBLOCK. - * The epoll(7) fd is created w/ EPOLL_CLOEXEC. - * A FileHandler struct is allocated and initialised for the event- - * fd(2), registering interest for TCL_READABLE on it via Platform- - * EventsControl(). - * readyEvents and maxReadyEvents are initialised with 512 epoll_events. + * - notifierMutex is initialised. + * - The eventfd(2) is created w/ EFD_CLOEXEC and EFD_NONBLOCK. + * - The epoll(7) fd is created w/ EPOLL_CLOEXEC. + * - A FileHandler struct is allocated and initialised for the + * eventfd(2), registering interest for TCL_READABLE on it via + * PlatformEventsControl(). + * - readyEvents and maxReadyEvents are initialised with 512 + * epoll_events. * *---------------------------------------------------------------------- */ void -PlatformEventsInit( - void) +PlatformEventsInit(void) { ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); FileHandler *filePtr; @@ -361,16 +373,17 @@ PlatformEventsInit( } filePtr = ckalloc(sizeof(*filePtr)); #ifdef HAVE_EVENTFD - if ((tsdPtr->triggerEventFd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK)) <= 0) { + tsdPtr->triggerEventFd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK); + if (tsdPtr->triggerEventFd <= 0) { Tcl_Panic("Tcl_InitNotifier: %s", "could not create trigger eventfd"); } filePtr->fd = tsdPtr->triggerEventFd; -#else +#else /* !HAVE_EVENTFD */ if (pipe2(tsdPtr->triggerPipe, O_CLOEXEC | O_NONBLOCK) != 0) { Tcl_Panic("Tcl_InitNotifier: %s", "could not create trigger pipe"); } filePtr->fd = tsdPtr->triggerPipe[0]; -#endif +#endif /* HAVE_EVENTFD */ tsdPtr->triggerFilePtr = filePtr; if ((tsdPtr->eventsFd = epoll_create1(EPOLL_CLOEXEC)) == -1) { Tcl_Panic("epoll_create1: %s", strerror(errno)); @@ -379,8 +392,8 @@ PlatformEventsInit( PlatformEventsControl(filePtr, tsdPtr, EPOLL_CTL_ADD, 1); if (!tsdPtr->readyEvents) { tsdPtr->maxReadyEvents = 512; - tsdPtr->readyEvents = ckalloc(tsdPtr->maxReadyEvents - * sizeof(tsdPtr->readyEvents[0])); + tsdPtr->readyEvents = ckalloc( + tsdPtr->maxReadyEvents * sizeof(tsdPtr->readyEvents[0])); } LIST_INIT(&tsdPtr->firstReadyFileHandlerPtr); } @@ -390,8 +403,8 @@ PlatformEventsInit( * * PlatformEventsTranslate -- * - * This function translates the platform-specific mask of returned - * events in eventPtr to a mask of TCL_* bits. + * This function translates the platform-specific mask of returned events + * in eventPtr to a mask of TCL_* bits. * * Results: * Returns the translated mask. @@ -404,7 +417,7 @@ PlatformEventsInit( int PlatformEventsTranslate( - struct epoll_event *eventPtr) + struct epoll_event *eventPtr) { int mask; @@ -429,16 +442,16 @@ PlatformEventsTranslate( * This function abstracts waiting for I/O events via epoll_wait. * * Results: - * Returns -1 if epoll_wait failed. Returns 0 if polling and if no - * events became available whilst polling. Returns a pointer to and - * the count of all returned events in all other cases. + * Returns -1 if epoll_wait failed. Returns 0 if polling and if no events + * became available whilst polling. Returns a pointer to and the count of + * all returned events in all other cases. * * Side effects: - * gettimeofday(2), epoll_wait(2), and gettimeofday(2) are called, - * in the specified order. - * If timePtr specifies a positive value, it is updated to reflect - * the amount of time that has passed; if its value would {under, - * over}flow, it is set to zero. + * gettimeofday(2), epoll_wait(2), and gettimeofday(2) are called, in the + * specified order. + * If timePtr specifies a positive value, it is updated to reflect the + * amount of time that has passed; if its value would {under, over}flow, + * it is set to zero. * *---------------------------------------------------------------------- */ @@ -457,8 +470,8 @@ PlatformEventsWait( /* * If timePtr is NULL, epoll_wait(2) will wait indefinitely. If it - * specifies a timeout of {0,0}, epoll_wait(2) will poll. Otherwise, - * the timeout will simply be converted to milliseconds. + * specifies a timeout of {0,0}, epoll_wait(2) will poll. Otherwise, the + * timeout will simply be converted to milliseconds. */ if (!timePtr) { @@ -473,9 +486,9 @@ PlatformEventsWait( } /* - * Call (and possibly block on) epoll_wait(2) and substract the delta - * of gettimeofday(2) before and after the call from timePtr if the - * latter is not NULL. Return the number of events returned by epoll_wait(2). + * Call (and possibly block on) epoll_wait(2) and substract the delta of + * gettimeofday(2) before and after the call from timePtr if the latter is + * not NULL. Return the number of events returned by epoll_wait(2). */ gettimeofday(&tv0, NULL); @@ -484,10 +497,10 @@ PlatformEventsWait( if (timePtr && (timePtr->tv_sec && timePtr->tv_usec)) { timersub(&tv1, &tv0, &tv_delta); if (!timercmp(&tv_delta, timePtr, >)) { - timersub(timePtr, &tv_delta, timePtr); + timersub(timePtr, &tv_delta, timePtr); } else { - timePtr->tv_sec = 0; - timePtr->tv_usec = 0; + timePtr->tv_sec = 0; + timePtr->tv_usec = 0; } } return numFound; @@ -498,8 +511,8 @@ PlatformEventsWait( * * Tcl_CreateFileHandler -- * - * This function registers a file handler with the epoll notifier - * of the thread of the caller. + * This function registers a file handler with the epoll notifier of the + * thread of the caller. * * Results: * None. @@ -551,8 +564,8 @@ Tcl_CreateFileHandler( filePtr->clientData = clientData; filePtr->mask = mask; - PlatformEventsControl(filePtr, tsdPtr, isNew ? - EPOLL_CTL_ADD : EPOLL_CTL_MOD, isNew); + PlatformEventsControl(filePtr, tsdPtr, + isNew ? EPOLL_CTL_ADD : EPOLL_CTL_MOD, isNew); } } @@ -561,8 +574,8 @@ Tcl_CreateFileHandler( * * Tcl_DeleteFileHandler -- * - * Cancel a previously-arranged callback arrangement for a file on - * the epoll file descriptor of the thread of the caller. + * Cancel a previously-arranged callback arrangement for a file on the + * epoll file descriptor of the thread of the caller. * * Results: * None. @@ -632,6 +645,7 @@ Tcl_DeleteFileHandler( * This function is called by Tcl_DoOneEvent to wait for new events on * the message queue. If the block time is 0, then Tcl_WaitForEvent just * polls without blocking. + * * The waiting logic is implemented in PlatformEventsWait. * * Results: @@ -646,7 +660,7 @@ Tcl_DeleteFileHandler( int Tcl_WaitForEvent( - const Tcl_Time *timePtr) /* Maximum block time, or NULL. */ + const Tcl_Time *timePtr) /* Maximum block time, or NULL. */ { if (tclNotifierHooks.waitForEventProc) { return tclNotifierHooks.waitForEventProc(timePtr); @@ -696,10 +710,11 @@ Tcl_WaitForEvent( * Walk the list of FileHandlers associated with regular files * (S_IFREG) belonging to tsdPtr, queue Tcl events for them, and * update their mask of events of interest. + * * As epoll(7) does not support regular files, the behaviour of * {select,poll}(2) is simply simulated here: fds associated with - * regular files are added to this list by PlatformEventsControl() - * and processed here before calling (and possibly blocking) on + * regular files are added to this list by PlatformEventsControl() and + * processed here before calling (and possibly blocking) on * PlatformEventsWait(). */ @@ -720,7 +735,7 @@ Tcl_WaitForEvent( if (filePtr->readyMask == 0) { FileHandlerEvent *fileEvPtr = - ckalloc(sizeof(FileHandlerEvent)); + ckalloc(sizeof(FileHandlerEvent)); fileEvPtr->header.proc = FileHandlerEventProc; fileEvPtr->fd = filePtr->fd; @@ -731,9 +746,9 @@ Tcl_WaitForEvent( } /* - * If any events were queued in the above loop, force PlatformEvents- - * Wait() to poll as there already are events that need to be processed - * at this point. + * If any events were queued in the above loop, force + * PlatformEventsWait() to poll as there already are events that need + * to be processed at this point. */ if (numQueued) { @@ -751,10 +766,12 @@ Tcl_WaitForEvent( * to facilitate inter-thread IPC. If another thread intends to wake * up this thread whilst it's blocking on PlatformEventsWait(), it * write(2)s to the eventfd(2)/trigger pipe (see Tcl_AlertNotifier(),) - * which in turn will cause PlatformEventsWait() to return immediately. + * which in turn will cause PlatformEventsWait() to return + * immediately. */ - numFound = PlatformEventsWait(tsdPtr->readyEvents, tsdPtr->maxReadyEvents, timeoutPtr); + numFound = PlatformEventsWait(tsdPtr->readyEvents, + tsdPtr->maxReadyEvents, timeoutPtr); for (numEvent = 0; numEvent < numFound; numEvent++) { pedPtr = tsdPtr->readyEvents[numEvent].data.ptr; filePtr = pedPtr->filePtr; @@ -762,21 +779,28 @@ Tcl_WaitForEvent( #ifdef HAVE_EVENTFD if (filePtr->fd == tsdPtr->triggerEventFd) { uint64_t eventFdVal; - i = read(tsdPtr->triggerEventFd, &eventFdVal, sizeof(eventFdVal)); + i = read(tsdPtr->triggerEventFd, &eventFdVal, + sizeof(eventFdVal)); if ((i != sizeof(eventFdVal)) && (errno != EAGAIN)) { -#else + Tcl_Panic( + "Tcl_WaitForEvent: read from %p->triggerEventFd: %s", + (void *) tsdPtr, strerror(errno)); + } + continue; + } +#else /* !HAVE_EVENTFD */ if (filePtr->fd == tsdPtr->triggerPipe[0]) { char triggerPipeVal; - i = read(tsdPtr->triggerPipe[0], &triggerPipeVal, sizeof(triggerPipeVal)); + i = read(tsdPtr->triggerPipe[0], &triggerPipeVal, + sizeof(triggerPipeVal)); if ((i != sizeof(triggerPipeVal)) && (errno != EAGAIN)) { -#endif - Tcl_Panic("Tcl_WaitForEvent: " - "read from %p->triggerEventFd: %s", - (void *)tsdPtr, strerror(errno)); - } else { - continue; + Tcl_Panic( + "Tcl_WaitForEvent: read from %p->triggerPipe[0]: %s", + (void *) tsdPtr, strerror(errno)); } + continue; } +#endif /* HAVE_EVENTFD */ if (!mask) { continue; } @@ -800,9 +824,8 @@ Tcl_WaitForEvent( } } +#endif /* NOTIFIER_EPOLL && TCL_THREADS */ #endif /* !HAVE_COREFOUNDATION */ - -#endif /* NOTIFIER_EPOLL */ /* * Local Variables: diff --git a/unix/tclKqueueNotfy.c b/unix/tclKqueueNotfy.c index 6d685ad..99d794e 100644 --- a/unix/tclKqueueNotfy.c +++ b/unix/tclKqueueNotfy.c @@ -14,10 +14,10 @@ */ #include "tclInt.h" -#if defined(NOTIFIER_KQUEUE) && TCL_THREADS - #ifndef HAVE_COREFOUNDATION /* Darwin/Mac OS X CoreFoundation notifier is * in tclMacOSXNotify.c */ +#if defined(NOTIFIER_KQUEUE) && TCL_THREADS + #include #include #include @@ -51,9 +51,9 @@ typedef struct FileHandler { } FileHandler; /* - * The following structure associates a FileHandler and the thread that owns it - * with the file descriptors of interest and their event masks passed to kevent(2) - * and their corresponding event(s) returned by kevent(2). + * The following structure associates a FileHandler and the thread that owns + * it with the file descriptors of interest and their event masks passed to + * kevent(2) and their corresponding event(s) returned by kevent(2). */ struct ThreadSpecificData; @@ -96,20 +96,27 @@ typedef struct ThreadSpecificData { * PlatformEventsFinalize. */ int triggerPipe[2]; /* pipe(2) used by other threads to wake * up this thread for inter-thread IPC. */ - int eventsFd; /* kqueue(2) file descriptor used to wait for fds. */ + int eventsFd; /* kqueue(2) file descriptor used to wait for + * fds. */ struct kevent *readyEvents; /* Pointer to at most maxReadyEvents events * returned by kevent(2). */ size_t maxReadyEvents; /* Count of kevents in readyEvents. */ } ThreadSpecificData; static Tcl_ThreadDataKey dataKey; - -static void PlatformEventsControl(FileHandler *filePtr, ThreadSpecificData *tsdPtr, int op, int isNew); -static void PlatformEventsFinalize(void); -static void PlatformEventsInit(void); -static int PlatformEventsTranslate(struct kevent *eventPtr); -static int PlatformEventsWait(struct kevent *events, size_t numEvents, struct timeval *timePtr); - + +/* + * Forward declarations of internal functions. + */ + +static void PlatformEventsControl(FileHandler *filePtr, + ThreadSpecificData *tsdPtr, int op, int isNew); +static void PlatformEventsFinalize(void); +static void PlatformEventsInit(void); +static int PlatformEventsTranslate(struct kevent *eventPtr); +static int PlatformEventsWait(struct kevent *events, + size_t numEvents, struct timeval *timePtr); + #include "tclUnixNotfy.c" /* @@ -180,6 +187,7 @@ Tcl_FinalizeNotifier( * This function registers interest for the file descriptor and the mask * of TCL_* bits associated with filePtr on the kqueue file descriptor * associated with tsdPtr. + * * Future calls to kevent will return filePtr and tsdPtr alongside with * the event registered here via the PlatformEventData struct. * @@ -187,26 +195,26 @@ Tcl_FinalizeNotifier( * None. * * Side effects: - * If adding a new file descriptor, a PlatformEventData struct will be - * allocated and associated with filePtr. - * fstat is called on the file descriptor; if it is associated with - * a regular file (S_IFREG,) filePtr is considered to be ready for I/O - * and added to or deleted from the corresponding list in tsdPtr. - * If it is not associated with a regular file, the file descriptor is - * added, modified concerning its mask of events of interest, or deleted - * from the epoll file descriptor of the calling thread. - * If deleting a file descriptor, kevent(2) is called twice specifying - * EVFILT_READ first and then EVFILT_WRITE (see note below.) + * - If adding a new file descriptor, a PlatformEventData struct will be + * allocated and associated with filePtr. + * - fstat is called on the file descriptor; if it is associated with + * a regular file (S_IFREG,) filePtr is considered to be ready for I/O + * and added to or deleted from the corresponding list in tsdPtr. + * - If it is not associated with a regular file, the file descriptor is + * added, modified concerning its mask of events of interest, or + * deleted from the epoll file descriptor of the calling thread. + * - If deleting a file descriptor, kevent(2) is called twice specifying + * EVFILT_READ first and then EVFILT_WRITE (see note below.) * *---------------------------------------------------------------------- */ void PlatformEventsControl( - FileHandler *filePtr, - ThreadSpecificData *tsdPtr, - int op, - int isNew) + FileHandler *filePtr, + ThreadSpecificData *tsdPtr, + int op, + int isNew) { int numChanges; struct kevent changeList[2]; @@ -221,11 +229,11 @@ PlatformEventsControl( } /* - * N.B. As discussed in Tcl_WaitForEvent(), kqueue(2) does not repro- - * duce the `always ready' {select,poll}(2) behaviour for regular - * files (S_IFREG) prior to FreeBSD 11.0-RELEASE. Therefore, file- - * Ptr is in these cases simply added or deleted from the list of - * FileHandlers associated with regular files belonging to tsdPtr. + * N.B. As discussed in Tcl_WaitForEvent(), kqueue(2) does not reproduce + * the `always ready' {select,poll}(2) behaviour for regular files + * (S_IFREG) prior to FreeBSD 11.0-RELEASE. Therefore, filePtr is in these + * cases simply added or deleted from the list of FileHandlers associated + * with regular files belonging to tsdPtr. */ if (fstat(filePtr->fd, &fdStat) == -1) { @@ -234,7 +242,8 @@ PlatformEventsControl( switch (op) { case EV_ADD: if (isNew) { - LIST_INSERT_HEAD(&tsdPtr->firstReadyFileHandlerPtr, filePtr, readyNode); + LIST_INSERT_HEAD(&tsdPtr->firstReadyFileHandlerPtr, filePtr, + readyNode); } break; case EV_DELETE: @@ -248,38 +257,41 @@ PlatformEventsControl( switch (op) { case EV_ADD: if (filePtr->mask & (TCL_READABLE | TCL_EXCEPTION)) { - EV_SET(&changeList[numChanges], (uintptr_t)filePtr->fd, EVFILT_READ, - op, 0, 0, filePtr->pedPtr); + EV_SET(&changeList[numChanges], (uintptr_t)filePtr->fd, + EVFILT_READ, op, 0, 0, filePtr->pedPtr); numChanges++; } if (filePtr->mask & TCL_WRITABLE) { - EV_SET(&changeList[numChanges], (uintptr_t)filePtr->fd, EVFILT_WRITE, - op, 0, 0, filePtr->pedPtr); + EV_SET(&changeList[numChanges], (uintptr_t)filePtr->fd, + EVFILT_WRITE, op, 0, 0, filePtr->pedPtr); numChanges++; } if (numChanges) { - if (kevent(tsdPtr->eventsFd, changeList, numChanges, NULL, 0, NULL) == -1) { + if (kevent(tsdPtr->eventsFd, changeList, numChanges, NULL, 0, + NULL) == -1) { Tcl_Panic("kevent: %s", strerror(errno)); } } break; case EV_DELETE: /* - * N.B. kqueue(2) has separate filters for readability and writabi- - * lity fd events. We therefore need to ensure that fds are - * ompletely removed from the kqueue(2) fd when deleting. - * This is exacerbated by changes to filePtr->mask w/o calls - * to PlatforEventsControl() after e.g. an exec(3) in a child - * process. - * As one of these calls can fail, two separate kevent(2) calls - * are made for EVFILT_{READ,WRITE}. + * N.B. kqueue(2) has separate filters for readability and writability + * fd events. We therefore need to ensure that fds are ompletely + * removed from the kqueue(2) fd when deleting. This is exacerbated + * by changes to filePtr->mask w/o calls to PlatforEventsControl() + * after e.g. an exec(3) in a child process. + * + * As one of these calls can fail, two separate kevent(2) calls are + * made for EVFILT_{READ,WRITE}. */ - EV_SET(&changeList[0], (uintptr_t)filePtr->fd, EVFILT_READ, op, 0, 0, NULL); + EV_SET(&changeList[0], (uintptr_t)filePtr->fd, EVFILT_READ, op, 0, 0, + NULL); if ((kevent(tsdPtr->eventsFd, changeList, 1, NULL, 0, NULL) == -1) && (errno != ENOENT)) { Tcl_Panic("kevent: %s", strerror(errno)); } - EV_SET(&changeList[0], (uintptr_t)filePtr->fd, EVFILT_WRITE, op, 0, 0, NULL); + EV_SET(&changeList[0], (uintptr_t)filePtr->fd, EVFILT_WRITE, op, 0, 0, + NULL); if ((kevent(tsdPtr->eventsFd, changeList, 1, NULL, 0, NULL) == -1) && (errno != ENOENT)) { Tcl_Panic("kevent: %s", strerror(errno)); @@ -293,10 +305,10 @@ PlatformEventsControl( * * PlatformEventsFinalize -- * - * This function closes the pipe and the kqueue file descriptors - * and frees the kevent structs owned by the thread of the caller. - * The above operations are protected by tsdPtr->notifierMutex, which - * is destroyed thereafter. + * This function closes the pipe and the kqueue file descriptors and + * frees the kevent structs owned by the thread of the caller. The above + * operations are protected by tsdPtr->notifierMutex, which is destroyed + * thereafter. * * Results: * None. @@ -314,7 +326,7 @@ PlatformEventsControl( void PlatformEventsFinalize( - void) + void) { ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); @@ -346,31 +358,30 @@ PlatformEventsFinalize( * * PlatformEventsInit -- * - * This function abstracts creating a kqueue fd via the kqueue - * system call and allocating memory for the kevents structs in - * tsdPtr for the thread of the caller. + * This function abstracts creating a kqueue fd via the kqueue system + * call and allocating memory for the kevents structs in tsdPtr for the + * thread of the caller. * * Results: * None. * * Side effects: * The following per-thread entities are initialised: - * notifierMutex is initialised. - * The pipe(2) is created; fcntl(2) is called on both fds to set - * FD_CLOEXEC and O_NONBLOCK. - * The kqueue(2) fd is created; fcntl(2) is called on it to set - * FD_CLOEXEC. - * A FileHandler struct is allocated and initialised for the event- - * fd(2), registering interest for TCL_READABLE on it via Platform- - * EventsControl(). - * readyEvents and maxReadyEvents are initialised with 512 kevents. - + * - notifierMutex is initialised. + * - The pipe(2) is created; fcntl(2) is called on both fds to set + * FD_CLOEXEC and O_NONBLOCK. + * - The kqueue(2) fd is created; fcntl(2) is called on it to set + * FD_CLOEXEC. + * - A FileHandler struct is allocated and initialised for the event- + * fd(2), registering interest for TCL_READABLE on it via Platform- + * EventsControl(). + * - readyEvents and maxReadyEvents are initialised with 512 kevents. + * *---------------------------------------------------------------------- */ void -PlatformEventsInit( - void) +PlatformEventsInit(void) { ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); int i, fdFl; @@ -404,8 +415,8 @@ PlatformEventsInit( PlatformEventsControl(filePtr, tsdPtr, EV_ADD, 1); if (!tsdPtr->readyEvents) { tsdPtr->maxReadyEvents = 512; - tsdPtr->readyEvents = ckalloc(tsdPtr->maxReadyEvents - * sizeof(tsdPtr->readyEvents[0])); + tsdPtr->readyEvents = ckalloc( + tsdPtr->maxReadyEvents * sizeof(tsdPtr->readyEvents[0])); } LIST_INIT(&tsdPtr->firstReadyFileHandlerPtr); } @@ -429,7 +440,7 @@ PlatformEventsInit( int PlatformEventsTranslate( - struct kevent *eventPtr) + struct kevent *eventPtr) { int mask; @@ -454,20 +465,20 @@ PlatformEventsTranslate( * * PlatformEventsWait -- * - * This function abstracts waiting for I/O events via the kevent - * system call. + * This function abstracts waiting for I/O events via the kevent system + * call. * * Results: * Returns -1 if kevent failed. Returns 0 if polling and if no events - * became available whilst polling. Returns a pointer to and the count - * of all returned events in all other cases. + * became available whilst polling. Returns a pointer to and the count of + * all returned events in all other cases. * * Side effects: - * gettimeofday(2), kevent(2), and gettimeofday(2) are called, - * in the specified order. - * If timePtr specifies a positive value, it is updated to reflect - * the amount of time that has passed; if its value would {under, - * over}flow, it is set to zero. + * gettimeofday(2), kevent(2), and gettimeofday(2) are called, in the + * specified order. + * If timePtr specifies a positive value, it is updated to reflect the + * amount of time that has passed; if its value would {under, over}flow, + * it is set to zero. * *---------------------------------------------------------------------- */ @@ -485,9 +496,9 @@ PlatformEventsWait( ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); /* - * If timePtr is NULL, kevent(2) will wait indefinitely. If it speci- - * fies a timeout of {0,0}, kevent(2) will poll. Otherwise, the time- - * out will simply be converted to a timespec. + * If timePtr is NULL, kevent(2) will wait indefinitely. If it specifies a + * timeout of {0,0}, kevent(2) will poll. Otherwise, the timeout will + * simply be converted to a timespec. */ if (!timePtr) { @@ -504,20 +515,21 @@ PlatformEventsWait( /* * Call (and possibly block on) kevent(2) and substract the delta of - * gettimeofday(2) before and after the call from timePtr if the latter - * is not NULL. Return the number of events returned by kevent(2). + * gettimeofday(2) before and after the call from timePtr if the latter is + * not NULL. Return the number of events returned by kevent(2). */ gettimeofday(&tv0, NULL); - numFound = kevent(tsdPtr->eventsFd, NULL, 0, events, (int)numEvents, timeoutPtr); + numFound = kevent(tsdPtr->eventsFd, NULL, 0, events, (int) numEvents, + timeoutPtr); gettimeofday(&tv1, NULL); if (timePtr && (timePtr->tv_sec && timePtr->tv_usec)) { timersub(&tv1, &tv0, &tv_delta); if (!timercmp(&tv_delta, timePtr, >)) { - timersub(timePtr, &tv_delta, timePtr); + timersub(timePtr, &tv_delta, timePtr); } else { - timePtr->tv_sec = 0; - timePtr->tv_usec = 0; + timePtr->tv_sec = 0; + timePtr->tv_usec = 0; } } return numFound; @@ -590,8 +602,8 @@ Tcl_CreateFileHandler( * * Tcl_DeleteFileHandler -- * - * Cancel a previously-arranged callback arrangement for a file on - * the kqueue of the thread of the caller. + * Cancel a previously-arranged callback arrangement for a file on the + * kqueue of the thread of the caller. * * Results: * None. @@ -661,6 +673,7 @@ Tcl_DeleteFileHandler( * This function is called by Tcl_DoOneEvent to wait for new events on * the message queue. If the block time is 0, then Tcl_WaitForEvent just * polls without blocking. + * * The waiting logic is implemented in PlatformEventsWait. * * Results: @@ -726,11 +739,13 @@ Tcl_WaitForEvent( * Walk the list of FileHandlers associated with regular files * (S_IFREG) belonging to tsdPtr, queue Tcl events for them, and * update their mask of events of interest. + * * kqueue(2), unlike epoll(7), does support regular files, but - * EVFILT_READ only `[r]eturns when the file pointer is not at - * the end of file' as opposed to unconditionally. While FreeBSD - * 11.0-RELEASE adds support for this mode (NOTE_FILE_POLL,) this - * is not used for reasons of compatibility. + * EVFILT_READ only `[r]eturns when the file pointer is not at the end + * of file' as opposed to unconditionally. While FreeBSD 11.0-RELEASE + * adds support for this mode (NOTE_FILE_POLL,) this is not used for + * reasons of compatibility. + * * Therefore, the behaviour of {select,poll}(2) is simply simulated * here: fds associated with regular files are added to this list by * PlatformEventsControl() and processed here before calling (and @@ -754,7 +769,7 @@ Tcl_WaitForEvent( if (filePtr->readyMask == 0) { FileHandlerEvent *fileEvPtr = - ckalloc(sizeof(FileHandlerEvent)); + ckalloc(sizeof(FileHandlerEvent)); fileEvPtr->header.proc = FileHandlerEventProc; fileEvPtr->fd = filePtr->fd; @@ -788,22 +803,19 @@ Tcl_WaitForEvent( * cause PlatformEventsWait() to return immediately. */ - numFound = PlatformEventsWait(tsdPtr->readyEvents, tsdPtr->maxReadyEvents, timeoutPtr); + numFound = PlatformEventsWait(tsdPtr->readyEvents, + tsdPtr->maxReadyEvents, timeoutPtr); for (numEvent = 0; numEvent < numFound; numEvent++) { - pedPtr = (struct PlatformEventData *)tsdPtr->readyEvents[numEvent].udata; + pedPtr = (struct PlatformEventData *) + tsdPtr->readyEvents[numEvent].udata; filePtr = pedPtr->filePtr; mask = PlatformEventsTranslate(&tsdPtr->readyEvents[numEvent]); if (filePtr->fd == tsdPtr->triggerPipe[0]) { - do { - i = read(tsdPtr->triggerPipe[0], buf, 1); - if ((i == -1) && (errno != EAGAIN)) { - Tcl_Panic("Tcl_WaitForEvent: " - "read from %p->triggerPipe: %s", - (void *)tsdPtr, strerror(errno)); - } else { - break; - } - } while (1); + i = read(tsdPtr->triggerPipe[0], buf, 1); + if ((i == -1) && (errno != EAGAIN)) { + Tcl_Panic("Tcl_WaitForEvent: read from %p->triggerPipe: %s", + (void *) tsdPtr, strerror(errno)); + } continue; } if (!mask) { @@ -829,9 +841,8 @@ Tcl_WaitForEvent( } } +#endif /* NOTIFIER_KQUEUE && TCL_THREADS */ #endif /* !HAVE_COREFOUNDATION */ - -#endif /* NOTIFIER_KQUEUE */ /* * Local Variables: diff --git a/unix/tclSelectNotfy.c b/unix/tclSelectNotfy.c index 811b49a..a0dea57 100644 --- a/unix/tclSelectNotfy.c +++ b/unix/tclSelectNotfy.c @@ -1,9 +1,9 @@ /* * tclSelectNotfy.c -- * - * This file contains the implementation of the select()-based - * generic Unix notifier, which is the lowest-level part of the - * Tcl event loop. This file works together with generic/tclNotify.c. + * This file contains the implementation of the select()-based generic + * Unix notifier, which is the lowest-level part of the Tcl event loop. + * This file works together with generic/tclNotify.c. * * Copyright (c) 1995-1997 Sun Microsystems, Inc. * @@ -12,10 +12,10 @@ */ #include "tclInt.h" -#if (!defined(NOTIFIER_EPOLL) && !defined(NOTIFIER_KQUEUE)) || !TCL_THREADS - #ifndef HAVE_COREFOUNDATION /* Darwin/Mac OS X CoreFoundation notifier is * in tclMacOSXNotify.c */ +#if (!defined(NOTIFIER_EPOLL) && !defined(NOTIFIER_KQUEUE)) || !TCL_THREADS + #include /* @@ -94,16 +94,17 @@ typedef struct ThreadSpecificData { * notifierMutex lock before accessing these * fields. */ #ifdef __CYGWIN__ - void *event; /* Any other thread alerts a notifier - * that an event is ready to be processed - * by sending this event. */ + void *event; /* Any other thread alerts a notifier that an + * event is ready to be processed by sending + * this event. */ void *hwnd; /* Messaging window. */ #else /* !__CYGWIN__ */ pthread_cond_t waitCV; /* Any other thread alerts a notifier that an * event is ready to be processed by signaling * this condition variable. */ #endif /* __CYGWIN__ */ - int waitCVinitialized; /* Variable to flag initialization of the structure */ + int waitCVinitialized; /* Variable to flag initialization of the + * structure. */ int eventReady; /* True if an event is ready to be processed. * Used as condition flag together with waitCV * above. */ @@ -171,12 +172,14 @@ static int notifierThreadRunning = 0; static pthread_cond_t notifierCV = PTHREAD_COND_INITIALIZER; /* - * The pollState bits - * POLL_WANT is set by each thread before it waits on its condition - * variable. It is checked by the notifier before it does select. - * POLL_DONE is set by the notifier if it goes into select after seeing - * POLL_WANT. The idea is to ensure it tries a select with the - * same bits the initial thread had set. + * The pollState bits: + * + * POLL_WANT is set by each thread before it waits on its condition variable. + * It is checked by the notifier before it does select. + * + * POLL_DONE is set by the notifier if it goes into select after seeing + * POLL_WANT. The idea is to ensure it tries a select with the same bits + * the initial thread had set. */ #define POLL_WANT 0x1 @@ -196,24 +199,24 @@ static Tcl_ThreadId notifierThread; #if TCL_THREADS static TCL_NORETURN void NotifierThreadProc(ClientData clientData); #if defined(HAVE_PTHREAD_ATFORK) -static int atForkInit = 0; -static void AtForkChild(void); +static int atForkInit = 0; +static void AtForkChild(void); #endif /* HAVE_PTHREAD_ATFORK */ #endif /* TCL_THREADS */ -static int FileHandlerEventProc(Tcl_Event *evPtr, int flags); +static int FileHandlerEventProc(Tcl_Event *evPtr, int flags); /* - * Import of Windows API when building threaded with Cygwin. + * Import of critical bits of Windows API when building threaded with Cygwin. */ #if defined(__CYGWIN__) typedef struct { - void *hwnd; - unsigned int *message; - int wParam; - int lParam; - int time; - int x; + void *hwnd; /* Messaging window. */ + unsigned int *message; /* Message payload. */ + int wParam; /* Event-specific "word" parameter. */ + int lParam; /* Event-specific "long" parameter. */ + int time; /* Event timestamp. */ + int x; /* Event location (where meaningful). */ int y; } MSG; @@ -233,8 +236,9 @@ typedef struct { extern void __stdcall CloseHandle(void *); extern void *__stdcall CreateEventW(void *, unsigned char, unsigned char, void *); -extern void * __stdcall CreateWindowExW(void *, const void *, const void *, - DWORD, int, int, int, int, void *, void *, void *, void *); +extern void *__stdcall CreateWindowExW(void *, const void *, const void *, + DWORD, int, int, int, int, void *, void *, void *, + void *); extern DWORD __stdcall DefWindowProcW(void *, int, void *, void *); extern unsigned char __stdcall DestroyWindow(void *); extern int __stdcall DispatchMessageW(const MSG *); @@ -336,7 +340,6 @@ Tcl_InitNotifier(void) #endif /* HAVE_PTHREAD_ATFORK */ notifierCount++; - pthread_mutex_unlock(¬ifierInitMutex); #endif /* TCL_THREADS */ @@ -381,28 +384,25 @@ Tcl_FinalizeNotifier( * pipe and wait for the background thread to terminate. */ - if (notifierCount == 0) { + if (notifierCount == 0 && triggerPipe != -1) { + if (write(triggerPipe, "q", 1) != 1) { + Tcl_Panic("Tcl_FinalizeNotifier: %s", + "unable to write 'q' to triggerPipe"); + } + close(triggerPipe); + pthread_mutex_lock(¬ifierMutex); + while(triggerPipe != -1) { + pthread_cond_wait(¬ifierCV, ¬ifierMutex); + } + pthread_mutex_unlock(¬ifierMutex); + if (notifierThreadRunning) { + int result = pthread_join((pthread_t) notifierThread, NULL); - if (triggerPipe != -1) { - if (write(triggerPipe, "q", 1) != 1) { + if (result) { Tcl_Panic("Tcl_FinalizeNotifier: %s", - "unable to write q to triggerPipe"); - } - close(triggerPipe); - pthread_mutex_lock(¬ifierMutex); - while(triggerPipe != -1) { - pthread_cond_wait(¬ifierCV, ¬ifierMutex); - } - pthread_mutex_unlock(¬ifierMutex); - if (notifierThreadRunning) { - int result = pthread_join((pthread_t) notifierThread, NULL); - - if (result) { - Tcl_Panic("Tcl_FinalizeNotifier: unable to join notifier " - "thread"); - } - notifierThreadRunning = 0; + "unable to join notifier thread"); } + notifierThreadRunning = 0; } } @@ -645,7 +645,7 @@ Tcl_WaitForEvent( # ifdef __CYGWIN__ MSG msg; # endif /* __CYGWIN__ */ -#else +#else /* !TCL_THREADS */ /* * Impl. notes: timeout & timeoutPtr are used if, and only if threads * are not enabled. They are the arguments for the regular select() @@ -771,18 +771,19 @@ Tcl_WaitForEvent( MsgWaitForMultipleObjects(1, &tsdPtr->event, 0, timeout, 1279); pthread_mutex_lock(¬ifierMutex); } -#else +#else /* !__CYGWIN__ */ if (timePtr != NULL) { - Tcl_Time now; - struct timespec ptime; + Tcl_Time now; + struct timespec ptime; - Tcl_GetTime(&now); - ptime.tv_sec = timePtr->sec + now.sec + (timePtr->usec + now.usec) / 1000000; - ptime.tv_nsec = 1000 * ((timePtr->usec + now.usec) % 1000000); + Tcl_GetTime(&now); + ptime.tv_sec = timePtr->sec + now.sec + + (timePtr->usec + now.usec) / 1000000; + ptime.tv_nsec = 1000 * ((timePtr->usec + now.usec) % 1000000); - pthread_cond_timedwait(&tsdPtr->waitCV, ¬ifierMutex, &ptime); + pthread_cond_timedwait(&tsdPtr->waitCV, ¬ifierMutex, &ptime); } else { - pthread_cond_wait(&tsdPtr->waitCV, ¬ifierMutex); + pthread_cond_wait(&tsdPtr->waitCV, ¬ifierMutex); } #endif /* __CYGWIN__ */ } @@ -830,8 +831,7 @@ Tcl_WaitForEvent( "unable to write to triggerPipe"); } } - -#else +#else /* !TCL_THREADS */ tsdPtr->readyMasks = tsdPtr->checkMasks; numFound = select(tsdPtr->numFdBits, &tsdPtr->readyMasks.readable, &tsdPtr->readyMasks.writable, &tsdPtr->readyMasks.exception, @@ -892,8 +892,6 @@ Tcl_WaitForEvent( } } -#if TCL_THREADS - /* *---------------------------------------------------------------------- * @@ -918,6 +916,7 @@ Tcl_WaitForEvent( *---------------------------------------------------------------------- */ +#if TCL_THREADS static TCL_NORETURN void NotifierThreadProc( ClientData clientData) /* Not used. */ @@ -1101,12 +1100,10 @@ NotifierThreadProc( TclpThreadExit(0); } - #endif /* TCL_THREADS */ - + +#endif /* (!NOTIFIER_EPOLL && !NOTIFIER_KQUEUE) || !TCL_THREADS */ #endif /* !HAVE_COREFOUNDATION */ - -#endif /* !NOTIFIER_EPOLL && !NOTIFIER_KQUEUE */ /* * Local Variables: diff --git a/unix/tclUnixNotfy.c b/unix/tclUnixNotfy.c index fb7e569..3817071 100644 --- a/unix/tclUnixNotfy.c +++ b/unix/tclUnixNotfy.c @@ -18,7 +18,7 @@ * Static routines defined in this file. */ -static int FileHandlerEventProc(Tcl_Event *evPtr, int flags); +static int FileHandlerEventProc(Tcl_Event *evPtr, int flags); #if !TCL_THREADS # undef NOTIFIER_EPOLL # undef NOTIFIER_KQUEUE @@ -27,7 +27,7 @@ static int FileHandlerEventProc(Tcl_Event *evPtr, int flags); # define NOTIFIER_SELECT static TCL_NORETURN void NotifierThreadProc(ClientData clientData); # if defined(HAVE_PTHREAD_ATFORK) -static void AtForkChild(void); +static void AtForkChild(void); # endif /* HAVE_PTHREAD_ATFORK */ /* @@ -120,7 +120,7 @@ Tcl_AlertNotifier( # endif /* __CYGWIN__ */ pthread_mutex_unlock(¬ifierMutex); #endif /* TCL_THREADS */ -#else +#else /* !NOTIFIER_SELECT */ ThreadSpecificData *tsdPtr = clientData; #if defined(NOTIFIER_EPOLL) && defined(HAVE_EVENTFD) uint64_t eventFdVal = 1; @@ -128,12 +128,13 @@ Tcl_AlertNotifier( sizeof(eventFdVal)) != sizeof(eventFdVal)) { Tcl_Panic("Tcl_AlertNotifier: unable to write to %p->triggerEventFd", (void *)tsdPtr); + } #else if (write(tsdPtr->triggerPipe[1], "", 1) != 1) { Tcl_Panic("Tcl_AlertNotifier: unable to write to %p->triggerPipe", (void *)tsdPtr); -#endif /* NOTIFIER_EPOLL && HAVE_EVENTFD */ } +#endif /* NOTIFIER_EPOLL && HAVE_EVENTFD */ #endif /* NOTIFIER_SELECT */ } } @@ -301,15 +302,15 @@ FileHandlerEventProc( static void AlertSingleThread( - ThreadSpecificData *tsdPtr) + ThreadSpecificData *tsdPtr) { tsdPtr->eventReady = 1; if (tsdPtr->onList) { /* - * Remove the ThreadSpecificData structure of this thread - * from the waiting list. This prevents us from - * continuously spinning on epoll_wait until the other - * threads runs and services the file event. + * Remove the ThreadSpecificData structure of this thread from the + * waiting list. This prevents us from continuously spinning on + * epoll_wait until the other threads runs and services the file + * event. */ if (tsdPtr->prevPtr) { @@ -326,7 +327,7 @@ AlertSingleThread( } #ifdef __CYGWIN__ PostMessageW(tsdPtr->hwnd, 1024, 0, 0); -#else /* __CYGWIN__ */ +#else /* !__CYGWIN__ */ pthread_cond_broadcast(&tsdPtr->waitCV); #endif /* __CYGWIN__ */ } @@ -359,9 +360,10 @@ AtForkChild(void) pthread_cond_init(¬ifierCV, NULL); /* - * notifierThreadRunning == 1: thread is running, (there might be data in notifier lists) + * notifierThreadRunning == 1: thread is running, (there might be data in + * notifier lists) * atForkInit == 0: InitNotifier was never called - * notifierCount != 0: unbalanced InitNotifier() / FinalizeNotifier calls + * notifierCount != 0: unbalanced InitNotifier() / FinalizeNotifier calls * waitingListPtr != 0: there are threads currently waiting for events. */ @@ -382,8 +384,8 @@ AtForkChild(void) waitingListPtr = NULL; /* - * The tsdPtr from before the fork is copied as well. But since - * we are paranoic, we don't trust its condvar and reset it. + * The tsdPtr from before the fork is copied as well. But since we + * are paranoic, we don't trust its condvar and reset it. */ #ifdef __CYGWIN__ DestroyWindow(tsdPtr->hwnd); @@ -391,10 +393,10 @@ AtForkChild(void) className, 0, 0, 0, 0, 0, NULL, NULL, TclWinGetTclInstance(), NULL); ResetEvent(tsdPtr->event); -#else +#else /* !__CYGWIN__ */ pthread_cond_destroy(&tsdPtr->waitCV); pthread_cond_init(&tsdPtr->waitCV, NULL); -#endif +#endif /* __CYGWIN__ */ /* * In case, we had multiple threads running before the fork, @@ -465,8 +467,8 @@ TclUnixWaitForFile( if (timeout > 0) { Tcl_GetTime(&now); - abortTime.sec = now.sec + timeout/1000; - abortTime.usec = now.usec + (timeout%1000)*1000; + abortTime.sec = now.sec + timeout / 1000; + abortTime.usec = now.usec + (timeout % 1000) * 1000; if (abortTime.usec >= 1000000) { abortTime.usec -= 1000000; abortTime.sec += 1; @@ -501,7 +503,7 @@ TclUnixWaitForFile( * become ready or a timeout to occur. */ - while (1) { + do { if (timeout > 0) { blockTime.tv_sec = abortTime.sec - now.sec; blockTime.tv_usec = abortTime.usec - now.usec; @@ -524,9 +526,9 @@ TclUnixWaitForFile( } else if (!timeoutPtr->tv_sec && !timeoutPtr->tv_usec) { pollTimeout = 0; } else { - pollTimeout = (int)timeoutPtr->tv_sec * 1000; + pollTimeout = (int) timeoutPtr->tv_sec * 1000; if (timeoutPtr->tv_usec) { - pollTimeout += ((int)timeoutPtr->tv_usec / 1000); + pollTimeout += (int) timeoutPtr->tv_usec / 1000; } } numFound = poll(pollFds, 1, pollTimeout); @@ -557,13 +559,11 @@ TclUnixWaitForFile( */ Tcl_GetTime(&now); - if ((abortTime.sec < now.sec) - || (abortTime.sec==now.sec && abortTime.usec<=now.usec)) { - break; - } - } + } while ((abortTime.sec > now.sec) + || (abortTime.sec == now.sec && abortTime.usec > now.usec)); return result; } + #endif /* !HAVE_COREFOUNDATION */ /* -- cgit v0.12 From 49cd80a29d7bb4252a2ad031783314b98821a6ce Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Mon, 22 Oct 2018 17:48:40 +0000 Subject: Fix "registry" test-cases. Thanks to Harald Oehlmann for spotting this! --- tests/registry.test | 4 ++-- win/Makefile.in | 4 ++-- win/makefile.vc | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/registry.test b/tests/registry.test index 2072559..b6be074 100644 --- a/tests/registry.test +++ b/tests/registry.test @@ -19,7 +19,7 @@ testConstraint reg 0 if {[testConstraint win]} { if {![catch { ::tcltest::loadTestedCommands - set ::regver [package require registry 1.3.2] + set ::regver [package require registry 1.3.3] }]} { testConstraint reg 1 } @@ -33,7 +33,7 @@ testConstraint english [expr { test registry-1.0 {check if we are testing the right dll} {win reg} { set ::regver -} {1.3.2} +} {1.3.3} test registry-1.1 {argument parsing for registry command} {win reg} { list [catch {registry} msg] $msg } {1 {wrong # args: should be "registry ?-32bit|-64bit? option ?arg ...?"}} diff --git a/win/Makefile.in b/win/Makefile.in index eee688b..a8d487b 100644 --- a/win/Makefile.in +++ b/win/Makefile.in @@ -713,14 +713,14 @@ test-tcl: binaries $(TCLSH) $(CAT32) $(TEST_DLL_FILE) ./$(TCLSH) "$(ROOT_DIR_NATIVE)/tests/all.tcl" $(TESTFLAGS) \ -load "package ifneeded Tcltest ${VERSION}@TCL_PATCH_LEVEL@ [list load [file normalize ${TEST_DLL_FILE}] Tcltest]; \ package ifneeded dde 1.4.0 [list load [file normalize ${DDE_DLL_FILE}] dde]; \ - package ifneeded registry 1.3.2 [list load [file normalize ${REG_DLL_FILE}] registry]" | ./$(CAT32) + package ifneeded registry 1.3.3 [list load [file normalize ${REG_DLL_FILE}] registry]" | ./$(CAT32) # Useful target to launch a built tclsh with the proper path,... runtest: binaries $(TCLSH) $(TEST_DLL_FILE) @TCL_LIBRARY="$(LIBRARY_DIR)"; export TCL_LIBRARY; \ ./$(TCLSH) $(TESTFLAGS) -load "package ifneeded Tcltest ${VERSION}@TCL_PATCH_LEVEL@ [list load [file normalize ${TEST_DLL_FILE}] Tcltest]; \ package ifneeded dde 1.4.0 [list load [file normalize ${DDE_DLL_FILE}] dde]; \ - package ifneeded registry 1.3.2 [list load [file normalize ${REG_DLL_FILE}] registry]" $(SCRIPT) + package ifneeded registry 1.3.3 [list load [file normalize ${REG_DLL_FILE}] registry]" $(SCRIPT) # This target can be used to run tclsh from the build directory via # `make shell SCRIPT=foo.tcl` diff --git a/win/makefile.vc b/win/makefile.vc index ff31e96..337a894 100644 --- a/win/makefile.vc +++ b/win/makefile.vc @@ -385,7 +385,7 @@ test-core: setup $(TCLTEST) dlls $(CAT32) set TCL_LIBRARY=$(ROOT:\=/)/library $(DEBUGGER) $(TCLTEST) "$(ROOT:\=/)/tests/all.tcl" $(TESTFLAGS) -loadfile << package ifneeded dde 1.4.0 [list load "$(TCLDDELIB:\=/)" dde] - package ifneeded registry 1.3.2 [list load "$(TCLREGLIB:\=/)" registry] + package ifneeded registry 1.3.3 [list load "$(TCLREGLIB:\=/)" registry] << runtest: setup $(TCLTEST) dlls $(CAT32) -- cgit v0.12 From cee756478e65a985a7c60c9b457748de69693007 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Mon, 22 Oct 2018 18:21:23 +0000 Subject: Fix error-message on MacOS: the __LINKEDIT segment does not cover the end of the file. Reason: We appended a zip-file to the end of the library, so during install "strip" doesn't work any more --- unix/Makefile.in | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/unix/Makefile.in b/unix/Makefile.in index 487ae61..b2ea458 100644 --- a/unix/Makefile.in +++ b/unix/Makefile.in @@ -858,8 +858,7 @@ install: $(INSTALL_TARGETS) install-strip: $(MAKE) $(INSTALL_TARGETS) \ - INSTALL_PROGRAM="$(INSTALL_PROGRAM) ${INSTALL_STRIP_PROGRAM}" \ - INSTALL_LIBRARY="$(INSTALL_LIBRARY) ${INSTALL_STRIP_LIBRARY}" + INSTALL_PROGRAM="$(INSTALL_PROGRAM) ${INSTALL_STRIP_PROGRAM}" install-binaries: binaries @for i in "$(LIB_INSTALL_DIR)" "$(BIN_INSTALL_DIR)" \ -- cgit v0.12 From 86013715f6a114cd89394f52ed82e18d58813c77 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Mon, 22 Oct 2018 18:36:42 +0000 Subject: Missing ',' in documentation (discovered by MacOSX help processing). Some whitespacing --- doc/CrtObjCmd.3 | 2 +- generic/tclOO.c | 2 +- generic/tclUtil.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/CrtObjCmd.3 b/doc/CrtObjCmd.3 index 87ce07e..2cd9222 100644 --- a/doc/CrtObjCmd.3 +++ b/doc/CrtObjCmd.3 @@ -8,7 +8,7 @@ .so man.macros .BS .SH NAME -Tcl_CreateObjCommand, Tcl_DeleteCommand, Tcl_DeleteCommandFromToken, Tcl_GetCommandInfo, Tcl_GetCommandInfoFromToken, Tcl_SetCommandInfo, Tcl_SetCommandInfoFromToken, Tcl_GetCommandName, Tcl_GetCommandFullName, Tcl_GetCommandFromObj Tcl_RegisterCommandTypeName, Tcl_GetCommandTypeName \- implement new commands in C +Tcl_CreateObjCommand, Tcl_DeleteCommand, Tcl_DeleteCommandFromToken, Tcl_GetCommandInfo, Tcl_GetCommandInfoFromToken, Tcl_SetCommandInfo, Tcl_SetCommandInfoFromToken, Tcl_GetCommandName, Tcl_GetCommandFullName, Tcl_GetCommandFromObj, Tcl_RegisterCommandTypeName, Tcl_GetCommandTypeName \- implement new commands in C .SH SYNOPSIS .nf \fB#include \fR diff --git a/generic/tclOO.c b/generic/tclOO.c index 0c18390..2491c2f 100644 --- a/generic/tclOO.c +++ b/generic/tclOO.c @@ -1237,7 +1237,7 @@ ObjectNamespaceDeleted( /* * Because an object can be a class that is an instance of itself, the * class object's class structure should only be cleaned after most of - * the cleanup on the object is done. + * the cleanup on the object is done. * * The class of objects needs some special care; if it is deleted (and * we're not killing the whole interpreter) we force the delete of the diff --git a/generic/tclUtil.c b/generic/tclUtil.c index 4ea9c2e..385bdd3 100644 --- a/generic/tclUtil.c +++ b/generic/tclUtil.c @@ -3660,7 +3660,7 @@ TclFormatInt( * GetWideForIndex -- * * This function produces a wide integer value corresponding to the - * list index held in *objPtr. The parsing supports all values + * list index held in *objPtr. The parsing supports all values * recognized as any size of integer, and the syntaxes end[-+]$integer * and $integer[-+]$integer. The argument endValue is used to give * the meaning of the literal index value "end". -- cgit v0.12 From f8876cc390ecf388114f426db15e641a5adb20fc Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Mon, 22 Oct 2018 19:32:11 +0000 Subject: Update libtommath to latest "develop" branch --- libtommath/README.md | 6 +- libtommath/bn_error.c | 4 +- libtommath/bn_fast_mp_invmod.c | 12 +- libtommath/bn_fast_mp_montgomery_reduce.c | 4 +- libtommath/bn_fast_s_mp_mul_digs.c | 4 +- libtommath/bn_fast_s_mp_mul_high_digs.c | 4 +- libtommath/bn_fast_s_mp_sqr.c | 4 +- libtommath/bn_mp_2expt.c | 4 +- libtommath/bn_mp_abs.c | 4 +- libtommath/bn_mp_add.c | 4 +- libtommath/bn_mp_add_d.c | 4 +- libtommath/bn_mp_addmod.c | 4 +- libtommath/bn_mp_and.c | 4 +- libtommath/bn_mp_clamp.c | 4 +- libtommath/bn_mp_clear.c | 4 +- libtommath/bn_mp_clear_multi.c | 4 +- libtommath/bn_mp_cmp.c | 4 +- libtommath/bn_mp_cmp_d.c | 4 +- libtommath/bn_mp_cmp_mag.c | 4 +- libtommath/bn_mp_cnt_lsb.c | 4 +- libtommath/bn_mp_complement.c | 26 ++++ libtommath/bn_mp_copy.c | 4 +- libtommath/bn_mp_count_bits.c | 4 +- libtommath/bn_mp_div.c | 4 +- libtommath/bn_mp_div_2.c | 4 +- libtommath/bn_mp_div_2d.c | 4 +- libtommath/bn_mp_div_3.c | 4 +- libtommath/bn_mp_div_d.c | 4 +- libtommath/bn_mp_dr_is_modulus.c | 4 +- libtommath/bn_mp_dr_reduce.c | 4 +- libtommath/bn_mp_dr_setup.c | 4 +- libtommath/bn_mp_exch.c | 4 +- libtommath/bn_mp_export.c | 4 +- libtommath/bn_mp_expt_d.c | 4 +- libtommath/bn_mp_expt_d_ex.c | 4 +- libtommath/bn_mp_exptmod.c | 4 +- libtommath/bn_mp_exptmod_fast.c | 4 +- libtommath/bn_mp_exteuclid.c | 4 +- libtommath/bn_mp_fread.c | 4 +- libtommath/bn_mp_fwrite.c | 4 +- libtommath/bn_mp_gcd.c | 4 +- libtommath/bn_mp_get_int.c | 4 +- libtommath/bn_mp_get_long.c | 4 +- libtommath/bn_mp_get_long_long.c | 4 +- libtommath/bn_mp_grow.c | 4 +- libtommath/bn_mp_import.c | 4 +- libtommath/bn_mp_init.c | 4 +- libtommath/bn_mp_init_copy.c | 4 +- libtommath/bn_mp_init_multi.c | 4 +- libtommath/bn_mp_init_set.c | 4 +- libtommath/bn_mp_init_set_int.c | 4 +- libtommath/bn_mp_init_size.c | 4 +- libtommath/bn_mp_invmod.c | 4 +- libtommath/bn_mp_invmod_slow.c | 4 +- libtommath/bn_mp_is_square.c | 28 ++-- libtommath/bn_mp_jacobi.c | 4 +- libtommath/bn_mp_karatsuba_mul.c | 8 +- libtommath/bn_mp_karatsuba_sqr.c | 8 +- libtommath/bn_mp_lcm.c | 4 +- libtommath/bn_mp_lshd.c | 4 +- libtommath/bn_mp_mod.c | 4 +- libtommath/bn_mp_mod_2d.c | 4 +- libtommath/bn_mp_mod_d.c | 4 +- libtommath/bn_mp_montgomery_calc_normalization.c | 4 +- libtommath/bn_mp_montgomery_reduce.c | 4 +- libtommath/bn_mp_montgomery_setup.c | 4 +- libtommath/bn_mp_mul.c | 4 +- libtommath/bn_mp_mul_2.c | 4 +- libtommath/bn_mp_mul_2d.c | 4 +- libtommath/bn_mp_mul_d.c | 4 +- libtommath/bn_mp_mulmod.c | 4 +- libtommath/bn_mp_n_root.c | 4 +- libtommath/bn_mp_n_root_ex.c | 4 +- libtommath/bn_mp_neg.c | 4 +- libtommath/bn_mp_or.c | 4 +- libtommath/bn_mp_prime_fermat.c | 4 +- libtommath/bn_mp_prime_is_divisible.c | 4 +- libtommath/bn_mp_prime_is_prime.c | 4 +- libtommath/bn_mp_prime_miller_rabin.c | 4 +- libtommath/bn_mp_prime_next_prime.c | 4 +- libtommath/bn_mp_prime_rabin_miller_trials.c | 4 +- libtommath/bn_mp_prime_random_ex.c | 4 +- libtommath/bn_mp_radix_size.c | 4 +- libtommath/bn_mp_radix_smap.c | 28 ++-- libtommath/bn_mp_rand.c | 190 ++++++++++++++++++++--- libtommath/bn_mp_read_radix.c | 4 +- libtommath/bn_mp_read_signed_bin.c | 4 +- libtommath/bn_mp_read_unsigned_bin.c | 4 +- libtommath/bn_mp_reduce.c | 4 +- libtommath/bn_mp_reduce_2k.c | 14 +- libtommath/bn_mp_reduce_2k_l.c | 14 +- libtommath/bn_mp_reduce_2k_setup.c | 4 +- libtommath/bn_mp_reduce_2k_setup_l.c | 10 +- libtommath/bn_mp_reduce_is_2k.c | 4 +- libtommath/bn_mp_reduce_is_2k_l.c | 4 +- libtommath/bn_mp_reduce_setup.c | 4 +- libtommath/bn_mp_rshd.c | 4 +- libtommath/bn_mp_set.c | 4 +- libtommath/bn_mp_set_int.c | 4 +- libtommath/bn_mp_set_long.c | 4 +- libtommath/bn_mp_set_long_long.c | 4 +- libtommath/bn_mp_shrink.c | 4 +- libtommath/bn_mp_signed_bin_size.c | 4 +- libtommath/bn_mp_sqr.c | 4 +- libtommath/bn_mp_sqrmod.c | 4 +- libtommath/bn_mp_sqrt.c | 4 +- libtommath/bn_mp_sqrtmod_prime.c | 2 +- libtommath/bn_mp_sub.c | 4 +- libtommath/bn_mp_sub_d.c | 4 +- libtommath/bn_mp_submod.c | 4 +- libtommath/bn_mp_tc_and.c | 89 +++++++++++ libtommath/bn_mp_tc_div_2d.c | 36 +++++ libtommath/bn_mp_tc_or.c | 89 +++++++++++ libtommath/bn_mp_tc_xor.c | 89 +++++++++++ libtommath/bn_mp_to_signed_bin.c | 4 +- libtommath/bn_mp_to_signed_bin_n.c | 4 +- libtommath/bn_mp_to_unsigned_bin.c | 4 +- libtommath/bn_mp_to_unsigned_bin_n.c | 4 +- libtommath/bn_mp_toom_mul.c | 124 ++++++++------- libtommath/bn_mp_toom_sqr.c | 98 ++++++------ libtommath/bn_mp_toradix.c | 4 +- libtommath/bn_mp_toradix_n.c | 4 +- libtommath/bn_mp_unsigned_bin_size.c | 4 +- libtommath/bn_mp_xor.c | 4 +- libtommath/bn_mp_zero.c | 4 +- libtommath/bn_prime_tab.c | 4 +- libtommath/bn_reverse.c | 4 +- libtommath/bn_s_mp_add.c | 4 +- libtommath/bn_s_mp_exptmod.c | 4 +- libtommath/bn_s_mp_mul_digs.c | 4 +- libtommath/bn_s_mp_mul_high_digs.c | 4 +- libtommath/bn_s_mp_sqr.c | 4 +- libtommath/bn_s_mp_sub.c | 4 +- libtommath/bncore.c | 4 +- libtommath/callgraph.txt | 177 +++++++++++++++++++++ libtommath/makefile | 52 ++++--- libtommath/makefile.bcc | 32 ++-- libtommath/makefile.cygwin_dll | 32 ++-- libtommath/makefile.icc | 48 +++--- libtommath/makefile.msvc | 39 ++--- libtommath/makefile.shared | 54 +++---- libtommath/makefile_include.mk | 37 ++++- libtommath/tommath.h | 54 ++++--- libtommath/tommath_class.h | 67 +++++++- libtommath/tommath_private.h | 6 +- 145 files changed, 1216 insertions(+), 717 deletions(-) create mode 100644 libtommath/bn_mp_complement.c create mode 100644 libtommath/bn_mp_tc_and.c create mode 100644 libtommath/bn_mp_tc_div_2d.c create mode 100644 libtommath/bn_mp_tc_or.c create mode 100644 libtommath/bn_mp_tc_xor.c diff --git a/libtommath/README.md b/libtommath/README.md index 3bc491d..0e57a4d 100644 --- a/libtommath/README.md +++ b/libtommath/README.md @@ -4,9 +4,11 @@ This is the git repository for [LibTomMath](http://www.libtom.net/LibTomMath/), ## Build Status -master - [![Build Status - master](https://travis-ci.org/libtom/libtommath.png?branch=master)](https://travis-ci.org/libtom/libtommath) +master: [![Build Status](https://api.travis-ci.org/libtom/libtommath.png?branch=master)](https://travis-ci.org/libtom/libtommath) -develop - [![Build Status - develop](https://travis-ci.org/libtom/libtommath.png?branch=develop)](https://travis-ci.org/libtom/libtommath) +develop: [![Build Status](https://api.travis-ci.org/libtom/libtommath.png?branch=develop)](https://travis-ci.org/libtom/libtommath) + +API/ABI changes: [check here](https://abi-laboratory.pro/tracker/timeline/libtommath/) ## Summary diff --git a/libtommath/bn_error.c b/libtommath/bn_error.c index 7e816bf..05b398a 100644 --- a/libtommath/bn_error.c +++ b/libtommath/bn_error.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_ERROR_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ static const struct { diff --git a/libtommath/bn_fast_mp_invmod.c b/libtommath/bn_fast_mp_invmod.c index 6be44f8..be1a810 100644 --- a/libtommath/bn_fast_mp_invmod.c +++ b/libtommath/bn_fast_mp_invmod.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_FAST_MP_INVMOD_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* computes the modular inverse via binary extended euclidean algorithm, @@ -140,6 +138,14 @@ top: goto LBL_ERR; } } + + /* too big */ + while (mp_cmp_mag(&D, b) != MP_LT) { + if ((res = mp_sub(&D, b, &D)) != MP_OKAY) { + goto LBL_ERR; + } + } + mp_exch(&D, c); c->sign = neg; res = MP_OKAY; diff --git a/libtommath/bn_fast_mp_montgomery_reduce.c b/libtommath/bn_fast_mp_montgomery_reduce.c index 8f91196..3454f58 100644 --- a/libtommath/bn_fast_mp_montgomery_reduce.c +++ b/libtommath/bn_fast_mp_montgomery_reduce.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_FAST_MP_MONTGOMERY_REDUCE_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* computes xR**-1 == x (mod N) via Montgomery Reduction diff --git a/libtommath/bn_fast_s_mp_mul_digs.c b/libtommath/bn_fast_s_mp_mul_digs.c index e542c2e..1da314c 100644 --- a/libtommath/bn_fast_s_mp_mul_digs.c +++ b/libtommath/bn_fast_s_mp_mul_digs.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_FAST_S_MP_MUL_DIGS_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* Fast (comba) multiplier diff --git a/libtommath/bn_fast_s_mp_mul_high_digs.c b/libtommath/bn_fast_s_mp_mul_high_digs.c index 6ea8a6c..45d30ca 100644 --- a/libtommath/bn_fast_s_mp_mul_high_digs.c +++ b/libtommath/bn_fast_s_mp_mul_high_digs.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_FAST_S_MP_MUL_HIGH_DIGS_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* this is a modified version of fast_s_mul_digs that only produces diff --git a/libtommath/bn_fast_s_mp_sqr.c b/libtommath/bn_fast_s_mp_sqr.c index 1050121..3614a44 100644 --- a/libtommath/bn_fast_s_mp_sqr.c +++ b/libtommath/bn_fast_s_mp_sqr.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_FAST_S_MP_SQR_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* the jist of squaring... diff --git a/libtommath/bn_mp_2expt.c b/libtommath/bn_mp_2expt.c index 5333d48..6737a55 100644 --- a/libtommath/bn_mp_2expt.c +++ b/libtommath/bn_mp_2expt.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_2EXPT_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* computes a = 2**b diff --git a/libtommath/bn_mp_abs.c b/libtommath/bn_mp_abs.c index 9b6bcec..7c60014 100644 --- a/libtommath/bn_mp_abs.c +++ b/libtommath/bn_mp_abs.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_ABS_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* b = |a| diff --git a/libtommath/bn_mp_add.c b/libtommath/bn_mp_add.c index d31d5a0..af53713 100644 --- a/libtommath/bn_mp_add.c +++ b/libtommath/bn_mp_add.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_ADD_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* high level addition (handles signs) */ diff --git a/libtommath/bn_mp_add_d.c b/libtommath/bn_mp_add_d.c index e5ede1f..69cbd12 100644 --- a/libtommath/bn_mp_add_d.c +++ b/libtommath/bn_mp_add_d.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_ADD_D_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* single digit addition */ diff --git a/libtommath/bn_mp_addmod.c b/libtommath/bn_mp_addmod.c index 0d612c3..b7907e5 100644 --- a/libtommath/bn_mp_addmod.c +++ b/libtommath/bn_mp_addmod.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_ADDMOD_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* d = a + b (mod c) */ diff --git a/libtommath/bn_mp_and.c b/libtommath/bn_mp_and.c index 09ff772..24f380e 100644 --- a/libtommath/bn_mp_and.c +++ b/libtommath/bn_mp_and.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_AND_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* AND two ints together */ diff --git a/libtommath/bn_mp_clamp.c b/libtommath/bn_mp_clamp.c index 79a5b20..1bdfdc9 100644 --- a/libtommath/bn_mp_clamp.c +++ b/libtommath/bn_mp_clamp.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_CLAMP_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* trim unused digits diff --git a/libtommath/bn_mp_clear.c b/libtommath/bn_mp_clear.c index fcf4d61..fc01cb8 100644 --- a/libtommath/bn_mp_clear.c +++ b/libtommath/bn_mp_clear.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_CLEAR_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* clear one (frees) */ diff --git a/libtommath/bn_mp_clear_multi.c b/libtommath/bn_mp_clear_multi.c index ac3949a..9d7d9da 100644 --- a/libtommath/bn_mp_clear_multi.c +++ b/libtommath/bn_mp_clear_multi.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_CLEAR_MULTI_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ #include diff --git a/libtommath/bn_mp_cmp.c b/libtommath/bn_mp_cmp.c index a33d483..d6e3761 100644 --- a/libtommath/bn_mp_cmp.c +++ b/libtommath/bn_mp_cmp.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_CMP_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* compare two ints (signed)*/ diff --git a/libtommath/bn_mp_cmp_d.c b/libtommath/bn_mp_cmp_d.c index 576a073..9816018 100644 --- a/libtommath/bn_mp_cmp_d.c +++ b/libtommath/bn_mp_cmp_d.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_CMP_D_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* compare a digit */ diff --git a/libtommath/bn_mp_cmp_mag.c b/libtommath/bn_mp_cmp_mag.c index e2c723f..a5f629a 100644 --- a/libtommath/bn_mp_cmp_mag.c +++ b/libtommath/bn_mp_cmp_mag.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_CMP_MAG_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* compare maginitude of two ints (unsigned) */ diff --git a/libtommath/bn_mp_cnt_lsb.c b/libtommath/bn_mp_cnt_lsb.c index 219c369..8e8f488 100644 --- a/libtommath/bn_mp_cnt_lsb.c +++ b/libtommath/bn_mp_cnt_lsb.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_CNT_LSB_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ static const int lnz[16] = { diff --git a/libtommath/bn_mp_complement.c b/libtommath/bn_mp_complement.c new file mode 100644 index 0000000..9dfddc3 --- /dev/null +++ b/libtommath/bn_mp_complement.c @@ -0,0 +1,26 @@ +#include "tommath_private.h" +#ifdef BN_MP_COMPLEMENT_C +/* LibTomMath, multiple-precision integer library -- Tom St Denis + * + * LibTomMath is a library that provides multiple-precision + * integer arithmetic as well as number theoretic functionality. + * + * The library was designed directly after the MPI library by + * Michael Fromberger but has been written from scratch with + * additional optimizations in place. + * + * The library is free for all purposes without any express + * guarantee it works. + */ + +/* b = ~a */ +int mp_complement(const mp_int *a, mp_int *b) +{ + int res = mp_neg(a, b); + return (res == MP_OKAY) ? mp_sub_d(b, 1uL, b) : res; +} +#endif + +/* ref: $Format:%D$ */ +/* git commit: $Format:%H$ */ +/* commit time: $Format:%ai$ */ diff --git a/libtommath/bn_mp_copy.c b/libtommath/bn_mp_copy.c index 17816e8..718febd 100644 --- a/libtommath/bn_mp_copy.c +++ b/libtommath/bn_mp_copy.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_COPY_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* copy, b = a */ diff --git a/libtommath/bn_mp_count_bits.c b/libtommath/bn_mp_count_bits.c index 4530c92..11b84b2 100644 --- a/libtommath/bn_mp_count_bits.c +++ b/libtommath/bn_mp_count_bits.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_COUNT_BITS_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* returns the number of bits in an int */ diff --git a/libtommath/bn_mp_div.c b/libtommath/bn_mp_div.c index f64f485..0d459d1 100644 --- a/libtommath/bn_mp_div.c +++ b/libtommath/bn_mp_div.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_DIV_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ #ifdef BN_MP_DIV_SMALL diff --git a/libtommath/bn_mp_div_2.c b/libtommath/bn_mp_div_2.c index 2907a1b..7ced424 100644 --- a/libtommath/bn_mp_div_2.c +++ b/libtommath/bn_mp_div_2.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_DIV_2_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* b = a/2 */ diff --git a/libtommath/bn_mp_div_2d.c b/libtommath/bn_mp_div_2d.c index aeaa8f2..3fb822c 100644 --- a/libtommath/bn_mp_div_2d.c +++ b/libtommath/bn_mp_div_2d.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_DIV_2D_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* shift right by a certain bit count (store quotient in c, optional remainder in d) */ diff --git a/libtommath/bn_mp_div_3.c b/libtommath/bn_mp_div_3.c index 9d41793..c5ca137 100644 --- a/libtommath/bn_mp_div_3.c +++ b/libtommath/bn_mp_div_3.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_DIV_3_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* divide by three (based on routine from MPI and the GMP manual) */ diff --git a/libtommath/bn_mp_div_d.c b/libtommath/bn_mp_div_d.c index 2124bcc..3020ab2 100644 --- a/libtommath/bn_mp_div_d.c +++ b/libtommath/bn_mp_div_d.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_DIV_D_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ static int s_is_power_of_two(mp_digit b, int *p) diff --git a/libtommath/bn_mp_dr_is_modulus.c b/libtommath/bn_mp_dr_is_modulus.c index bf4ed8b..b01c77c 100644 --- a/libtommath/bn_mp_dr_is_modulus.c +++ b/libtommath/bn_mp_dr_is_modulus.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_DR_IS_MODULUS_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* determines if a number is a valid DR modulus */ diff --git a/libtommath/bn_mp_dr_reduce.c b/libtommath/bn_mp_dr_reduce.c index d677b03..da36b85 100644 --- a/libtommath/bn_mp_dr_reduce.c +++ b/libtommath/bn_mp_dr_reduce.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_DR_REDUCE_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* reduce "x" in place modulo "n" using the Diminished Radix algorithm. diff --git a/libtommath/bn_mp_dr_setup.c b/libtommath/bn_mp_dr_setup.c index 32aa582..afcdaf0 100644 --- a/libtommath/bn_mp_dr_setup.c +++ b/libtommath/bn_mp_dr_setup.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_DR_SETUP_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* determines the setup value */ diff --git a/libtommath/bn_mp_exch.c b/libtommath/bn_mp_exch.c index 2bc635f..b846928 100644 --- a/libtommath/bn_mp_exch.c +++ b/libtommath/bn_mp_exch.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_EXCH_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* swap the elements of two integers, for cases where you can't simply swap the diff --git a/libtommath/bn_mp_export.c b/libtommath/bn_mp_export.c index 92a85d5..e55101a 100644 --- a/libtommath/bn_mp_export.c +++ b/libtommath/bn_mp_export.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_EXPORT_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* based on gmp's mpz_export. diff --git a/libtommath/bn_mp_expt_d.c b/libtommath/bn_mp_expt_d.c index f5ce3c1..7aff105 100644 --- a/libtommath/bn_mp_expt_d.c +++ b/libtommath/bn_mp_expt_d.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_EXPT_D_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* wrapper function for mp_expt_d_ex() */ diff --git a/libtommath/bn_mp_expt_d_ex.c b/libtommath/bn_mp_expt_d_ex.c index d363d59..53e880c 100644 --- a/libtommath/bn_mp_expt_d_ex.c +++ b/libtommath/bn_mp_expt_d_ex.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_EXPT_D_EX_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* calculate c = a**b using a square-multiply algorithm */ diff --git a/libtommath/bn_mp_exptmod.c b/libtommath/bn_mp_exptmod.c index 934fd25..ec0cf7e 100644 --- a/libtommath/bn_mp_exptmod.c +++ b/libtommath/bn_mp_exptmod.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_EXPTMOD_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ diff --git a/libtommath/bn_mp_exptmod_fast.c b/libtommath/bn_mp_exptmod_fast.c index 52d4a55..0d01e38 100644 --- a/libtommath/bn_mp_exptmod_fast.c +++ b/libtommath/bn_mp_exptmod_fast.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_EXPTMOD_FAST_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* computes Y == G**X mod P, HAC pp.616, Algorithm 14.85 diff --git a/libtommath/bn_mp_exteuclid.c b/libtommath/bn_mp_exteuclid.c index 29bad83..b13ee30 100644 --- a/libtommath/bn_mp_exteuclid.c +++ b/libtommath/bn_mp_exteuclid.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_EXTEUCLID_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* Extended euclidean algorithm of (a, b) produces diff --git a/libtommath/bn_mp_fread.c b/libtommath/bn_mp_fread.c index 6922183..7652aac 100644 --- a/libtommath/bn_mp_fread.c +++ b/libtommath/bn_mp_fread.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_FREAD_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ #ifndef LTM_NO_FILE diff --git a/libtommath/bn_mp_fwrite.c b/libtommath/bn_mp_fwrite.c index 8541bc7..8df2134 100644 --- a/libtommath/bn_mp_fwrite.c +++ b/libtommath/bn_mp_fwrite.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_FWRITE_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ #ifndef LTM_NO_FILE diff --git a/libtommath/bn_mp_gcd.c b/libtommath/bn_mp_gcd.c index f5aa78b..0a5000e 100644 --- a/libtommath/bn_mp_gcd.c +++ b/libtommath/bn_mp_gcd.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_GCD_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* Greatest Common Divisor using the binary method */ diff --git a/libtommath/bn_mp_get_int.c b/libtommath/bn_mp_get_int.c index d99a0a0..4f99363 100644 --- a/libtommath/bn_mp_get_int.c +++ b/libtommath/bn_mp_get_int.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_GET_INT_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* get the lower 32-bits of an mp_int */ diff --git a/libtommath/bn_mp_get_long.c b/libtommath/bn_mp_get_long.c index 9ec2664..bb9bd75 100644 --- a/libtommath/bn_mp_get_long.c +++ b/libtommath/bn_mp_get_long.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_GET_LONG_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* get the lower unsigned long of an mp_int, platform dependent */ diff --git a/libtommath/bn_mp_get_long_long.c b/libtommath/bn_mp_get_long_long.c index ffde373..a7a18cd 100644 --- a/libtommath/bn_mp_get_long_long.c +++ b/libtommath/bn_mp_get_long_long.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_GET_LONG_LONG_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* get the lower unsigned long long of an mp_int, platform dependent */ diff --git a/libtommath/bn_mp_grow.c b/libtommath/bn_mp_grow.c index 60f8f32..d336ba1 100644 --- a/libtommath/bn_mp_grow.c +++ b/libtommath/bn_mp_grow.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_GROW_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* grow as required */ diff --git a/libtommath/bn_mp_import.c b/libtommath/bn_mp_import.c index 9bbd215..e28d20e 100644 --- a/libtommath/bn_mp_import.c +++ b/libtommath/bn_mp_import.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_IMPORT_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* based on gmp's mpz_import. diff --git a/libtommath/bn_mp_init.c b/libtommath/bn_mp_init.c index ad630e3..cdc0bd2 100644 --- a/libtommath/bn_mp_init.c +++ b/libtommath/bn_mp_init.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_INIT_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* init a new mp_int */ diff --git a/libtommath/bn_mp_init_copy.c b/libtommath/bn_mp_init_copy.c index 5681015..3d3e6cd 100644 --- a/libtommath/bn_mp_init_copy.c +++ b/libtommath/bn_mp_init_copy.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_INIT_COPY_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* creates "a" then copies b into it */ diff --git a/libtommath/bn_mp_init_multi.c b/libtommath/bn_mp_init_multi.c index 9ed777c..d254696 100644 --- a/libtommath/bn_mp_init_multi.c +++ b/libtommath/bn_mp_init_multi.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_INIT_MULTI_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ #include diff --git a/libtommath/bn_mp_init_set.c b/libtommath/bn_mp_init_set.c index e9c1b12..4bce757 100644 --- a/libtommath/bn_mp_init_set.c +++ b/libtommath/bn_mp_init_set.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_INIT_SET_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* initialize and set a digit */ diff --git a/libtommath/bn_mp_init_set_int.c b/libtommath/bn_mp_init_set_int.c index 8e7441a..10c5bb7 100644 --- a/libtommath/bn_mp_init_set_int.c +++ b/libtommath/bn_mp_init_set_int.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_INIT_SET_INT_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* initialize and set a digit */ diff --git a/libtommath/bn_mp_init_size.c b/libtommath/bn_mp_init_size.c index 35713ac..ccca5b9 100644 --- a/libtommath/bn_mp_init_size.c +++ b/libtommath/bn_mp_init_size.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_INIT_SIZE_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* init an mp_init for a given size */ diff --git a/libtommath/bn_mp_invmod.c b/libtommath/bn_mp_invmod.c index 96717ea..8dd188c 100644 --- a/libtommath/bn_mp_invmod.c +++ b/libtommath/bn_mp_invmod.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_INVMOD_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* hac 14.61, pp608 */ diff --git a/libtommath/bn_mp_invmod_slow.c b/libtommath/bn_mp_invmod_slow.c index 360f161..49ed095 100644 --- a/libtommath/bn_mp_invmod_slow.c +++ b/libtommath/bn_mp_invmod_slow.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_INVMOD_SLOW_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* hac 14.61, pp608 */ diff --git a/libtommath/bn_mp_is_square.c b/libtommath/bn_mp_is_square.c index 329d727..6e3cb56 100644 --- a/libtommath/bn_mp_is_square.c +++ b/libtommath/bn_mp_is_square.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_IS_SQUARE_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* Check if remainders are possible squares - fast exclude non-squares */ @@ -75,31 +73,31 @@ int mp_is_square(const mp_int *arg, int *ret) return res; } if ((res = mp_mod(arg, &t, &t)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } r = mp_get_int(&t); /* Check for other prime modules, note it's not an ERROR but we must - * free "t" so the easiest way is to goto ERR. We know that res + * free "t" so the easiest way is to goto LBL_ERR. We know that res * is already equal to MP_OKAY from the mp_mod call */ - if (((1uL<<(r%11uL)) & 0x5C4uL) != 0uL) goto ERR; - if (((1uL<<(r%13uL)) & 0x9E4uL) != 0uL) goto ERR; - if (((1uL<<(r%17uL)) & 0x5CE8uL) != 0uL) goto ERR; - if (((1uL<<(r%19uL)) & 0x4F50CuL) != 0uL) goto ERR; - if (((1uL<<(r%23uL)) & 0x7ACCA0uL) != 0uL) goto ERR; - if (((1uL<<(r%29uL)) & 0xC2EDD0CuL) != 0uL) goto ERR; - if (((1uL<<(r%31uL)) & 0x6DE2B848uL) != 0uL) goto ERR; + if (((1uL<<(r%11uL)) & 0x5C4uL) != 0uL) goto LBL_ERR; + if (((1uL<<(r%13uL)) & 0x9E4uL) != 0uL) goto LBL_ERR; + if (((1uL<<(r%17uL)) & 0x5CE8uL) != 0uL) goto LBL_ERR; + if (((1uL<<(r%19uL)) & 0x4F50CuL) != 0uL) goto LBL_ERR; + if (((1uL<<(r%23uL)) & 0x7ACCA0uL) != 0uL) goto LBL_ERR; + if (((1uL<<(r%29uL)) & 0xC2EDD0CuL) != 0uL) goto LBL_ERR; + if (((1uL<<(r%31uL)) & 0x6DE2B848uL) != 0uL) goto LBL_ERR; /* Final check - is sqr(sqrt(arg)) == arg ? */ if ((res = mp_sqrt(arg, &t)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_sqr(&t, &t)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } *ret = (mp_cmp_mag(&t, arg) == MP_EQ) ? MP_YES : MP_NO; -ERR: +LBL_ERR: mp_clear(&t); return res; } diff --git a/libtommath/bn_mp_jacobi.c b/libtommath/bn_mp_jacobi.c index ef2e72f..fe37f22 100644 --- a/libtommath/bn_mp_jacobi.c +++ b/libtommath/bn_mp_jacobi.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_JACOBI_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* computes the jacobi c = (a | n) (or Legendre if n is prime) diff --git a/libtommath/bn_mp_karatsuba_mul.c b/libtommath/bn_mp_karatsuba_mul.c index 1a84211..af12c55 100644 --- a/libtommath/bn_mp_karatsuba_mul.c +++ b/libtommath/bn_mp_karatsuba_mul.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_KARATSUBA_MUL_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* c = |a| * |b| using Karatsuba Multiplication using @@ -60,7 +58,7 @@ int mp_karatsuba_mul(const mp_int *a, const mp_int *b, mp_int *c) /* init copy all the temps */ if (mp_init_size(&x0, B) != MP_OKAY) - goto ERR; + goto LBL_ERR; if (mp_init_size(&x1, a->used - B) != MP_OKAY) goto X0; if (mp_init_size(&y0, B) != MP_OKAY) @@ -164,7 +162,7 @@ X1: mp_clear(&x1); X0: mp_clear(&x0); -ERR: +LBL_ERR: return err; } #endif diff --git a/libtommath/bn_mp_karatsuba_sqr.c b/libtommath/bn_mp_karatsuba_sqr.c index c566b06..99a31b8 100644 --- a/libtommath/bn_mp_karatsuba_sqr.c +++ b/libtommath/bn_mp_karatsuba_sqr.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_KARATSUBA_SQR_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* Karatsuba squaring, computes b = a*a using three @@ -37,7 +35,7 @@ int mp_karatsuba_sqr(const mp_int *a, mp_int *b) /* init copy all the temps */ if (mp_init_size(&x0, B) != MP_OKAY) - goto ERR; + goto LBL_ERR; if (mp_init_size(&x1, a->used - B) != MP_OKAY) goto X0; @@ -117,7 +115,7 @@ X1: mp_clear(&x1); X0: mp_clear(&x0); -ERR: +LBL_ERR: return err; } #endif diff --git a/libtommath/bn_mp_lcm.c b/libtommath/bn_mp_lcm.c index 24b621c..3798afc 100644 --- a/libtommath/bn_mp_lcm.c +++ b/libtommath/bn_mp_lcm.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_LCM_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* computes least common multiple as |a*b|/(a, b) */ diff --git a/libtommath/bn_mp_lshd.c b/libtommath/bn_mp_lshd.c index b49b545..649df90 100644 --- a/libtommath/bn_mp_lshd.c +++ b/libtommath/bn_mp_lshd.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_LSHD_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* shift left a certain amount of digits */ diff --git a/libtommath/bn_mp_mod.c b/libtommath/bn_mp_mod.c index 64e73ea..21acf8c 100644 --- a/libtommath/bn_mp_mod.c +++ b/libtommath/bn_mp_mod.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_MOD_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* c = a mod b, 0 <= c < b if b > 0, b < c <= 0 if b < 0 */ diff --git a/libtommath/bn_mp_mod_2d.c b/libtommath/bn_mp_mod_2d.c index 7a74746..bf69221 100644 --- a/libtommath/bn_mp_mod_2d.c +++ b/libtommath/bn_mp_mod_2d.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_MOD_2D_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* calc a value mod 2**b */ diff --git a/libtommath/bn_mp_mod_d.c b/libtommath/bn_mp_mod_d.c index 9a24e78..5252c4f 100644 --- a/libtommath/bn_mp_mod_d.c +++ b/libtommath/bn_mp_mod_d.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_MOD_D_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ int mp_mod_d(const mp_int *a, mp_digit b, mp_digit *c) diff --git a/libtommath/bn_mp_montgomery_calc_normalization.c b/libtommath/bn_mp_montgomery_calc_normalization.c index 360e3e5..8b0a320 100644 --- a/libtommath/bn_mp_montgomery_calc_normalization.c +++ b/libtommath/bn_mp_montgomery_calc_normalization.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_MONTGOMERY_CALC_NORMALIZATION_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* diff --git a/libtommath/bn_mp_montgomery_reduce.c b/libtommath/bn_mp_montgomery_reduce.c index e3a0eaa..2def073 100644 --- a/libtommath/bn_mp_montgomery_reduce.c +++ b/libtommath/bn_mp_montgomery_reduce.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_MONTGOMERY_REDUCE_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* computes xR**-1 == x (mod N) via Montgomery Reduction */ diff --git a/libtommath/bn_mp_montgomery_setup.c b/libtommath/bn_mp_montgomery_setup.c index 75da42b..cd53b6d 100644 --- a/libtommath/bn_mp_montgomery_setup.c +++ b/libtommath/bn_mp_montgomery_setup.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_MONTGOMERY_SETUP_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* setups the montgomery reduction stuff */ diff --git a/libtommath/bn_mp_mul.c b/libtommath/bn_mp_mul.c index babb12b..e7613a3 100644 --- a/libtommath/bn_mp_mul.c +++ b/libtommath/bn_mp_mul.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_MUL_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* high level multiplication (handles sign) */ diff --git a/libtommath/bn_mp_mul_2.c b/libtommath/bn_mp_mul_2.c index 7611536..e0f051f 100644 --- a/libtommath/bn_mp_mul_2.c +++ b/libtommath/bn_mp_mul_2.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_MUL_2_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* b = a*2 */ diff --git a/libtommath/bn_mp_mul_2d.c b/libtommath/bn_mp_mul_2d.c index 96aef85..42c6535 100644 --- a/libtommath/bn_mp_mul_2d.c +++ b/libtommath/bn_mp_mul_2d.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_MUL_2D_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* shift left by a certain bit count */ diff --git a/libtommath/bn_mp_mul_d.c b/libtommath/bn_mp_mul_d.c index 13f94a2..d6bddfd 100644 --- a/libtommath/bn_mp_mul_d.c +++ b/libtommath/bn_mp_mul_d.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_MUL_D_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* multiply by a digit */ diff --git a/libtommath/bn_mp_mulmod.c b/libtommath/bn_mp_mulmod.c index aeee4ee..ca9ef3e 100644 --- a/libtommath/bn_mp_mulmod.c +++ b/libtommath/bn_mp_mulmod.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_MULMOD_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* d = a * b (mod c) */ diff --git a/libtommath/bn_mp_n_root.c b/libtommath/bn_mp_n_root.c index a09804f..16232d8 100644 --- a/libtommath/bn_mp_n_root.c +++ b/libtommath/bn_mp_n_root.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_N_ROOT_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* wrapper function for mp_n_root_ex() diff --git a/libtommath/bn_mp_n_root_ex.c b/libtommath/bn_mp_n_root_ex.c index 60c9929..9fd7098 100644 --- a/libtommath/bn_mp_n_root_ex.c +++ b/libtommath/bn_mp_n_root_ex.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_N_ROOT_EX_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* find the n'th root of an integer diff --git a/libtommath/bn_mp_neg.c b/libtommath/bn_mp_neg.c index 75f8bbd..612b9c7 100644 --- a/libtommath/bn_mp_neg.c +++ b/libtommath/bn_mp_neg.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_NEG_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* b = -a */ diff --git a/libtommath/bn_mp_or.c b/libtommath/bn_mp_or.c index f411509..151dfff 100644 --- a/libtommath/bn_mp_or.c +++ b/libtommath/bn_mp_or.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_OR_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* OR two ints together */ diff --git a/libtommath/bn_mp_prime_fermat.c b/libtommath/bn_mp_prime_fermat.c index e71e0ae..7cd39bd 100644 --- a/libtommath/bn_mp_prime_fermat.c +++ b/libtommath/bn_mp_prime_fermat.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_PRIME_FERMAT_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* performs one Fermat test. diff --git a/libtommath/bn_mp_prime_is_divisible.c b/libtommath/bn_mp_prime_is_divisible.c index c49fdd2..706521e 100644 --- a/libtommath/bn_mp_prime_is_divisible.c +++ b/libtommath/bn_mp_prime_is_divisible.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_PRIME_IS_DIVISIBLE_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* determines if an integers is divisible by one diff --git a/libtommath/bn_mp_prime_is_prime.c b/libtommath/bn_mp_prime_is_prime.c index e97712d..209fba0 100644 --- a/libtommath/bn_mp_prime_is_prime.c +++ b/libtommath/bn_mp_prime_is_prime.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_PRIME_IS_PRIME_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* performs a variable number of rounds of Miller-Rabin diff --git a/libtommath/bn_mp_prime_miller_rabin.c b/libtommath/bn_mp_prime_miller_rabin.c index 34c4d1c..5d94e36 100644 --- a/libtommath/bn_mp_prime_miller_rabin.c +++ b/libtommath/bn_mp_prime_miller_rabin.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_PRIME_MILLER_RABIN_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* Miller-Rabin test of "a" to the base of "b" as described in diff --git a/libtommath/bn_mp_prime_next_prime.c b/libtommath/bn_mp_prime_next_prime.c index b106a74..89e2841 100644 --- a/libtommath/bn_mp_prime_next_prime.c +++ b/libtommath/bn_mp_prime_next_prime.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_PRIME_NEXT_PRIME_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* finds the next prime after the number "a" using "t" trials diff --git a/libtommath/bn_mp_prime_rabin_miller_trials.c b/libtommath/bn_mp_prime_rabin_miller_trials.c index cde309a..d400902 100644 --- a/libtommath/bn_mp_prime_rabin_miller_trials.c +++ b/libtommath/bn_mp_prime_rabin_miller_trials.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_PRIME_RABIN_MILLER_TRIALS_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ diff --git a/libtommath/bn_mp_prime_random_ex.c b/libtommath/bn_mp_prime_random_ex.c index 1ae2934..13fdcdf 100644 --- a/libtommath/bn_mp_prime_random_ex.c +++ b/libtommath/bn_mp_prime_random_ex.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_PRIME_RANDOM_EX_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* makes a truly random prime of a given size (bits), diff --git a/libtommath/bn_mp_radix_size.c b/libtommath/bn_mp_radix_size.c index 29355cb..1e286ed 100644 --- a/libtommath/bn_mp_radix_size.c +++ b/libtommath/bn_mp_radix_size.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_RADIX_SIZE_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* returns size of ASCII reprensentation */ diff --git a/libtommath/bn_mp_radix_smap.c b/libtommath/bn_mp_radix_smap.c index 262775c..6e9f64a 100644 --- a/libtommath/bn_mp_radix_smap.c +++ b/libtommath/bn_mp_radix_smap.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_RADIX_SMAP_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,24 +11,22 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* chars used in radix conversions */ -const char *mp_s_rmap = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/"; +const char *const mp_s_rmap = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/"; const uint8_t mp_s_rmap_reverse[] = { - 0xff, 0xff, 0xff, 0x3e, 0xff, 0xff, 0xff, 0x3f, /* ()*+,-./ */ - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, /* 01234567 */ - 0x08, 0x09, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 89:;<=>? */ - 0xff, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, /* @ABCDEFG */ - 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, /* HIJKLMNO */ - 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, /* PQRSTUVW */ - 0x21, 0x22, 0x23, 0xff, 0xff, 0xff, 0xff, 0xff, /* XYZ[\]^_ */ - 0xff, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, /* `abcdefg */ - 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, /* hijklmno */ - 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, /* pqrstuvw */ - 0x3b, 0x3c, 0x3d, 0xff, 0xff, 0xff, 0xff, 0xff, /* xyz{|}~. */ + 0xff, 0xff, 0xff, 0x3e, 0xff, 0xff, 0xff, 0x3f, /* ()*+,-./ */ + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, /* 01234567 */ + 0x08, 0x09, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 89:;<=>? */ + 0xff, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, /* @ABCDEFG */ + 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, /* HIJKLMNO */ + 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, /* PQRSTUVW */ + 0x21, 0x22, 0x23, 0xff, 0xff, 0xff, 0xff, 0xff, /* XYZ[\]^_ */ + 0xff, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, /* `abcdefg */ + 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, /* hijklmno */ + 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, /* pqrstuvw */ + 0x3b, 0x3c, 0x3d, 0xff, 0xff, 0xff, 0xff, 0xff, /* xyz{|}~. */ }; const size_t mp_s_rmap_reverse_sz = sizeof(mp_s_rmap_reverse); #endif diff --git a/libtommath/bn_mp_rand.c b/libtommath/bn_mp_rand.c index 2ed665e..af017f2 100644 --- a/libtommath/bn_mp_rand.c +++ b/libtommath/bn_mp_rand.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_RAND_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,38 +11,173 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ -#if defined(MP_8BIT) || defined(MP_16BIT) -#define MP_GEN_RANDOM_SHIFT DIGIT_BIT -#else -#if MP_GEN_RANDOM_MAX == 0xffffffffu -#define MP_GEN_RANDOM_SHIFT 32 -#elif MP_GEN_RANDOM_MAX == 32767 -/* SHRT_MAX */ -#define MP_GEN_RANDOM_SHIFT 15 -#elif MP_GEN_RANDOM_MAX == 2147483647 -/* INT_MAX */ -#define MP_GEN_RANDOM_SHIFT 31 -#elif !defined(MP_GEN_RANDOM_SHIFT) -#error Thou shalt define their own valid MP_GEN_RANDOM_SHIFT -#endif -#endif +/* First the OS-specific special cases + * - *BSD + * - Windows + */ +#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__) +#define MP_ARC4RANDOM +#define MP_GEN_RANDOM_MAX 0xffffffffu +#define MP_GEN_RANDOM_SHIFT 32 -/* makes a pseudo-random int of a given size */ -static mp_digit s_gen_random(void) +static int s_read_arc4random(mp_digit *p) { mp_digit d = 0, msk = 0; do { d <<= MP_GEN_RANDOM_SHIFT; - d |= ((mp_digit) MP_GEN_RANDOM()); + d |= ((mp_digit) arc4random()); msk <<= MP_GEN_RANDOM_SHIFT; msk |= (MP_MASK & MP_GEN_RANDOM_MAX); } while ((MP_MASK & msk) != MP_MASK); - d &= MP_MASK; - return d; + *p = d; + return MP_OKAY; +} +#endif + +#if defined(_WIN32) || defined(_WIN32_WCE) +#define MP_WIN_CSP + +#ifndef _WIN32_WINNT +#define _WIN32_WINNT 0x0400 +#endif +#ifdef _WIN32_WCE +#define UNDER_CE +#define ARM +#endif + +#define WIN32_LEAN_AND_MEAN +#include +#include + +static HCRYPTPROV hProv = 0; + +static void s_cleanup_win_csp(void) +{ + CryptReleaseContext(hProv, 0); + hProv = 0; +} + +static int s_read_win_csp(mp_digit *p) +{ + int ret = -1; + if (hProv == 0) { + if (!CryptAcquireContext(&hProv, NULL, MS_DEF_PROV, PROV_RSA_FULL, + (CRYPT_VERIFYCONTEXT | CRYPT_MACHINE_KEYSET)) && + !CryptAcquireContext(&hProv, NULL, MS_DEF_PROV, PROV_RSA_FULL, + CRYPT_VERIFYCONTEXT | CRYPT_MACHINE_KEYSET | CRYPT_NEWKEYSET)) { + hProv = 0; + return ret; + } + atexit(s_cleanup_win_csp); + } + if (CryptGenRandom(hProv, sizeof(*p), (void *)p) == TRUE) { + ret = MP_OKAY; + } + return ret; +} +#endif /* WIN32 */ + +#if !defined(MP_WIN_CSP) && defined(__linux__) && defined(__GLIBC_PREREQ) +#if __GLIBC_PREREQ(2, 25) +#define MP_GETRANDOM +#include +#include + +static int s_read_getrandom(mp_digit *p) +{ + int ret; + do { + ret = getrandom(p, sizeof(*p), 0); + } while ((ret == -1) && (errno == EINTR)); + if (ret == sizeof(*p)) return MP_OKAY; + return -1; +} +#endif +#endif + +/* We assume all platforms besides windows provide "/dev/urandom". + * In case yours doesn't, define MP_NO_DEV_URANDOM at compile-time. + */ +#if !defined(MP_WIN_CSP) && !defined(MP_NO_DEV_URANDOM) +#ifndef MP_DEV_URANDOM +#define MP_DEV_URANDOM "/dev/urandom" +#endif +#include +#include +#include + +static int s_read_dev_urandom(mp_digit *p) +{ + ssize_t r; + int fd; + do { + fd = open(MP_DEV_URANDOM, O_RDONLY); + } while ((fd == -1) && (errno == EINTR)); + if (fd == -1) return -1; + do { + r = read(fd, p, sizeof(*p)); + } while ((r == -1) && (errno == EINTR)); + close(fd); + if (r != sizeof(*p)) return -1; + return MP_OKAY; +} +#endif + +#if defined(MP_PRNG_ENABLE_LTM_RNG) +unsigned long (*ltm_rng)(unsigned char *out, unsigned long outlen, void (*callback)(void)); +void (*ltm_rng_callback)(void); + +static int s_read_ltm_rng(mp_digit *p) +{ + unsigned long ret; + if (ltm_rng == NULL) return -1; + ret = ltm_rng((void *)p, sizeof(*p), ltm_rng_callback); + if (ret != sizeof(*p)) return -1; + return MP_OKAY; +} +#endif + +static int s_rand_digit(mp_digit *p) +{ + int ret = -1; + +#if defined(MP_ARC4RANDOM) + ret = s_read_arc4random(p); + if (ret == MP_OKAY) return ret; +#endif + +#if defined(MP_WIN_CSP) + ret = s_read_win_csp(p); + if (ret == MP_OKAY) return ret; +#else + +#if defined(MP_GETRANDOM) + ret = s_read_getrandom(p); + if (ret == MP_OKAY) return ret; +#endif +#if defined(MP_DEV_URANDOM) + ret = s_read_dev_urandom(p); + if (ret == MP_OKAY) return ret; +#endif + +#endif /* MP_WIN_CSP */ + +#if defined(MP_PRNG_ENABLE_LTM_RNG) + ret = s_read_ltm_rng(p); + if (ret == MP_OKAY) return ret; +#endif + + return ret; +} + +/* makes a pseudo-random int of a given size */ +static int s_gen_random(mp_digit *r) +{ + int ret = s_rand_digit(r); + *r &= MP_MASK; + return ret; } int mp_rand(mp_int *a, int digits) @@ -57,7 +192,9 @@ int mp_rand(mp_int *a, int digits) /* first place a random non-zero digit */ do { - d = s_gen_random(); + if (s_gen_random(&d) != MP_OKAY) { + return MP_VAL; + } } while (d == 0u); if ((res = mp_add_d(a, d, a)) != MP_OKAY) { @@ -69,7 +206,10 @@ int mp_rand(mp_int *a, int digits) return res; } - if ((res = mp_add_d(a, s_gen_random(), a)) != MP_OKAY) { + if (s_gen_random(&d) != MP_OKAY) { + return MP_VAL; + } + if ((res = mp_add_d(a, d, a)) != MP_OKAY) { return res; } } diff --git a/libtommath/bn_mp_read_radix.c b/libtommath/bn_mp_read_radix.c index 55c5ee1..02ba113 100644 --- a/libtommath/bn_mp_read_radix.c +++ b/libtommath/bn_mp_read_radix.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_READ_RADIX_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* read a string [ASCII] in a given radix */ diff --git a/libtommath/bn_mp_read_signed_bin.c b/libtommath/bn_mp_read_signed_bin.c index 17bc6ce..3a0e231 100644 --- a/libtommath/bn_mp_read_signed_bin.c +++ b/libtommath/bn_mp_read_signed_bin.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_READ_SIGNED_BIN_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* read signed bin, big endian, first byte is 0==positive or 1==negative */ diff --git a/libtommath/bn_mp_read_unsigned_bin.c b/libtommath/bn_mp_read_unsigned_bin.c index 6398c43..f29e7e6 100644 --- a/libtommath/bn_mp_read_unsigned_bin.c +++ b/libtommath/bn_mp_read_unsigned_bin.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_READ_UNSIGNED_BIN_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* reads a unsigned char array, assumes the msb is stored first [big endian] */ diff --git a/libtommath/bn_mp_reduce.c b/libtommath/bn_mp_reduce.c index 5b1d405..3f93387 100644 --- a/libtommath/bn_mp_reduce.c +++ b/libtommath/bn_mp_reduce.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_REDUCE_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* reduces x mod m, assumes 0 < x < m**2, mu is diff --git a/libtommath/bn_mp_reduce_2k.c b/libtommath/bn_mp_reduce_2k.c index e1e2bc8..f5c74b8 100644 --- a/libtommath/bn_mp_reduce_2k.c +++ b/libtommath/bn_mp_reduce_2k.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_REDUCE_2K_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* reduces a modulo n where n is of the form 2**p - d */ @@ -29,29 +27,29 @@ int mp_reduce_2k(mp_int *a, const mp_int *n, mp_digit d) top: /* q = a/2**p, a = a mod 2**p */ if ((res = mp_div_2d(a, p, &q, a)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if (d != 1u) { /* q = q * d */ if ((res = mp_mul_d(&q, d, &q)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } } /* a = a + q */ if ((res = s_mp_add(a, &q, a)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if (mp_cmp_mag(a, n) != MP_LT) { if ((res = s_mp_sub(a, n, a)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } goto top; } -ERR: +LBL_ERR: mp_clear(&q); return res; } diff --git a/libtommath/bn_mp_reduce_2k_l.c b/libtommath/bn_mp_reduce_2k_l.c index 23381bf..cbdfad7 100644 --- a/libtommath/bn_mp_reduce_2k_l.c +++ b/libtommath/bn_mp_reduce_2k_l.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_REDUCE_2K_L_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* reduces a modulo n where n is of the form 2**p - d @@ -32,27 +30,27 @@ int mp_reduce_2k_l(mp_int *a, const mp_int *n, const mp_int *d) top: /* q = a/2**p, a = a mod 2**p */ if ((res = mp_div_2d(a, p, &q, a)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } /* q = q * d */ if ((res = mp_mul(&q, d, &q)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } /* a = a + q */ if ((res = s_mp_add(a, &q, a)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if (mp_cmp_mag(a, n) != MP_LT) { if ((res = s_mp_sub(a, n, a)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } goto top; } -ERR: +LBL_ERR: mp_clear(&q); return res; } diff --git a/libtommath/bn_mp_reduce_2k_setup.c b/libtommath/bn_mp_reduce_2k_setup.c index e6ae839..11248a3 100644 --- a/libtommath/bn_mp_reduce_2k_setup.c +++ b/libtommath/bn_mp_reduce_2k_setup.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_REDUCE_2K_SETUP_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* determines the setup value */ diff --git a/libtommath/bn_mp_reduce_2k_setup_l.c b/libtommath/bn_mp_reduce_2k_setup_l.c index af81b5b..04c7634 100644 --- a/libtommath/bn_mp_reduce_2k_setup_l.c +++ b/libtommath/bn_mp_reduce_2k_setup_l.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_REDUCE_2K_SETUP_L_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* determines the setup value */ @@ -26,14 +24,14 @@ int mp_reduce_2k_setup_l(const mp_int *a, mp_int *d) } if ((res = mp_2expt(&tmp, mp_count_bits(a))) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = s_mp_sub(&tmp, a, d)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } -ERR: +LBL_ERR: mp_clear(&tmp); return res; } diff --git a/libtommath/bn_mp_reduce_is_2k.c b/libtommath/bn_mp_reduce_is_2k.c index f59d535..14612c0 100644 --- a/libtommath/bn_mp_reduce_is_2k.c +++ b/libtommath/bn_mp_reduce_is_2k.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_REDUCE_IS_2K_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* determines if mp_reduce_2k can be used */ diff --git a/libtommath/bn_mp_reduce_is_2k_l.c b/libtommath/bn_mp_reduce_is_2k_l.c index 22c7582..7c9cacf 100644 --- a/libtommath/bn_mp_reduce_is_2k_l.c +++ b/libtommath/bn_mp_reduce_is_2k_l.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_REDUCE_IS_2K_L_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* determines if reduce_2k_l can be used */ diff --git a/libtommath/bn_mp_reduce_setup.c b/libtommath/bn_mp_reduce_setup.c index 70e193a..92d03fc 100644 --- a/libtommath/bn_mp_reduce_setup.c +++ b/libtommath/bn_mp_reduce_setup.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_REDUCE_SETUP_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* pre-calculate the value required for Barrett reduction diff --git a/libtommath/bn_mp_rshd.c b/libtommath/bn_mp_rshd.c index fd06735..d17ad00 100644 --- a/libtommath/bn_mp_rshd.c +++ b/libtommath/bn_mp_rshd.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_RSHD_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* shift right a certain amount of digits */ diff --git a/libtommath/bn_mp_set.c b/libtommath/bn_mp_set.c index 952d080..dc03f4c 100644 --- a/libtommath/bn_mp_set.c +++ b/libtommath/bn_mp_set.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_SET_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* set to a digit */ diff --git a/libtommath/bn_mp_set_int.c b/libtommath/bn_mp_set_int.c index 006f263..4d6e580 100644 --- a/libtommath/bn_mp_set_int.c +++ b/libtommath/bn_mp_set_int.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_SET_INT_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* set a 32-bit const */ diff --git a/libtommath/bn_mp_set_long.c b/libtommath/bn_mp_set_long.c index 8cbb811..f842632 100644 --- a/libtommath/bn_mp_set_long.c +++ b/libtommath/bn_mp_set_long.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_SET_LONG_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* set a platform dependent unsigned long int */ diff --git a/libtommath/bn_mp_set_long_long.c b/libtommath/bn_mp_set_long_long.c index 3566b45..7c77501 100644 --- a/libtommath/bn_mp_set_long_long.c +++ b/libtommath/bn_mp_set_long_long.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_SET_LONG_LONG_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* set a platform dependent unsigned long long int */ diff --git a/libtommath/bn_mp_shrink.c b/libtommath/bn_mp_shrink.c index 3e4dde0..b2e9d89 100644 --- a/libtommath/bn_mp_shrink.c +++ b/libtommath/bn_mp_shrink.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_SHRINK_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* shrink a bignum */ diff --git a/libtommath/bn_mp_signed_bin_size.c b/libtommath/bn_mp_signed_bin_size.c index 1fdfd85..529482f 100644 --- a/libtommath/bn_mp_signed_bin_size.c +++ b/libtommath/bn_mp_signed_bin_size.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_SIGNED_BIN_SIZE_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* get the size for an signed equivalent */ diff --git a/libtommath/bn_mp_sqr.c b/libtommath/bn_mp_sqr.c index a98f16c..237c919 100644 --- a/libtommath/bn_mp_sqr.c +++ b/libtommath/bn_mp_sqr.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_SQR_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* computes b = a*a */ diff --git a/libtommath/bn_mp_sqrmod.c b/libtommath/bn_mp_sqrmod.c index c3c7ec9..f3ed8a8 100644 --- a/libtommath/bn_mp_sqrmod.c +++ b/libtommath/bn_mp_sqrmod.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_SQRMOD_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* c = a * a (mod b) */ diff --git a/libtommath/bn_mp_sqrt.c b/libtommath/bn_mp_sqrt.c index d70c523..ec1b785 100644 --- a/libtommath/bn_mp_sqrt.c +++ b/libtommath/bn_mp_sqrt.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_SQRT_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* this function is less generic than mp_n_root, simpler and faster */ diff --git a/libtommath/bn_mp_sqrtmod_prime.c b/libtommath/bn_mp_sqrtmod_prime.c index d4cf3de..f7647b9 100644 --- a/libtommath/bn_mp_sqrtmod_prime.c +++ b/libtommath/bn_mp_sqrtmod_prime.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_SQRTMOD_PRIME_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * diff --git a/libtommath/bn_mp_sub.c b/libtommath/bn_mp_sub.c index 19cb65e..9ef1059 100644 --- a/libtommath/bn_mp_sub.c +++ b/libtommath/bn_mp_sub.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_SUB_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* high level subtraction (handles signs) */ diff --git a/libtommath/bn_mp_sub_d.c b/libtommath/bn_mp_sub_d.c index e5fbfff..1ac9859 100644 --- a/libtommath/bn_mp_sub_d.c +++ b/libtommath/bn_mp_sub_d.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_SUB_D_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* single digit subtraction */ diff --git a/libtommath/bn_mp_submod.c b/libtommath/bn_mp_submod.c index c4db397..0325b9d 100644 --- a/libtommath/bn_mp_submod.c +++ b/libtommath/bn_mp_submod.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_SUBMOD_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* d = a - b (mod c) */ diff --git a/libtommath/bn_mp_tc_and.c b/libtommath/bn_mp_tc_and.c new file mode 100644 index 0000000..e9fe4c6 --- /dev/null +++ b/libtommath/bn_mp_tc_and.c @@ -0,0 +1,89 @@ +#include "tommath_private.h" +#ifdef BN_MP_TC_AND_C +/* LibTomMath, multiple-precision integer library -- Tom St Denis + * + * LibTomMath is a library that provides multiple-precision + * integer arithmetic as well as number theoretic functionality. + * + * The library was designed directly after the MPI library by + * Michael Fromberger but has been written from scratch with + * additional optimizations in place. + * + * The library is free for all purposes without any express + * guarantee it works. + */ + +/* two complement and */ +int mp_tc_and(const mp_int *a, const mp_int *b, mp_int *c) +{ + int res = MP_OKAY, bits; + int as = mp_isneg(a), bs = mp_isneg(b); + mp_int *mx = NULL, _mx, acpy, bcpy; + + if ((as != MP_NO) || (bs != MP_NO)) { + bits = MAX(mp_count_bits(a), mp_count_bits(b)); + res = mp_init_set_int(&_mx, 1uL); + if (res != MP_OKAY) { + goto end; + } + + mx = &_mx; + res = mp_mul_2d(mx, bits + 1, mx); + if (res != MP_OKAY) { + goto end; + } + + if (as != MP_NO) { + res = mp_init(&acpy); + if (res != MP_OKAY) { + goto end; + } + + res = mp_add(mx, a, &acpy); + if (res != MP_OKAY) { + mp_clear(&acpy); + goto end; + } + a = &acpy; + } + if (bs != MP_NO) { + res = mp_init(&bcpy); + if (res != MP_OKAY) { + goto end; + } + + res = mp_add(mx, b, &bcpy); + if (res != MP_OKAY) { + mp_clear(&bcpy); + goto end; + } + b = &bcpy; + } + } + + res = mp_and(a, b, c); + + if ((as != MP_NO) && (bs != MP_NO) && (res == MP_OKAY)) { + res = mp_sub(c, mx, c); + } + +end: + if (a == &acpy) { + mp_clear(&acpy); + } + + if (b == &bcpy) { + mp_clear(&bcpy); + } + + if (mx == &_mx) { + mp_clear(mx); + } + + return res; +} +#endif + +/* ref: $Format:%D$ */ +/* git commit: $Format:%H$ */ +/* commit time: $Format:%ai$ */ diff --git a/libtommath/bn_mp_tc_div_2d.c b/libtommath/bn_mp_tc_div_2d.c new file mode 100644 index 0000000..ea190c3 --- /dev/null +++ b/libtommath/bn_mp_tc_div_2d.c @@ -0,0 +1,36 @@ +#include "tommath_private.h" +#ifdef BN_MP_TC_DIV_2D_C +/* LibTomMath, multiple-precision integer library -- Tom St Denis + * + * LibTomMath is a library that provides multiple-precision + * integer arithmetic as well as number theoretic functionality. + * + * The library was designed directly after the MPI library by + * Michael Fromberger but has been written from scratch with + * additional optimizations in place. + * + * The library is free for all purposes without any express + * guarantee it works. + */ + +/* two complement right shift */ +int mp_tc_div_2d(const mp_int *a, int b, mp_int *c) +{ + int res; + if (mp_isneg(a) == MP_NO) { + return mp_div_2d(a, b, c, NULL); + } + + res = mp_add_d(a, 1uL, c); + if (res != MP_OKAY) { + return res; + } + + res = mp_div_2d(c, b, c, NULL); + return (res == MP_OKAY) ? mp_sub_d(c, 1uL, c) : res; +} +#endif + +/* ref: $Format:%D$ */ +/* git commit: $Format:%H$ */ +/* commit time: $Format:%ai$ */ diff --git a/libtommath/bn_mp_tc_or.c b/libtommath/bn_mp_tc_or.c new file mode 100644 index 0000000..91b6b40 --- /dev/null +++ b/libtommath/bn_mp_tc_or.c @@ -0,0 +1,89 @@ +#include "tommath_private.h" +#ifdef BN_MP_TC_OR_C +/* LibTomMath, multiple-precision integer library -- Tom St Denis + * + * LibTomMath is a library that provides multiple-precision + * integer arithmetic as well as number theoretic functionality. + * + * The library was designed directly after the MPI library by + * Michael Fromberger but has been written from scratch with + * additional optimizations in place. + * + * The library is free for all purposes without any express + * guarantee it works. + */ + +/* two complement or */ +int mp_tc_or(const mp_int *a, const mp_int *b, mp_int *c) +{ + int res = MP_OKAY, bits; + int as = mp_isneg(a), bs = mp_isneg(b); + mp_int *mx = NULL, _mx, acpy, bcpy; + + if ((as != MP_NO) || (bs != MP_NO)) { + bits = MAX(mp_count_bits(a), mp_count_bits(b)); + res = mp_init_set_int(&_mx, 1uL); + if (res != MP_OKAY) { + goto end; + } + + mx = &_mx; + res = mp_mul_2d(mx, bits + 1, mx); + if (res != MP_OKAY) { + goto end; + } + + if (as != MP_NO) { + res = mp_init(&acpy); + if (res != MP_OKAY) { + goto end; + } + + res = mp_add(mx, a, &acpy); + if (res != MP_OKAY) { + mp_clear(&acpy); + goto end; + } + a = &acpy; + } + if (bs != MP_NO) { + res = mp_init(&bcpy); + if (res != MP_OKAY) { + goto end; + } + + res = mp_add(mx, b, &bcpy); + if (res != MP_OKAY) { + mp_clear(&bcpy); + goto end; + } + b = &bcpy; + } + } + + res = mp_or(a, b, c); + + if (((as != MP_NO) || (bs != MP_NO)) && (res == MP_OKAY)) { + res = mp_sub(c, mx, c); + } + +end: + if (a == &acpy) { + mp_clear(&acpy); + } + + if (b == &bcpy) { + mp_clear(&bcpy); + } + + if (mx == &_mx) { + mp_clear(mx); + } + + return res; +} +#endif + +/* ref: $Format:%D$ */ +/* git commit: $Format:%H$ */ +/* commit time: $Format:%ai$ */ diff --git a/libtommath/bn_mp_tc_xor.c b/libtommath/bn_mp_tc_xor.c new file mode 100644 index 0000000..50fb12d --- /dev/null +++ b/libtommath/bn_mp_tc_xor.c @@ -0,0 +1,89 @@ +#include "tommath_private.h" +#ifdef BN_MP_TC_XOR_C +/* LibTomMath, multiple-precision integer library -- Tom St Denis + * + * LibTomMath is a library that provides multiple-precision + * integer arithmetic as well as number theoretic functionality. + * + * The library was designed directly after the MPI library by + * Michael Fromberger but has been written from scratch with + * additional optimizations in place. + * + * The library is free for all purposes without any express + * guarantee it works. + */ + +/* two complement xor */ +int mp_tc_xor(const mp_int *a, const mp_int *b, mp_int *c) +{ + int res = MP_OKAY, bits; + int as = mp_isneg(a), bs = mp_isneg(b); + mp_int *mx = NULL, _mx, acpy, bcpy; + + if ((as != MP_NO) || (bs != MP_NO)) { + bits = MAX(mp_count_bits(a), mp_count_bits(b)); + res = mp_init_set_int(&_mx, 1uL); + if (res != MP_OKAY) { + goto end; + } + + mx = &_mx; + res = mp_mul_2d(mx, bits + 1, mx); + if (res != MP_OKAY) { + goto end; + } + + if (as != MP_NO) { + res = mp_init(&acpy); + if (res != MP_OKAY) { + goto end; + } + + res = mp_add(mx, a, &acpy); + if (res != MP_OKAY) { + mp_clear(&acpy); + goto end; + } + a = &acpy; + } + if (bs != MP_NO) { + res = mp_init(&bcpy); + if (res != MP_OKAY) { + goto end; + } + + res = mp_add(mx, b, &bcpy); + if (res != MP_OKAY) { + mp_clear(&bcpy); + goto end; + } + b = &bcpy; + } + } + + res = mp_xor(a, b, c); + + if ((as != bs) && (res == MP_OKAY)) { + res = mp_sub(c, mx, c); + } + +end: + if (a == &acpy) { + mp_clear(&acpy); + } + + if (b == &bcpy) { + mp_clear(&bcpy); + } + + if (mx == &_mx) { + mp_clear(mx); + } + + return res; +} +#endif + +/* ref: $Format:%D$ */ +/* git commit: $Format:%H$ */ +/* commit time: $Format:%ai$ */ diff --git a/libtommath/bn_mp_to_signed_bin.c b/libtommath/bn_mp_to_signed_bin.c index 4d4be88..22a938e 100644 --- a/libtommath/bn_mp_to_signed_bin.c +++ b/libtommath/bn_mp_to_signed_bin.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_TO_SIGNED_BIN_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* store in signed [big endian] format */ diff --git a/libtommath/bn_mp_to_signed_bin_n.c b/libtommath/bn_mp_to_signed_bin_n.c index f1d7c8b..417a380 100644 --- a/libtommath/bn_mp_to_signed_bin_n.c +++ b/libtommath/bn_mp_to_signed_bin_n.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_TO_SIGNED_BIN_N_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* store in signed [big endian] format */ diff --git a/libtommath/bn_mp_to_unsigned_bin.c b/libtommath/bn_mp_to_unsigned_bin.c index a53f711..aa719ae 100644 --- a/libtommath/bn_mp_to_unsigned_bin.c +++ b/libtommath/bn_mp_to_unsigned_bin.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_TO_UNSIGNED_BIN_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* store in unsigned [big endian] format */ diff --git a/libtommath/bn_mp_to_unsigned_bin_n.c b/libtommath/bn_mp_to_unsigned_bin_n.c index e7d303c..43676e8 100644 --- a/libtommath/bn_mp_to_unsigned_bin_n.c +++ b/libtommath/bn_mp_to_unsigned_bin_n.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_TO_UNSIGNED_BIN_N_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* store in unsigned [big endian] format */ diff --git a/libtommath/bn_mp_toom_mul.c b/libtommath/bn_mp_toom_mul.c index 00b6bfb..ff7df02 100644 --- a/libtommath/bn_mp_toom_mul.c +++ b/libtommath/bn_mp_toom_mul.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_TOOM_MUL_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* multiplication using the Toom-Cook 3-way algorithm @@ -39,126 +37,126 @@ int mp_toom_mul(const mp_int *a, const mp_int *b, mp_int *c) /* a = a2 * B**2 + a1 * B + a0 */ if ((res = mp_mod_2d(a, DIGIT_BIT * B, &a0)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_copy(a, &a1)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } mp_rshd(&a1, B); if ((res = mp_mod_2d(&a1, DIGIT_BIT * B, &a1)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_copy(a, &a2)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } mp_rshd(&a2, B*2); /* b = b2 * B**2 + b1 * B + b0 */ if ((res = mp_mod_2d(b, DIGIT_BIT * B, &b0)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_copy(b, &b1)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } mp_rshd(&b1, B); (void)mp_mod_2d(&b1, DIGIT_BIT * B, &b1); if ((res = mp_copy(b, &b2)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } mp_rshd(&b2, B*2); /* w0 = a0*b0 */ if ((res = mp_mul(&a0, &b0, &w0)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } /* w4 = a2 * b2 */ if ((res = mp_mul(&a2, &b2, &w4)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } /* w1 = (a2 + 2(a1 + 2a0))(b2 + 2(b1 + 2b0)) */ if ((res = mp_mul_2(&a0, &tmp1)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_add(&tmp1, &a1, &tmp1)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_mul_2(&tmp1, &tmp1)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_add(&tmp1, &a2, &tmp1)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_mul_2(&b0, &tmp2)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_add(&tmp2, &b1, &tmp2)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_mul_2(&tmp2, &tmp2)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_add(&tmp2, &b2, &tmp2)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_mul(&tmp1, &tmp2, &w1)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } /* w3 = (a0 + 2(a1 + 2a2))(b0 + 2(b1 + 2b2)) */ if ((res = mp_mul_2(&a2, &tmp1)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_add(&tmp1, &a1, &tmp1)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_mul_2(&tmp1, &tmp1)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_add(&tmp1, &a0, &tmp1)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_mul_2(&b2, &tmp2)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_add(&tmp2, &b1, &tmp2)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_mul_2(&tmp2, &tmp2)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_add(&tmp2, &b0, &tmp2)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_mul(&tmp1, &tmp2, &w3)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } /* w2 = (a2 + a1 + a0)(b2 + b1 + b0) */ if ((res = mp_add(&a2, &a1, &tmp1)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_add(&tmp1, &a0, &tmp1)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_add(&b2, &b1, &tmp2)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_add(&tmp2, &b0, &tmp2)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_mul(&tmp1, &tmp2, &w2)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } /* now solve the matrix @@ -175,104 +173,104 @@ int mp_toom_mul(const mp_int *a, const mp_int *b, mp_int *c) /* r1 - r4 */ if ((res = mp_sub(&w1, &w4, &w1)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } /* r3 - r0 */ if ((res = mp_sub(&w3, &w0, &w3)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } /* r1/2 */ if ((res = mp_div_2(&w1, &w1)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } /* r3/2 */ if ((res = mp_div_2(&w3, &w3)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } /* r2 - r0 - r4 */ if ((res = mp_sub(&w2, &w0, &w2)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_sub(&w2, &w4, &w2)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } /* r1 - r2 */ if ((res = mp_sub(&w1, &w2, &w1)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } /* r3 - r2 */ if ((res = mp_sub(&w3, &w2, &w3)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } /* r1 - 8r0 */ if ((res = mp_mul_2d(&w0, 3, &tmp1)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_sub(&w1, &tmp1, &w1)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } /* r3 - 8r4 */ if ((res = mp_mul_2d(&w4, 3, &tmp1)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_sub(&w3, &tmp1, &w3)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } /* 3r2 - r1 - r3 */ if ((res = mp_mul_d(&w2, 3uL, &w2)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_sub(&w2, &w1, &w2)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_sub(&w2, &w3, &w2)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } /* r1 - r2 */ if ((res = mp_sub(&w1, &w2, &w1)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } /* r3 - r2 */ if ((res = mp_sub(&w3, &w2, &w3)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } /* r1/3 */ if ((res = mp_div_3(&w1, &w1, NULL)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } /* r3/3 */ if ((res = mp_div_3(&w3, &w3, NULL)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } /* at this point shift W[n] by B*n */ if ((res = mp_lshd(&w1, 1*B)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_lshd(&w2, 2*B)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_lshd(&w3, 3*B)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_lshd(&w4, 4*B)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_add(&w0, &w1, c)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_add(&w2, &w3, &tmp1)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_add(&w4, &tmp1, &tmp1)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_add(&tmp1, c, c)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } -ERR: +LBL_ERR: mp_clear_multi(&w0, &w1, &w2, &w3, &w4, &a0, &a1, &a2, &b0, &b1, &b2, &tmp1, &tmp2, NULL); diff --git a/libtommath/bn_mp_toom_sqr.c b/libtommath/bn_mp_toom_sqr.c index 183de20..edc89cd 100644 --- a/libtommath/bn_mp_toom_sqr.c +++ b/libtommath/bn_mp_toom_sqr.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_TOOM_SQR_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* squaring using Toom-Cook 3-way algorithm */ @@ -31,78 +29,78 @@ int mp_toom_sqr(const mp_int *a, mp_int *b) /* a = a2 * B**2 + a1 * B + a0 */ if ((res = mp_mod_2d(a, DIGIT_BIT * B, &a0)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_copy(a, &a1)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } mp_rshd(&a1, B); if ((res = mp_mod_2d(&a1, DIGIT_BIT * B, &a1)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_copy(a, &a2)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } mp_rshd(&a2, B*2); /* w0 = a0*a0 */ if ((res = mp_sqr(&a0, &w0)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } /* w4 = a2 * a2 */ if ((res = mp_sqr(&a2, &w4)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } /* w1 = (a2 + 2(a1 + 2a0))**2 */ if ((res = mp_mul_2(&a0, &tmp1)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_add(&tmp1, &a1, &tmp1)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_mul_2(&tmp1, &tmp1)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_add(&tmp1, &a2, &tmp1)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_sqr(&tmp1, &w1)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } /* w3 = (a0 + 2(a1 + 2a2))**2 */ if ((res = mp_mul_2(&a2, &tmp1)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_add(&tmp1, &a1, &tmp1)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_mul_2(&tmp1, &tmp1)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_add(&tmp1, &a0, &tmp1)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_sqr(&tmp1, &w3)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } /* w2 = (a2 + a1 + a0)**2 */ if ((res = mp_add(&a2, &a1, &tmp1)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_add(&tmp1, &a0, &tmp1)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_sqr(&tmp1, &w2)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } /* now solve the matrix @@ -118,104 +116,104 @@ int mp_toom_sqr(const mp_int *a, mp_int *b) /* r1 - r4 */ if ((res = mp_sub(&w1, &w4, &w1)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } /* r3 - r0 */ if ((res = mp_sub(&w3, &w0, &w3)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } /* r1/2 */ if ((res = mp_div_2(&w1, &w1)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } /* r3/2 */ if ((res = mp_div_2(&w3, &w3)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } /* r2 - r0 - r4 */ if ((res = mp_sub(&w2, &w0, &w2)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_sub(&w2, &w4, &w2)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } /* r1 - r2 */ if ((res = mp_sub(&w1, &w2, &w1)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } /* r3 - r2 */ if ((res = mp_sub(&w3, &w2, &w3)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } /* r1 - 8r0 */ if ((res = mp_mul_2d(&w0, 3, &tmp1)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_sub(&w1, &tmp1, &w1)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } /* r3 - 8r4 */ if ((res = mp_mul_2d(&w4, 3, &tmp1)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_sub(&w3, &tmp1, &w3)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } /* 3r2 - r1 - r3 */ if ((res = mp_mul_d(&w2, 3uL, &w2)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_sub(&w2, &w1, &w2)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_sub(&w2, &w3, &w2)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } /* r1 - r2 */ if ((res = mp_sub(&w1, &w2, &w1)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } /* r3 - r2 */ if ((res = mp_sub(&w3, &w2, &w3)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } /* r1/3 */ if ((res = mp_div_3(&w1, &w1, NULL)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } /* r3/3 */ if ((res = mp_div_3(&w3, &w3, NULL)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } /* at this point shift W[n] by B*n */ if ((res = mp_lshd(&w1, 1*B)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_lshd(&w2, 2*B)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_lshd(&w3, 3*B)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_lshd(&w4, 4*B)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_add(&w0, &w1, b)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_add(&w2, &w3, &tmp1)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_add(&w4, &tmp1, &tmp1)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } if ((res = mp_add(&tmp1, b, b)) != MP_OKAY) { - goto ERR; + goto LBL_ERR; } -ERR: +LBL_ERR: mp_clear_multi(&w0, &w1, &w2, &w3, &w4, &a0, &a1, &a2, &tmp1, NULL); return res; } diff --git a/libtommath/bn_mp_toradix.c b/libtommath/bn_mp_toradix.c index 7dd6e4f..8c05e75 100644 --- a/libtommath/bn_mp_toradix.c +++ b/libtommath/bn_mp_toradix.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_TORADIX_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* stores a bignum as a ASCII string in a given radix (2..64) */ diff --git a/libtommath/bn_mp_toradix_n.c b/libtommath/bn_mp_toradix_n.c index ef885fc..27cb401 100644 --- a/libtommath/bn_mp_toradix_n.c +++ b/libtommath/bn_mp_toradix_n.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_TORADIX_N_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* stores a bignum as a ASCII string in a given radix (2..64) diff --git a/libtommath/bn_mp_unsigned_bin_size.c b/libtommath/bn_mp_unsigned_bin_size.c index 2b9ce8a..bc9b853 100644 --- a/libtommath/bn_mp_unsigned_bin_size.c +++ b/libtommath/bn_mp_unsigned_bin_size.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_UNSIGNED_BIN_SIZE_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* get the size for an unsigned equivalent */ diff --git a/libtommath/bn_mp_xor.c b/libtommath/bn_mp_xor.c index 9ebc53a..b502eb0 100644 --- a/libtommath/bn_mp_xor.c +++ b/libtommath/bn_mp_xor.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_XOR_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* XOR two ints together */ diff --git a/libtommath/bn_mp_zero.c b/libtommath/bn_mp_zero.c index 08aac2a..78f165b 100644 --- a/libtommath/bn_mp_zero.c +++ b/libtommath/bn_mp_zero.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_MP_ZERO_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* set to zero */ diff --git a/libtommath/bn_prime_tab.c b/libtommath/bn_prime_tab.c index bcd23ed..f23afcb 100644 --- a/libtommath/bn_prime_tab.c +++ b/libtommath/bn_prime_tab.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_PRIME_TAB_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ const mp_digit ltm_prime_tab[] = { diff --git a/libtommath/bn_reverse.c b/libtommath/bn_reverse.c index 71e3d03..5b49172 100644 --- a/libtommath/bn_reverse.c +++ b/libtommath/bn_reverse.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_REVERSE_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* reverse an array, used for radix code */ diff --git a/libtommath/bn_s_mp_add.c b/libtommath/bn_s_mp_add.c index 3f908ef..8a3bc82 100644 --- a/libtommath/bn_s_mp_add.c +++ b/libtommath/bn_s_mp_add.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_S_MP_ADD_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* low level addition, based on HAC pp.594, Algorithm 14.7 */ diff --git a/libtommath/bn_s_mp_exptmod.c b/libtommath/bn_s_mp_exptmod.c index a954757..f84da21 100644 --- a/libtommath/bn_s_mp_exptmod.c +++ b/libtommath/bn_s_mp_exptmod.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_S_MP_EXPTMOD_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ #ifdef MP_LOW_MEM diff --git a/libtommath/bn_s_mp_mul_digs.c b/libtommath/bn_s_mp_mul_digs.c index 214ae31..442c803 100644 --- a/libtommath/bn_s_mp_mul_digs.c +++ b/libtommath/bn_s_mp_mul_digs.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_S_MP_MUL_DIGS_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* multiplies |a| * |b| and only computes upto digs digits of result diff --git a/libtommath/bn_s_mp_mul_high_digs.c b/libtommath/bn_s_mp_mul_high_digs.c index 3c0418a..e6efd4e 100644 --- a/libtommath/bn_s_mp_mul_high_digs.c +++ b/libtommath/bn_s_mp_mul_high_digs.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_S_MP_MUL_HIGH_DIGS_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* multiplies |a| * |b| and does not compute the lower digs digits diff --git a/libtommath/bn_s_mp_sqr.c b/libtommath/bn_s_mp_sqr.c index 71bbccd..4cab045 100644 --- a/libtommath/bn_s_mp_sqr.c +++ b/libtommath/bn_s_mp_sqr.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_S_MP_SQR_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* low level squaring, b = a*a, HAC pp.596-597, Algorithm 14.16 */ diff --git a/libtommath/bn_s_mp_sub.c b/libtommath/bn_s_mp_sub.c index c8472af..fbce7ca 100644 --- a/libtommath/bn_s_mp_sub.c +++ b/libtommath/bn_s_mp_sub.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BN_S_MP_SUB_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* low level subtraction (assumes |a| > |b|), HAC pp.595 Algorithm 14.9 */ diff --git a/libtommath/bncore.c b/libtommath/bncore.c index cfd19f0..916712d 100644 --- a/libtommath/bncore.c +++ b/libtommath/bncore.c @@ -1,4 +1,4 @@ -#include +#include "tommath_private.h" #ifdef BNCORE_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -11,8 +11,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ /* Known optimal configurations diff --git a/libtommath/callgraph.txt b/libtommath/callgraph.txt index 52007c0..6cc4e45 100644 --- a/libtommath/callgraph.txt +++ b/libtommath/callgraph.txt @@ -237,6 +237,17 @@ BN_MP_CMP_MAG_C BN_MP_CNT_LSB_C +BN_MP_COMPLEMENT_C ++--->BN_MP_NEG_C +| +--->BN_MP_COPY_C +| | +--->BN_MP_GROW_C ++--->BN_MP_SUB_D_C +| +--->BN_MP_GROW_C +| +--->BN_MP_ADD_D_C +| | +--->BN_MP_CLAMP_C +| +--->BN_MP_CLAMP_C + + BN_MP_COPY_C +--->BN_MP_GROW_C @@ -12382,6 +12393,172 @@ BN_MP_SUB_D_C +--->BN_MP_CLAMP_C +BN_MP_TC_AND_C ++--->BN_MP_COUNT_BITS_C ++--->BN_MP_INIT_SET_INT_C +| +--->BN_MP_INIT_C +| +--->BN_MP_SET_INT_C +| | +--->BN_MP_ZERO_C +| | +--->BN_MP_MUL_2D_C +| | | +--->BN_MP_COPY_C +| | | | +--->BN_MP_GROW_C +| | | +--->BN_MP_GROW_C +| | | +--->BN_MP_LSHD_C +| | | | +--->BN_MP_RSHD_C +| | | +--->BN_MP_CLAMP_C +| | +--->BN_MP_CLAMP_C ++--->BN_MP_MUL_2D_C +| +--->BN_MP_COPY_C +| | +--->BN_MP_GROW_C +| +--->BN_MP_GROW_C +| +--->BN_MP_LSHD_C +| | +--->BN_MP_RSHD_C +| | | +--->BN_MP_ZERO_C +| +--->BN_MP_CLAMP_C ++--->BN_MP_INIT_C ++--->BN_MP_ADD_C +| +--->BN_S_MP_ADD_C +| | +--->BN_MP_GROW_C +| | +--->BN_MP_CLAMP_C +| +--->BN_MP_CMP_MAG_C +| +--->BN_S_MP_SUB_C +| | +--->BN_MP_GROW_C +| | +--->BN_MP_CLAMP_C ++--->BN_MP_CLEAR_C ++--->BN_MP_AND_C +| +--->BN_MP_INIT_COPY_C +| | +--->BN_MP_INIT_SIZE_C +| | +--->BN_MP_COPY_C +| | | +--->BN_MP_GROW_C +| +--->BN_MP_CLAMP_C +| +--->BN_MP_EXCH_C ++--->BN_MP_SUB_C +| +--->BN_S_MP_ADD_C +| | +--->BN_MP_GROW_C +| | +--->BN_MP_CLAMP_C +| +--->BN_MP_CMP_MAG_C +| +--->BN_S_MP_SUB_C +| | +--->BN_MP_GROW_C +| | +--->BN_MP_CLAMP_C + + +BN_MP_TC_DIV_2D_C ++--->BN_MP_DIV_2D_C +| +--->BN_MP_COPY_C +| | +--->BN_MP_GROW_C +| +--->BN_MP_ZERO_C +| +--->BN_MP_MOD_2D_C +| | +--->BN_MP_CLAMP_C +| +--->BN_MP_RSHD_C +| +--->BN_MP_CLAMP_C ++--->BN_MP_ADD_D_C +| +--->BN_MP_GROW_C +| +--->BN_MP_SUB_D_C +| | +--->BN_MP_CLAMP_C +| +--->BN_MP_CLAMP_C ++--->BN_MP_SUB_D_C +| +--->BN_MP_GROW_C +| +--->BN_MP_CLAMP_C + + +BN_MP_TC_OR_C ++--->BN_MP_COUNT_BITS_C ++--->BN_MP_INIT_SET_INT_C +| +--->BN_MP_INIT_C +| +--->BN_MP_SET_INT_C +| | +--->BN_MP_ZERO_C +| | +--->BN_MP_MUL_2D_C +| | | +--->BN_MP_COPY_C +| | | | +--->BN_MP_GROW_C +| | | +--->BN_MP_GROW_C +| | | +--->BN_MP_LSHD_C +| | | | +--->BN_MP_RSHD_C +| | | +--->BN_MP_CLAMP_C +| | +--->BN_MP_CLAMP_C ++--->BN_MP_MUL_2D_C +| +--->BN_MP_COPY_C +| | +--->BN_MP_GROW_C +| +--->BN_MP_GROW_C +| +--->BN_MP_LSHD_C +| | +--->BN_MP_RSHD_C +| | | +--->BN_MP_ZERO_C +| +--->BN_MP_CLAMP_C ++--->BN_MP_INIT_C ++--->BN_MP_ADD_C +| +--->BN_S_MP_ADD_C +| | +--->BN_MP_GROW_C +| | +--->BN_MP_CLAMP_C +| +--->BN_MP_CMP_MAG_C +| +--->BN_S_MP_SUB_C +| | +--->BN_MP_GROW_C +| | +--->BN_MP_CLAMP_C ++--->BN_MP_CLEAR_C ++--->BN_MP_OR_C +| +--->BN_MP_INIT_COPY_C +| | +--->BN_MP_INIT_SIZE_C +| | +--->BN_MP_COPY_C +| | | +--->BN_MP_GROW_C +| +--->BN_MP_CLAMP_C +| +--->BN_MP_EXCH_C ++--->BN_MP_SUB_C +| +--->BN_S_MP_ADD_C +| | +--->BN_MP_GROW_C +| | +--->BN_MP_CLAMP_C +| +--->BN_MP_CMP_MAG_C +| +--->BN_S_MP_SUB_C +| | +--->BN_MP_GROW_C +| | +--->BN_MP_CLAMP_C + + +BN_MP_TC_XOR_C ++--->BN_MP_COUNT_BITS_C ++--->BN_MP_INIT_SET_INT_C +| +--->BN_MP_INIT_C +| +--->BN_MP_SET_INT_C +| | +--->BN_MP_ZERO_C +| | +--->BN_MP_MUL_2D_C +| | | +--->BN_MP_COPY_C +| | | | +--->BN_MP_GROW_C +| | | +--->BN_MP_GROW_C +| | | +--->BN_MP_LSHD_C +| | | | +--->BN_MP_RSHD_C +| | | +--->BN_MP_CLAMP_C +| | +--->BN_MP_CLAMP_C ++--->BN_MP_MUL_2D_C +| +--->BN_MP_COPY_C +| | +--->BN_MP_GROW_C +| +--->BN_MP_GROW_C +| +--->BN_MP_LSHD_C +| | +--->BN_MP_RSHD_C +| | | +--->BN_MP_ZERO_C +| +--->BN_MP_CLAMP_C ++--->BN_MP_INIT_C ++--->BN_MP_ADD_C +| +--->BN_S_MP_ADD_C +| | +--->BN_MP_GROW_C +| | +--->BN_MP_CLAMP_C +| +--->BN_MP_CMP_MAG_C +| +--->BN_S_MP_SUB_C +| | +--->BN_MP_GROW_C +| | +--->BN_MP_CLAMP_C ++--->BN_MP_CLEAR_C ++--->BN_MP_XOR_C +| +--->BN_MP_INIT_COPY_C +| | +--->BN_MP_INIT_SIZE_C +| | +--->BN_MP_COPY_C +| | | +--->BN_MP_GROW_C +| +--->BN_MP_CLAMP_C +| +--->BN_MP_EXCH_C ++--->BN_MP_SUB_C +| +--->BN_S_MP_ADD_C +| | +--->BN_MP_GROW_C +| | +--->BN_MP_CLAMP_C +| +--->BN_MP_CMP_MAG_C +| +--->BN_S_MP_SUB_C +| | +--->BN_MP_GROW_C +| | +--->BN_MP_CLAMP_C + + BN_MP_TOOM_MUL_C +--->BN_MP_INIT_MULTI_C | +--->BN_MP_INIT_C diff --git a/libtommath/makefile b/libtommath/makefile index 5eddae4..7b8f422 100644 --- a/libtommath/makefile +++ b/libtommath/makefile @@ -29,27 +29,27 @@ LCOV_ARGS=--directory . OBJECTS=bncore.o bn_error.o bn_fast_mp_invmod.o bn_fast_mp_montgomery_reduce.o bn_fast_s_mp_mul_digs.o \ bn_fast_s_mp_mul_high_digs.o bn_fast_s_mp_sqr.o bn_mp_2expt.o bn_mp_abs.o bn_mp_add.o bn_mp_add_d.o \ bn_mp_addmod.o bn_mp_and.o bn_mp_clamp.o bn_mp_clear.o bn_mp_clear_multi.o bn_mp_cmp.o bn_mp_cmp_d.o \ -bn_mp_cmp_mag.o bn_mp_cnt_lsb.o bn_mp_copy.o bn_mp_count_bits.o bn_mp_div_2.o bn_mp_div_2d.o bn_mp_div_3.o \ -bn_mp_div.o bn_mp_div_d.o bn_mp_dr_is_modulus.o bn_mp_dr_reduce.o bn_mp_dr_setup.o bn_mp_exch.o \ -bn_mp_export.o bn_mp_expt_d.o bn_mp_expt_d_ex.o bn_mp_exptmod.o bn_mp_exptmod_fast.o bn_mp_exteuclid.o \ -bn_mp_fread.o bn_mp_fwrite.o bn_mp_gcd.o bn_mp_get_int.o bn_mp_get_long.o bn_mp_get_long_long.o \ -bn_mp_grow.o bn_mp_import.o bn_mp_init.o bn_mp_init_copy.o bn_mp_init_multi.o bn_mp_init_set.o \ -bn_mp_init_set_int.o bn_mp_init_size.o bn_mp_invmod.o bn_mp_invmod_slow.o bn_mp_is_square.o \ -bn_mp_jacobi.o bn_mp_karatsuba_mul.o bn_mp_karatsuba_sqr.o bn_mp_lcm.o bn_mp_lshd.o bn_mp_mod_2d.o \ -bn_mp_mod.o bn_mp_mod_d.o bn_mp_montgomery_calc_normalization.o bn_mp_montgomery_reduce.o \ -bn_mp_montgomery_setup.o bn_mp_mul_2.o bn_mp_mul_2d.o bn_mp_mul.o bn_mp_mul_d.o bn_mp_mulmod.o bn_mp_neg.o \ -bn_mp_n_root.o bn_mp_n_root_ex.o bn_mp_or.o bn_mp_prime_fermat.o bn_mp_prime_is_divisible.o \ -bn_mp_prime_is_prime.o bn_mp_prime_miller_rabin.o bn_mp_prime_next_prime.o \ +bn_mp_cmp_mag.o bn_mp_cnt_lsb.o bn_mp_complement.o bn_mp_copy.o bn_mp_count_bits.o bn_mp_div_2.o \ +bn_mp_div_2d.o bn_mp_div_3.o bn_mp_div.o bn_mp_div_d.o bn_mp_dr_is_modulus.o bn_mp_dr_reduce.o \ +bn_mp_dr_setup.o bn_mp_exch.o bn_mp_export.o bn_mp_expt_d.o bn_mp_expt_d_ex.o bn_mp_exptmod.o \ +bn_mp_exptmod_fast.o bn_mp_exteuclid.o bn_mp_fread.o bn_mp_fwrite.o bn_mp_gcd.o bn_mp_get_int.o \ +bn_mp_get_long.o bn_mp_get_long_long.o bn_mp_grow.o bn_mp_import.o bn_mp_init.o bn_mp_init_copy.o \ +bn_mp_init_multi.o bn_mp_init_set.o bn_mp_init_set_int.o bn_mp_init_size.o bn_mp_invmod.o \ +bn_mp_invmod_slow.o bn_mp_is_square.o bn_mp_jacobi.o bn_mp_karatsuba_mul.o bn_mp_karatsuba_sqr.o \ +bn_mp_lcm.o bn_mp_lshd.o bn_mp_mod_2d.o bn_mp_mod.o bn_mp_mod_d.o bn_mp_montgomery_calc_normalization.o \ +bn_mp_montgomery_reduce.o bn_mp_montgomery_setup.o bn_mp_mul_2.o bn_mp_mul_2d.o bn_mp_mul.o bn_mp_mul_d.o \ +bn_mp_mulmod.o bn_mp_neg.o bn_mp_n_root.o bn_mp_n_root_ex.o bn_mp_or.o bn_mp_prime_fermat.o \ +bn_mp_prime_is_divisible.o bn_mp_prime_is_prime.o bn_mp_prime_miller_rabin.o bn_mp_prime_next_prime.o \ bn_mp_prime_rabin_miller_trials.o bn_mp_prime_random_ex.o bn_mp_radix_size.o bn_mp_radix_smap.o \ bn_mp_rand.o bn_mp_read_radix.o bn_mp_read_signed_bin.o bn_mp_read_unsigned_bin.o bn_mp_reduce_2k.o \ bn_mp_reduce_2k_l.o bn_mp_reduce_2k_setup.o bn_mp_reduce_2k_setup_l.o bn_mp_reduce.o \ bn_mp_reduce_is_2k.o bn_mp_reduce_is_2k_l.o bn_mp_reduce_setup.o bn_mp_rshd.o bn_mp_set.o bn_mp_set_int.o \ bn_mp_set_long.o bn_mp_set_long_long.o bn_mp_shrink.o bn_mp_signed_bin_size.o bn_mp_sqr.o bn_mp_sqrmod.o \ -bn_mp_sqrt.o bn_mp_sqrtmod_prime.o bn_mp_sub.o bn_mp_sub_d.o bn_mp_submod.o bn_mp_toom_mul.o \ -bn_mp_toom_sqr.o bn_mp_toradix.o bn_mp_toradix_n.o bn_mp_to_signed_bin.o bn_mp_to_signed_bin_n.o \ -bn_mp_to_unsigned_bin.o bn_mp_to_unsigned_bin_n.o bn_mp_unsigned_bin_size.o bn_mp_xor.o bn_mp_zero.o \ -bn_prime_tab.o bn_reverse.o bn_s_mp_add.o bn_s_mp_exptmod.o bn_s_mp_mul_digs.o bn_s_mp_mul_high_digs.o \ -bn_s_mp_sqr.o bn_s_mp_sub.o +bn_mp_sqrt.o bn_mp_sqrtmod_prime.o bn_mp_sub.o bn_mp_sub_d.o bn_mp_submod.o bn_mp_tc_and.o \ +bn_mp_tc_div_2d.o bn_mp_tc_or.o bn_mp_tc_xor.o bn_mp_toom_mul.o bn_mp_toom_sqr.o bn_mp_toradix.o \ +bn_mp_toradix_n.o bn_mp_to_signed_bin.o bn_mp_to_signed_bin_n.o bn_mp_to_unsigned_bin.o \ +bn_mp_to_unsigned_bin_n.o bn_mp_unsigned_bin_size.o bn_mp_xor.o bn_mp_zero.o bn_prime_tab.o bn_reverse.o \ +bn_s_mp_add.o bn_s_mp_exptmod.o bn_s_mp_mul_digs.o bn_s_mp_mul_high_digs.o bn_s_mp_sqr.o bn_s_mp_sub.o #END_INS @@ -67,17 +67,17 @@ $(LIBNAME): $(OBJECTS) # So far I've seen improvements in the MP math profiled: make CFLAGS="$(CFLAGS) -fprofile-arcs -DTESTING" timing - ./ltmtest - rm -f *.a *.o ltmtest + ./timing + rm -f *.a *.o timing make CFLAGS="$(CFLAGS) -fbranch-probabilities" #make a single object profiled library profiled_single: perl gen.pl $(CC) $(CFLAGS) -fprofile-arcs -DTESTING -c mpi.c -o mpi.o - $(CC) $(CFLAGS) -DTESTING -DTIMER demo/timing.c mpi.o -lgcov -o ltmtest - ./ltmtest - rm -f *.o ltmtest + $(CC) $(CFLAGS) -DTESTING -DTIMER demo/timing.c mpi.o -lgcov -o timing + ./timing + rm -f *.o timing $(CC) $(CFLAGS) -fbranch-probabilities -DTESTING -c mpi.c -o mpi.o $(AR) $(ARFLAGS) $(LIBNAME) mpi.o ranlib $(LIBNAME) @@ -102,8 +102,8 @@ test_standalone: $(LIBNAME) demo/demo.o mtest: cd mtest ; $(CC) $(CFLAGS) -O0 mtest.c $(LFLAGS) -o mtest -timing: $(LIBNAME) - $(CC) $(CFLAGS) -DTIMER demo/timing.c $(LIBNAME) $(LFLAGS) -o ltmtest +timing: $(LIBNAME) demo/timing.c + $(CC) $(CFLAGS) -DTIMER demo/timing.c $(LIBNAME) $(LFLAGS) -o timing # You have to create a file .coveralls.yml with the content "repo_token: " # in the base folder to be able to submit to coveralls @@ -118,11 +118,12 @@ pretty: .PHONY: pre_gen pre_gen: + mkdir -p pre_gen perl gen.pl sed -e 's/[[:blank:]]*$$//' mpi.c > pre_gen/mpi.c rm mpi.c -zipup: clean pre_gen new_file manual poster docs +zipup: clean astyle new_file manual poster docs @# Update the index, so diff-index won't fail in case the pdf has been created. @# As the pdf creation modifies the tex files, git sometimes detects the @# modified files, but misses that it's put back to its original version. @@ -131,8 +132,11 @@ zipup: clean pre_gen new_file manual poster docs rm -rf libtommath-$(VERSION) ltm-$(VERSION).* @# files/dirs excluded from "git archive" are defined in .gitattributes git archive --format=tar --prefix=libtommath-$(VERSION)/ HEAD | tar x + @echo 'fixme check' + -@(find libtommath-$(VERSION)/ -type f | xargs grep 'FIXM[E]') && echo '############## BEWARE: the "fixme" marker was found !!! ##############' || true mkdir -p libtommath-$(VERSION)/doc cp doc/bn.pdf doc/tommath.pdf doc/poster.pdf libtommath-$(VERSION)/doc/ + $(MAKE) -C libtommath-$(VERSION)/ pre_gen tar -c libtommath-$(VERSION)/ | xz -6e -c - > ltm-$(VERSION).tar.xz zip -9rq ltm-$(VERSION).zip libtommath-$(VERSION) rm -rf libtommath-$(VERSION) diff --git a/libtommath/makefile.bcc b/libtommath/makefile.bcc index a0cfd74..7a64695 100644 --- a/libtommath/makefile.bcc +++ b/libtommath/makefile.bcc @@ -11,27 +11,27 @@ CFLAGS = -c -O2 -I. OBJECTS=bncore.obj bn_error.obj bn_fast_mp_invmod.obj bn_fast_mp_montgomery_reduce.obj bn_fast_s_mp_mul_digs.obj \ bn_fast_s_mp_mul_high_digs.obj bn_fast_s_mp_sqr.obj bn_mp_2expt.obj bn_mp_abs.obj bn_mp_add.obj bn_mp_add_d.obj \ bn_mp_addmod.obj bn_mp_and.obj bn_mp_clamp.obj bn_mp_clear.obj bn_mp_clear_multi.obj bn_mp_cmp.obj bn_mp_cmp_d.obj \ -bn_mp_cmp_mag.obj bn_mp_cnt_lsb.obj bn_mp_copy.obj bn_mp_count_bits.obj bn_mp_div_2.obj bn_mp_div_2d.obj bn_mp_div_3.obj \ -bn_mp_div.obj bn_mp_div_d.obj bn_mp_dr_is_modulus.obj bn_mp_dr_reduce.obj bn_mp_dr_setup.obj bn_mp_exch.obj \ -bn_mp_export.obj bn_mp_expt_d.obj bn_mp_expt_d_ex.obj bn_mp_exptmod.obj bn_mp_exptmod_fast.obj bn_mp_exteuclid.obj \ -bn_mp_fread.obj bn_mp_fwrite.obj bn_mp_gcd.obj bn_mp_get_int.obj bn_mp_get_long.obj bn_mp_get_long_long.obj \ -bn_mp_grow.obj bn_mp_import.obj bn_mp_init.obj bn_mp_init_copy.obj bn_mp_init_multi.obj bn_mp_init_set.obj \ -bn_mp_init_set_int.obj bn_mp_init_size.obj bn_mp_invmod.obj bn_mp_invmod_slow.obj bn_mp_is_square.obj \ -bn_mp_jacobi.obj bn_mp_karatsuba_mul.obj bn_mp_karatsuba_sqr.obj bn_mp_lcm.obj bn_mp_lshd.obj bn_mp_mod_2d.obj \ -bn_mp_mod.obj bn_mp_mod_d.obj bn_mp_montgomery_calc_normalization.obj bn_mp_montgomery_reduce.obj \ -bn_mp_montgomery_setup.obj bn_mp_mul_2.obj bn_mp_mul_2d.obj bn_mp_mul.obj bn_mp_mul_d.obj bn_mp_mulmod.obj bn_mp_neg.obj \ -bn_mp_n_root.obj bn_mp_n_root_ex.obj bn_mp_or.obj bn_mp_prime_fermat.obj bn_mp_prime_is_divisible.obj \ -bn_mp_prime_is_prime.obj bn_mp_prime_miller_rabin.obj bn_mp_prime_next_prime.obj \ +bn_mp_cmp_mag.obj bn_mp_cnt_lsb.obj bn_mp_complement.obj bn_mp_copy.obj bn_mp_count_bits.obj bn_mp_div_2.obj \ +bn_mp_div_2d.obj bn_mp_div_3.obj bn_mp_div.obj bn_mp_div_d.obj bn_mp_dr_is_modulus.obj bn_mp_dr_reduce.obj \ +bn_mp_dr_setup.obj bn_mp_exch.obj bn_mp_export.obj bn_mp_expt_d.obj bn_mp_expt_d_ex.obj bn_mp_exptmod.obj \ +bn_mp_exptmod_fast.obj bn_mp_exteuclid.obj bn_mp_fread.obj bn_mp_fwrite.obj bn_mp_gcd.obj bn_mp_get_int.obj \ +bn_mp_get_long.obj bn_mp_get_long_long.obj bn_mp_grow.obj bn_mp_import.obj bn_mp_init.obj bn_mp_init_copy.obj \ +bn_mp_init_multi.obj bn_mp_init_set.obj bn_mp_init_set_int.obj bn_mp_init_size.obj bn_mp_invmod.obj \ +bn_mp_invmod_slow.obj bn_mp_is_square.obj bn_mp_jacobi.obj bn_mp_karatsuba_mul.obj bn_mp_karatsuba_sqr.obj \ +bn_mp_lcm.obj bn_mp_lshd.obj bn_mp_mod_2d.obj bn_mp_mod.obj bn_mp_mod_d.obj bn_mp_montgomery_calc_normalization.obj \ +bn_mp_montgomery_reduce.obj bn_mp_montgomery_setup.obj bn_mp_mul_2.obj bn_mp_mul_2d.obj bn_mp_mul.obj bn_mp_mul_d.obj \ +bn_mp_mulmod.obj bn_mp_neg.obj bn_mp_n_root.obj bn_mp_n_root_ex.obj bn_mp_or.obj bn_mp_prime_fermat.obj \ +bn_mp_prime_is_divisible.obj bn_mp_prime_is_prime.obj bn_mp_prime_miller_rabin.obj bn_mp_prime_next_prime.obj \ bn_mp_prime_rabin_miller_trials.obj bn_mp_prime_random_ex.obj bn_mp_radix_size.obj bn_mp_radix_smap.obj \ bn_mp_rand.obj bn_mp_read_radix.obj bn_mp_read_signed_bin.obj bn_mp_read_unsigned_bin.obj bn_mp_reduce_2k.obj \ bn_mp_reduce_2k_l.obj bn_mp_reduce_2k_setup.obj bn_mp_reduce_2k_setup_l.obj bn_mp_reduce.obj \ bn_mp_reduce_is_2k.obj bn_mp_reduce_is_2k_l.obj bn_mp_reduce_setup.obj bn_mp_rshd.obj bn_mp_set.obj bn_mp_set_int.obj \ bn_mp_set_long.obj bn_mp_set_long_long.obj bn_mp_shrink.obj bn_mp_signed_bin_size.obj bn_mp_sqr.obj bn_mp_sqrmod.obj \ -bn_mp_sqrt.obj bn_mp_sqrtmod_prime.obj bn_mp_sub.obj bn_mp_sub_d.obj bn_mp_submod.obj bn_mp_toom_mul.obj \ -bn_mp_toom_sqr.obj bn_mp_toradix.obj bn_mp_toradix_n.obj bn_mp_to_signed_bin.obj bn_mp_to_signed_bin_n.obj \ -bn_mp_to_unsigned_bin.obj bn_mp_to_unsigned_bin_n.obj bn_mp_unsigned_bin_size.obj bn_mp_xor.obj bn_mp_zero.obj \ -bn_prime_tab.obj bn_reverse.obj bn_s_mp_add.obj bn_s_mp_exptmod.obj bn_s_mp_mul_digs.obj bn_s_mp_mul_high_digs.obj \ -bn_s_mp_sqr.obj bn_s_mp_sub.obj +bn_mp_sqrt.obj bn_mp_sqrtmod_prime.obj bn_mp_sub.obj bn_mp_sub_d.obj bn_mp_submod.obj bn_mp_tc_and.obj \ +bn_mp_tc_div_2d.obj bn_mp_tc_or.obj bn_mp_tc_xor.obj bn_mp_toom_mul.obj bn_mp_toom_sqr.obj bn_mp_toradix.obj \ +bn_mp_toradix_n.obj bn_mp_to_signed_bin.obj bn_mp_to_signed_bin_n.obj bn_mp_to_unsigned_bin.obj \ +bn_mp_to_unsigned_bin_n.obj bn_mp_unsigned_bin_size.obj bn_mp_xor.obj bn_mp_zero.obj bn_prime_tab.obj bn_reverse.obj \ +bn_s_mp_add.obj bn_s_mp_exptmod.obj bn_s_mp_mul_digs.obj bn_s_mp_mul_high_digs.obj bn_s_mp_sqr.obj bn_s_mp_sub.obj #END_INS diff --git a/libtommath/makefile.cygwin_dll b/libtommath/makefile.cygwin_dll index 6feb5b4..fbec3bf 100644 --- a/libtommath/makefile.cygwin_dll +++ b/libtommath/makefile.cygwin_dll @@ -16,27 +16,27 @@ default: windll OBJECTS=bncore.o bn_error.o bn_fast_mp_invmod.o bn_fast_mp_montgomery_reduce.o bn_fast_s_mp_mul_digs.o \ bn_fast_s_mp_mul_high_digs.o bn_fast_s_mp_sqr.o bn_mp_2expt.o bn_mp_abs.o bn_mp_add.o bn_mp_add_d.o \ bn_mp_addmod.o bn_mp_and.o bn_mp_clamp.o bn_mp_clear.o bn_mp_clear_multi.o bn_mp_cmp.o bn_mp_cmp_d.o \ -bn_mp_cmp_mag.o bn_mp_cnt_lsb.o bn_mp_copy.o bn_mp_count_bits.o bn_mp_div_2.o bn_mp_div_2d.o bn_mp_div_3.o \ -bn_mp_div.o bn_mp_div_d.o bn_mp_dr_is_modulus.o bn_mp_dr_reduce.o bn_mp_dr_setup.o bn_mp_exch.o \ -bn_mp_export.o bn_mp_expt_d.o bn_mp_expt_d_ex.o bn_mp_exptmod.o bn_mp_exptmod_fast.o bn_mp_exteuclid.o \ -bn_mp_fread.o bn_mp_fwrite.o bn_mp_gcd.o bn_mp_get_int.o bn_mp_get_long.o bn_mp_get_long_long.o \ -bn_mp_grow.o bn_mp_import.o bn_mp_init.o bn_mp_init_copy.o bn_mp_init_multi.o bn_mp_init_set.o \ -bn_mp_init_set_int.o bn_mp_init_size.o bn_mp_invmod.o bn_mp_invmod_slow.o bn_mp_is_square.o \ -bn_mp_jacobi.o bn_mp_karatsuba_mul.o bn_mp_karatsuba_sqr.o bn_mp_lcm.o bn_mp_lshd.o bn_mp_mod_2d.o \ -bn_mp_mod.o bn_mp_mod_d.o bn_mp_montgomery_calc_normalization.o bn_mp_montgomery_reduce.o \ -bn_mp_montgomery_setup.o bn_mp_mul_2.o bn_mp_mul_2d.o bn_mp_mul.o bn_mp_mul_d.o bn_mp_mulmod.o bn_mp_neg.o \ -bn_mp_n_root.o bn_mp_n_root_ex.o bn_mp_or.o bn_mp_prime_fermat.o bn_mp_prime_is_divisible.o \ -bn_mp_prime_is_prime.o bn_mp_prime_miller_rabin.o bn_mp_prime_next_prime.o \ +bn_mp_cmp_mag.o bn_mp_cnt_lsb.o bn_mp_complement.o bn_mp_copy.o bn_mp_count_bits.o bn_mp_div_2.o \ +bn_mp_div_2d.o bn_mp_div_3.o bn_mp_div.o bn_mp_div_d.o bn_mp_dr_is_modulus.o bn_mp_dr_reduce.o \ +bn_mp_dr_setup.o bn_mp_exch.o bn_mp_export.o bn_mp_expt_d.o bn_mp_expt_d_ex.o bn_mp_exptmod.o \ +bn_mp_exptmod_fast.o bn_mp_exteuclid.o bn_mp_fread.o bn_mp_fwrite.o bn_mp_gcd.o bn_mp_get_int.o \ +bn_mp_get_long.o bn_mp_get_long_long.o bn_mp_grow.o bn_mp_import.o bn_mp_init.o bn_mp_init_copy.o \ +bn_mp_init_multi.o bn_mp_init_set.o bn_mp_init_set_int.o bn_mp_init_size.o bn_mp_invmod.o \ +bn_mp_invmod_slow.o bn_mp_is_square.o bn_mp_jacobi.o bn_mp_karatsuba_mul.o bn_mp_karatsuba_sqr.o \ +bn_mp_lcm.o bn_mp_lshd.o bn_mp_mod_2d.o bn_mp_mod.o bn_mp_mod_d.o bn_mp_montgomery_calc_normalization.o \ +bn_mp_montgomery_reduce.o bn_mp_montgomery_setup.o bn_mp_mul_2.o bn_mp_mul_2d.o bn_mp_mul.o bn_mp_mul_d.o \ +bn_mp_mulmod.o bn_mp_neg.o bn_mp_n_root.o bn_mp_n_root_ex.o bn_mp_or.o bn_mp_prime_fermat.o \ +bn_mp_prime_is_divisible.o bn_mp_prime_is_prime.o bn_mp_prime_miller_rabin.o bn_mp_prime_next_prime.o \ bn_mp_prime_rabin_miller_trials.o bn_mp_prime_random_ex.o bn_mp_radix_size.o bn_mp_radix_smap.o \ bn_mp_rand.o bn_mp_read_radix.o bn_mp_read_signed_bin.o bn_mp_read_unsigned_bin.o bn_mp_reduce_2k.o \ bn_mp_reduce_2k_l.o bn_mp_reduce_2k_setup.o bn_mp_reduce_2k_setup_l.o bn_mp_reduce.o \ bn_mp_reduce_is_2k.o bn_mp_reduce_is_2k_l.o bn_mp_reduce_setup.o bn_mp_rshd.o bn_mp_set.o bn_mp_set_int.o \ bn_mp_set_long.o bn_mp_set_long_long.o bn_mp_shrink.o bn_mp_signed_bin_size.o bn_mp_sqr.o bn_mp_sqrmod.o \ -bn_mp_sqrt.o bn_mp_sqrtmod_prime.o bn_mp_sub.o bn_mp_sub_d.o bn_mp_submod.o bn_mp_toom_mul.o \ -bn_mp_toom_sqr.o bn_mp_toradix.o bn_mp_toradix_n.o bn_mp_to_signed_bin.o bn_mp_to_signed_bin_n.o \ -bn_mp_to_unsigned_bin.o bn_mp_to_unsigned_bin_n.o bn_mp_unsigned_bin_size.o bn_mp_xor.o bn_mp_zero.o \ -bn_prime_tab.o bn_reverse.o bn_s_mp_add.o bn_s_mp_exptmod.o bn_s_mp_mul_digs.o bn_s_mp_mul_high_digs.o \ -bn_s_mp_sqr.o bn_s_mp_sub.o +bn_mp_sqrt.o bn_mp_sqrtmod_prime.o bn_mp_sub.o bn_mp_sub_d.o bn_mp_submod.o bn_mp_tc_and.o \ +bn_mp_tc_div_2d.o bn_mp_tc_or.o bn_mp_tc_xor.o bn_mp_toom_mul.o bn_mp_toom_sqr.o bn_mp_toradix.o \ +bn_mp_toradix_n.o bn_mp_to_signed_bin.o bn_mp_to_signed_bin_n.o bn_mp_to_unsigned_bin.o \ +bn_mp_to_unsigned_bin_n.o bn_mp_unsigned_bin_size.o bn_mp_xor.o bn_mp_zero.o bn_prime_tab.o bn_reverse.o \ +bn_s_mp_add.o bn_s_mp_exptmod.o bn_s_mp_mul_digs.o bn_s_mp_mul_high_digs.o bn_s_mp_sqr.o bn_s_mp_sub.o #END_INS diff --git a/libtommath/makefile.icc b/libtommath/makefile.icc index 1563802..e3cfb00 100644 --- a/libtommath/makefile.icc +++ b/libtommath/makefile.icc @@ -42,27 +42,27 @@ DATAPATH=/usr/share/doc/libtommath/pdf OBJECTS=bncore.o bn_error.o bn_fast_mp_invmod.o bn_fast_mp_montgomery_reduce.o bn_fast_s_mp_mul_digs.o \ bn_fast_s_mp_mul_high_digs.o bn_fast_s_mp_sqr.o bn_mp_2expt.o bn_mp_abs.o bn_mp_add.o bn_mp_add_d.o \ bn_mp_addmod.o bn_mp_and.o bn_mp_clamp.o bn_mp_clear.o bn_mp_clear_multi.o bn_mp_cmp.o bn_mp_cmp_d.o \ -bn_mp_cmp_mag.o bn_mp_cnt_lsb.o bn_mp_copy.o bn_mp_count_bits.o bn_mp_div_2.o bn_mp_div_2d.o bn_mp_div_3.o \ -bn_mp_div.o bn_mp_div_d.o bn_mp_dr_is_modulus.o bn_mp_dr_reduce.o bn_mp_dr_setup.o bn_mp_exch.o \ -bn_mp_export.o bn_mp_expt_d.o bn_mp_expt_d_ex.o bn_mp_exptmod.o bn_mp_exptmod_fast.o bn_mp_exteuclid.o \ -bn_mp_fread.o bn_mp_fwrite.o bn_mp_gcd.o bn_mp_get_int.o bn_mp_get_long.o bn_mp_get_long_long.o \ -bn_mp_grow.o bn_mp_import.o bn_mp_init.o bn_mp_init_copy.o bn_mp_init_multi.o bn_mp_init_set.o \ -bn_mp_init_set_int.o bn_mp_init_size.o bn_mp_invmod.o bn_mp_invmod_slow.o bn_mp_is_square.o \ -bn_mp_jacobi.o bn_mp_karatsuba_mul.o bn_mp_karatsuba_sqr.o bn_mp_lcm.o bn_mp_lshd.o bn_mp_mod_2d.o \ -bn_mp_mod.o bn_mp_mod_d.o bn_mp_montgomery_calc_normalization.o bn_mp_montgomery_reduce.o \ -bn_mp_montgomery_setup.o bn_mp_mul_2.o bn_mp_mul_2d.o bn_mp_mul.o bn_mp_mul_d.o bn_mp_mulmod.o bn_mp_neg.o \ -bn_mp_n_root.o bn_mp_n_root_ex.o bn_mp_or.o bn_mp_prime_fermat.o bn_mp_prime_is_divisible.o \ -bn_mp_prime_is_prime.o bn_mp_prime_miller_rabin.o bn_mp_prime_next_prime.o \ +bn_mp_cmp_mag.o bn_mp_cnt_lsb.o bn_mp_complement.o bn_mp_copy.o bn_mp_count_bits.o bn_mp_div_2.o \ +bn_mp_div_2d.o bn_mp_div_3.o bn_mp_div.o bn_mp_div_d.o bn_mp_dr_is_modulus.o bn_mp_dr_reduce.o \ +bn_mp_dr_setup.o bn_mp_exch.o bn_mp_export.o bn_mp_expt_d.o bn_mp_expt_d_ex.o bn_mp_exptmod.o \ +bn_mp_exptmod_fast.o bn_mp_exteuclid.o bn_mp_fread.o bn_mp_fwrite.o bn_mp_gcd.o bn_mp_get_int.o \ +bn_mp_get_long.o bn_mp_get_long_long.o bn_mp_grow.o bn_mp_import.o bn_mp_init.o bn_mp_init_copy.o \ +bn_mp_init_multi.o bn_mp_init_set.o bn_mp_init_set_int.o bn_mp_init_size.o bn_mp_invmod.o \ +bn_mp_invmod_slow.o bn_mp_is_square.o bn_mp_jacobi.o bn_mp_karatsuba_mul.o bn_mp_karatsuba_sqr.o \ +bn_mp_lcm.o bn_mp_lshd.o bn_mp_mod_2d.o bn_mp_mod.o bn_mp_mod_d.o bn_mp_montgomery_calc_normalization.o \ +bn_mp_montgomery_reduce.o bn_mp_montgomery_setup.o bn_mp_mul_2.o bn_mp_mul_2d.o bn_mp_mul.o bn_mp_mul_d.o \ +bn_mp_mulmod.o bn_mp_neg.o bn_mp_n_root.o bn_mp_n_root_ex.o bn_mp_or.o bn_mp_prime_fermat.o \ +bn_mp_prime_is_divisible.o bn_mp_prime_is_prime.o bn_mp_prime_miller_rabin.o bn_mp_prime_next_prime.o \ bn_mp_prime_rabin_miller_trials.o bn_mp_prime_random_ex.o bn_mp_radix_size.o bn_mp_radix_smap.o \ bn_mp_rand.o bn_mp_read_radix.o bn_mp_read_signed_bin.o bn_mp_read_unsigned_bin.o bn_mp_reduce_2k.o \ bn_mp_reduce_2k_l.o bn_mp_reduce_2k_setup.o bn_mp_reduce_2k_setup_l.o bn_mp_reduce.o \ bn_mp_reduce_is_2k.o bn_mp_reduce_is_2k_l.o bn_mp_reduce_setup.o bn_mp_rshd.o bn_mp_set.o bn_mp_set_int.o \ bn_mp_set_long.o bn_mp_set_long_long.o bn_mp_shrink.o bn_mp_signed_bin_size.o bn_mp_sqr.o bn_mp_sqrmod.o \ -bn_mp_sqrt.o bn_mp_sqrtmod_prime.o bn_mp_sub.o bn_mp_sub_d.o bn_mp_submod.o bn_mp_toom_mul.o \ -bn_mp_toom_sqr.o bn_mp_toradix.o bn_mp_toradix_n.o bn_mp_to_signed_bin.o bn_mp_to_signed_bin_n.o \ -bn_mp_to_unsigned_bin.o bn_mp_to_unsigned_bin_n.o bn_mp_unsigned_bin_size.o bn_mp_xor.o bn_mp_zero.o \ -bn_prime_tab.o bn_reverse.o bn_s_mp_add.o bn_s_mp_exptmod.o bn_s_mp_mul_digs.o bn_s_mp_mul_high_digs.o \ -bn_s_mp_sqr.o bn_s_mp_sub.o +bn_mp_sqrt.o bn_mp_sqrtmod_prime.o bn_mp_sub.o bn_mp_sub_d.o bn_mp_submod.o bn_mp_tc_and.o \ +bn_mp_tc_div_2d.o bn_mp_tc_or.o bn_mp_tc_xor.o bn_mp_toom_mul.o bn_mp_toom_sqr.o bn_mp_toradix.o \ +bn_mp_toradix_n.o bn_mp_to_signed_bin.o bn_mp_to_signed_bin_n.o bn_mp_to_unsigned_bin.o \ +bn_mp_to_unsigned_bin_n.o bn_mp_unsigned_bin_size.o bn_mp_xor.o bn_mp_zero.o bn_prime_tab.o bn_reverse.o \ +bn_s_mp_add.o bn_s_mp_exptmod.o bn_s_mp_mul_digs.o bn_s_mp_mul_high_digs.o bn_s_mp_sqr.o bn_s_mp_sub.o #END_INS @@ -80,17 +80,17 @@ libtommath.a: $(OBJECTS) # So far I've seen improvements in the MP math profiled: make -f makefile.icc CFLAGS="$(CFLAGS) -prof_gen -DTESTING" timing - ./ltmtest - rm -f *.a *.o ltmtest + ./timing + rm -f *.a *.o timing make -f makefile.icc CFLAGS="$(CFLAGS) -prof_use" #make a single object profiled library profiled_single: perl gen.pl $(CC) $(CFLAGS) -prof_gen -DTESTING -c mpi.c -o mpi.o - $(CC) $(CFLAGS) -DTESTING -DTIMER demo/demo.c mpi.o -o ltmtest - ./ltmtest - rm -f *.o ltmtest + $(CC) $(CFLAGS) -DTESTING -DTIMER demo/demo.c mpi.o -o timing + ./timing + rm -f *.o timing $(CC) $(CFLAGS) -prof_use -ip -DTESTING -c mpi.c -o mpi.o $(AR) $(ARFLAGS) libtommath.a mpi.o ranlib libtommath.a @@ -107,11 +107,11 @@ test: libtommath.a demo/demo.o mtest: test cd mtest ; $(CC) $(CFLAGS) mtest.c -o mtest -timing: libtommath.a - $(CC) $(CFLAGS) -DTIMER demo/timing.c libtommath.a -o ltmtest +timing: libtommath.a demo/timing.c + $(CC) $(CFLAGS) -DTIMER demo/timing.c libtommath.a -o timing clean: - rm -f *.bat *.pdf *.o *.a *.obj *.lib *.exe *.dll etclib/*.o demo/demo.o test ltmtest mpitest mtest/mtest mtest/mtest.exe \ + rm -f *.bat *.pdf *.o *.a *.obj *.lib *.exe *.dll etclib/*.o demo/demo.o test timing mpitest mtest/mtest mtest/mtest.exe \ *.idx *.toc *.log *.aux *.dvi *.lof *.ind *.ilg *.ps *.log *.s mpi.c *.il etc/*.il *.dyn cd etc ; make clean cd pics ; make clean diff --git a/libtommath/makefile.msvc b/libtommath/makefile.msvc index a47aadd..22a27fe 100644 --- a/libtommath/makefile.msvc +++ b/libtommath/makefile.msvc @@ -2,7 +2,7 @@ # #Tom St Denis -CFLAGS = /I. /Ox /DWIN32 /W3 /Fo$@ +LTM_CFLAGS = /Ox /nologo /I. /D_CRT_SECURE_NO_WARNINGS /D_CRT_NONSTDC_NO_DEPRECATE /W3 $(CFLAGS) default: library @@ -10,31 +10,34 @@ default: library OBJECTS=bncore.obj bn_error.obj bn_fast_mp_invmod.obj bn_fast_mp_montgomery_reduce.obj bn_fast_s_mp_mul_digs.obj \ bn_fast_s_mp_mul_high_digs.obj bn_fast_s_mp_sqr.obj bn_mp_2expt.obj bn_mp_abs.obj bn_mp_add.obj bn_mp_add_d.obj \ bn_mp_addmod.obj bn_mp_and.obj bn_mp_clamp.obj bn_mp_clear.obj bn_mp_clear_multi.obj bn_mp_cmp.obj bn_mp_cmp_d.obj \ -bn_mp_cmp_mag.obj bn_mp_cnt_lsb.obj bn_mp_copy.obj bn_mp_count_bits.obj bn_mp_div_2.obj bn_mp_div_2d.obj bn_mp_div_3.obj \ -bn_mp_div.obj bn_mp_div_d.obj bn_mp_dr_is_modulus.obj bn_mp_dr_reduce.obj bn_mp_dr_setup.obj bn_mp_exch.obj \ -bn_mp_export.obj bn_mp_expt_d.obj bn_mp_expt_d_ex.obj bn_mp_exptmod.obj bn_mp_exptmod_fast.obj bn_mp_exteuclid.obj \ -bn_mp_fread.obj bn_mp_fwrite.obj bn_mp_gcd.obj bn_mp_get_int.obj bn_mp_get_long.obj bn_mp_get_long_long.obj \ -bn_mp_grow.obj bn_mp_import.obj bn_mp_init.obj bn_mp_init_copy.obj bn_mp_init_multi.obj bn_mp_init_set.obj \ -bn_mp_init_set_int.obj bn_mp_init_size.obj bn_mp_invmod.obj bn_mp_invmod_slow.obj bn_mp_is_square.obj \ -bn_mp_jacobi.obj bn_mp_karatsuba_mul.obj bn_mp_karatsuba_sqr.obj bn_mp_lcm.obj bn_mp_lshd.obj bn_mp_mod_2d.obj \ -bn_mp_mod.obj bn_mp_mod_d.obj bn_mp_montgomery_calc_normalization.obj bn_mp_montgomery_reduce.obj \ -bn_mp_montgomery_setup.obj bn_mp_mul_2.obj bn_mp_mul_2d.obj bn_mp_mul.obj bn_mp_mul_d.obj bn_mp_mulmod.obj bn_mp_neg.obj \ -bn_mp_n_root.obj bn_mp_n_root_ex.obj bn_mp_or.obj bn_mp_prime_fermat.obj bn_mp_prime_is_divisible.obj \ -bn_mp_prime_is_prime.obj bn_mp_prime_miller_rabin.obj bn_mp_prime_next_prime.obj \ +bn_mp_cmp_mag.obj bn_mp_cnt_lsb.obj bn_mp_complement.obj bn_mp_copy.obj bn_mp_count_bits.obj bn_mp_div_2.obj \ +bn_mp_div_2d.obj bn_mp_div_3.obj bn_mp_div.obj bn_mp_div_d.obj bn_mp_dr_is_modulus.obj bn_mp_dr_reduce.obj \ +bn_mp_dr_setup.obj bn_mp_exch.obj bn_mp_export.obj bn_mp_expt_d.obj bn_mp_expt_d_ex.obj bn_mp_exptmod.obj \ +bn_mp_exptmod_fast.obj bn_mp_exteuclid.obj bn_mp_fread.obj bn_mp_fwrite.obj bn_mp_gcd.obj bn_mp_get_int.obj \ +bn_mp_get_long.obj bn_mp_get_long_long.obj bn_mp_grow.obj bn_mp_import.obj bn_mp_init.obj bn_mp_init_copy.obj \ +bn_mp_init_multi.obj bn_mp_init_set.obj bn_mp_init_set_int.obj bn_mp_init_size.obj bn_mp_invmod.obj \ +bn_mp_invmod_slow.obj bn_mp_is_square.obj bn_mp_jacobi.obj bn_mp_karatsuba_mul.obj bn_mp_karatsuba_sqr.obj \ +bn_mp_lcm.obj bn_mp_lshd.obj bn_mp_mod_2d.obj bn_mp_mod.obj bn_mp_mod_d.obj bn_mp_montgomery_calc_normalization.obj \ +bn_mp_montgomery_reduce.obj bn_mp_montgomery_setup.obj bn_mp_mul_2.obj bn_mp_mul_2d.obj bn_mp_mul.obj bn_mp_mul_d.obj \ +bn_mp_mulmod.obj bn_mp_neg.obj bn_mp_n_root.obj bn_mp_n_root_ex.obj bn_mp_or.obj bn_mp_prime_fermat.obj \ +bn_mp_prime_is_divisible.obj bn_mp_prime_is_prime.obj bn_mp_prime_miller_rabin.obj bn_mp_prime_next_prime.obj \ bn_mp_prime_rabin_miller_trials.obj bn_mp_prime_random_ex.obj bn_mp_radix_size.obj bn_mp_radix_smap.obj \ bn_mp_rand.obj bn_mp_read_radix.obj bn_mp_read_signed_bin.obj bn_mp_read_unsigned_bin.obj bn_mp_reduce_2k.obj \ bn_mp_reduce_2k_l.obj bn_mp_reduce_2k_setup.obj bn_mp_reduce_2k_setup_l.obj bn_mp_reduce.obj \ bn_mp_reduce_is_2k.obj bn_mp_reduce_is_2k_l.obj bn_mp_reduce_setup.obj bn_mp_rshd.obj bn_mp_set.obj bn_mp_set_int.obj \ bn_mp_set_long.obj bn_mp_set_long_long.obj bn_mp_shrink.obj bn_mp_signed_bin_size.obj bn_mp_sqr.obj bn_mp_sqrmod.obj \ -bn_mp_sqrt.obj bn_mp_sqrtmod_prime.obj bn_mp_sub.obj bn_mp_sub_d.obj bn_mp_submod.obj bn_mp_toom_mul.obj \ -bn_mp_toom_sqr.obj bn_mp_toradix.obj bn_mp_toradix_n.obj bn_mp_to_signed_bin.obj bn_mp_to_signed_bin_n.obj \ -bn_mp_to_unsigned_bin.obj bn_mp_to_unsigned_bin_n.obj bn_mp_unsigned_bin_size.obj bn_mp_xor.obj bn_mp_zero.obj \ -bn_prime_tab.obj bn_reverse.obj bn_s_mp_add.obj bn_s_mp_exptmod.obj bn_s_mp_mul_digs.obj bn_s_mp_mul_high_digs.obj \ -bn_s_mp_sqr.obj bn_s_mp_sub.obj +bn_mp_sqrt.obj bn_mp_sqrtmod_prime.obj bn_mp_sub.obj bn_mp_sub_d.obj bn_mp_submod.obj bn_mp_tc_and.obj \ +bn_mp_tc_div_2d.obj bn_mp_tc_or.obj bn_mp_tc_xor.obj bn_mp_toom_mul.obj bn_mp_toom_sqr.obj bn_mp_toradix.obj \ +bn_mp_toradix_n.obj bn_mp_to_signed_bin.obj bn_mp_to_signed_bin_n.obj bn_mp_to_unsigned_bin.obj \ +bn_mp_to_unsigned_bin_n.obj bn_mp_unsigned_bin_size.obj bn_mp_xor.obj bn_mp_zero.obj bn_prime_tab.obj bn_reverse.obj \ +bn_s_mp_add.obj bn_s_mp_exptmod.obj bn_s_mp_mul_digs.obj bn_s_mp_mul_high_digs.obj bn_s_mp_sqr.obj bn_s_mp_sub.obj #END_INS -HEADERS=tommath.h tommath_class.h tommath_superclass.h +HEADERS=tommath.h tommath_class.h tommath_private.h tommath_superclass.h library: $(OBJECTS) lib /out:tommath.lib $(OBJECTS) + +.c.obj: + $(CC) $(LTM_CFLAGS) /c $< /Fo$@ diff --git a/libtommath/makefile.shared b/libtommath/makefile.shared index 67213a2..79e5f86 100644 --- a/libtommath/makefile.shared +++ b/libtommath/makefile.shared @@ -10,14 +10,14 @@ endif include makefile_include.mk -ifndef LT +ifndef LIBTOOL ifeq ($(PLATFORM), Darwin) - LT:=glibtool + LIBTOOL:=glibtool else - LT:=libtool + LIBTOOL:=libtool endif endif -LTCOMPILE = $(LT) --mode=compile --tag=CC $(CC) +LTCOMPILE = $(LIBTOOL) --mode=compile --tag=CC $(CC) LCOV_ARGS=--directory .libs --directory . @@ -25,27 +25,27 @@ LCOV_ARGS=--directory .libs --directory . OBJECTS=bncore.o bn_error.o bn_fast_mp_invmod.o bn_fast_mp_montgomery_reduce.o bn_fast_s_mp_mul_digs.o \ bn_fast_s_mp_mul_high_digs.o bn_fast_s_mp_sqr.o bn_mp_2expt.o bn_mp_abs.o bn_mp_add.o bn_mp_add_d.o \ bn_mp_addmod.o bn_mp_and.o bn_mp_clamp.o bn_mp_clear.o bn_mp_clear_multi.o bn_mp_cmp.o bn_mp_cmp_d.o \ -bn_mp_cmp_mag.o bn_mp_cnt_lsb.o bn_mp_copy.o bn_mp_count_bits.o bn_mp_div_2.o bn_mp_div_2d.o bn_mp_div_3.o \ -bn_mp_div.o bn_mp_div_d.o bn_mp_dr_is_modulus.o bn_mp_dr_reduce.o bn_mp_dr_setup.o bn_mp_exch.o \ -bn_mp_export.o bn_mp_expt_d.o bn_mp_expt_d_ex.o bn_mp_exptmod.o bn_mp_exptmod_fast.o bn_mp_exteuclid.o \ -bn_mp_fread.o bn_mp_fwrite.o bn_mp_gcd.o bn_mp_get_int.o bn_mp_get_long.o bn_mp_get_long_long.o \ -bn_mp_grow.o bn_mp_import.o bn_mp_init.o bn_mp_init_copy.o bn_mp_init_multi.o bn_mp_init_set.o \ -bn_mp_init_set_int.o bn_mp_init_size.o bn_mp_invmod.o bn_mp_invmod_slow.o bn_mp_is_square.o \ -bn_mp_jacobi.o bn_mp_karatsuba_mul.o bn_mp_karatsuba_sqr.o bn_mp_lcm.o bn_mp_lshd.o bn_mp_mod_2d.o \ -bn_mp_mod.o bn_mp_mod_d.o bn_mp_montgomery_calc_normalization.o bn_mp_montgomery_reduce.o \ -bn_mp_montgomery_setup.o bn_mp_mul_2.o bn_mp_mul_2d.o bn_mp_mul.o bn_mp_mul_d.o bn_mp_mulmod.o bn_mp_neg.o \ -bn_mp_n_root.o bn_mp_n_root_ex.o bn_mp_or.o bn_mp_prime_fermat.o bn_mp_prime_is_divisible.o \ -bn_mp_prime_is_prime.o bn_mp_prime_miller_rabin.o bn_mp_prime_next_prime.o \ +bn_mp_cmp_mag.o bn_mp_cnt_lsb.o bn_mp_complement.o bn_mp_copy.o bn_mp_count_bits.o bn_mp_div_2.o \ +bn_mp_div_2d.o bn_mp_div_3.o bn_mp_div.o bn_mp_div_d.o bn_mp_dr_is_modulus.o bn_mp_dr_reduce.o \ +bn_mp_dr_setup.o bn_mp_exch.o bn_mp_export.o bn_mp_expt_d.o bn_mp_expt_d_ex.o bn_mp_exptmod.o \ +bn_mp_exptmod_fast.o bn_mp_exteuclid.o bn_mp_fread.o bn_mp_fwrite.o bn_mp_gcd.o bn_mp_get_int.o \ +bn_mp_get_long.o bn_mp_get_long_long.o bn_mp_grow.o bn_mp_import.o bn_mp_init.o bn_mp_init_copy.o \ +bn_mp_init_multi.o bn_mp_init_set.o bn_mp_init_set_int.o bn_mp_init_size.o bn_mp_invmod.o \ +bn_mp_invmod_slow.o bn_mp_is_square.o bn_mp_jacobi.o bn_mp_karatsuba_mul.o bn_mp_karatsuba_sqr.o \ +bn_mp_lcm.o bn_mp_lshd.o bn_mp_mod_2d.o bn_mp_mod.o bn_mp_mod_d.o bn_mp_montgomery_calc_normalization.o \ +bn_mp_montgomery_reduce.o bn_mp_montgomery_setup.o bn_mp_mul_2.o bn_mp_mul_2d.o bn_mp_mul.o bn_mp_mul_d.o \ +bn_mp_mulmod.o bn_mp_neg.o bn_mp_n_root.o bn_mp_n_root_ex.o bn_mp_or.o bn_mp_prime_fermat.o \ +bn_mp_prime_is_divisible.o bn_mp_prime_is_prime.o bn_mp_prime_miller_rabin.o bn_mp_prime_next_prime.o \ bn_mp_prime_rabin_miller_trials.o bn_mp_prime_random_ex.o bn_mp_radix_size.o bn_mp_radix_smap.o \ bn_mp_rand.o bn_mp_read_radix.o bn_mp_read_signed_bin.o bn_mp_read_unsigned_bin.o bn_mp_reduce_2k.o \ bn_mp_reduce_2k_l.o bn_mp_reduce_2k_setup.o bn_mp_reduce_2k_setup_l.o bn_mp_reduce.o \ bn_mp_reduce_is_2k.o bn_mp_reduce_is_2k_l.o bn_mp_reduce_setup.o bn_mp_rshd.o bn_mp_set.o bn_mp_set_int.o \ bn_mp_set_long.o bn_mp_set_long_long.o bn_mp_shrink.o bn_mp_signed_bin_size.o bn_mp_sqr.o bn_mp_sqrmod.o \ -bn_mp_sqrt.o bn_mp_sqrtmod_prime.o bn_mp_sub.o bn_mp_sub_d.o bn_mp_submod.o bn_mp_toom_mul.o \ -bn_mp_toom_sqr.o bn_mp_toradix.o bn_mp_toradix_n.o bn_mp_to_signed_bin.o bn_mp_to_signed_bin_n.o \ -bn_mp_to_unsigned_bin.o bn_mp_to_unsigned_bin_n.o bn_mp_unsigned_bin_size.o bn_mp_xor.o bn_mp_zero.o \ -bn_prime_tab.o bn_reverse.o bn_s_mp_add.o bn_s_mp_exptmod.o bn_s_mp_mul_digs.o bn_s_mp_mul_high_digs.o \ -bn_s_mp_sqr.o bn_s_mp_sub.o +bn_mp_sqrt.o bn_mp_sqrtmod_prime.o bn_mp_sub.o bn_mp_sub_d.o bn_mp_submod.o bn_mp_tc_and.o \ +bn_mp_tc_div_2d.o bn_mp_tc_or.o bn_mp_tc_xor.o bn_mp_toom_mul.o bn_mp_toom_sqr.o bn_mp_toradix.o \ +bn_mp_toradix_n.o bn_mp_to_signed_bin.o bn_mp_to_signed_bin_n.o bn_mp_to_unsigned_bin.o \ +bn_mp_to_unsigned_bin_n.o bn_mp_unsigned_bin_size.o bn_mp_xor.o bn_mp_zero.o bn_prime_tab.o bn_reverse.o \ +bn_s_mp_add.o bn_s_mp_exptmod.o bn_s_mp_mul_digs.o bn_s_mp_mul_high_digs.o bn_s_mp_sqr.o bn_s_mp_sub.o #END_INS @@ -57,32 +57,32 @@ objs: $(OBJECTS) LOBJECTS = $(OBJECTS:.o=.lo) $(LIBNAME): $(OBJECTS) - $(LT) --mode=link --tag=CC $(CC) $(LDFLAGS) $(LOBJECTS) -o $(LIBNAME) -rpath $(LIBPATH) -version-info $(VERSION_SO) + $(LIBTOOL) --mode=link --tag=CC $(CC) $(LDFLAGS) $(LOBJECTS) -o $(LIBNAME) -rpath $(LIBPATH) -version-info $(VERSION_SO) install: $(LIBNAME) install -d $(DESTDIR)$(LIBPATH) install -d $(DESTDIR)$(INCPATH) - $(LT) --mode=install install -m 644 $(LIBNAME) $(DESTDIR)$(LIBPATH)/$(LIBNAME) + $(LIBTOOL) --mode=install install -m 644 $(LIBNAME) $(DESTDIR)$(LIBPATH)/$(LIBNAME) install -m 644 $(HEADERS_PUB) $(DESTDIR)$(INCPATH) sed -e 's,^prefix=.*,prefix=$(PREFIX),' -e 's,^Version:.*,Version: $(VERSION_PC),' libtommath.pc.in > libtommath.pc install -d $(DESTDIR)$(LIBPATH)/pkgconfig install -m 644 libtommath.pc $(DESTDIR)$(LIBPATH)/pkgconfig/ uninstall: - $(LT) --mode=uninstall rm $(DESTDIR)$(LIBPATH)/$(LIBNAME) + $(LIBTOOL) --mode=uninstall rm $(DESTDIR)$(LIBPATH)/$(LIBNAME) rm $(HEADERS_PUB:%=$(DESTDIR)$(INCPATH)/%) rm $(DESTDIR)$(LIBPATH)/pkgconfig/libtommath.pc test: $(LIBNAME) demo/demo.o $(CC) $(CFLAGS) -c demo/demo.c -o demo/demo.o - $(LT) --mode=link $(CC) $(LDFLAGS) -o test demo/demo.o $(LIBNAME) + $(LIBTOOL) --mode=link $(CC) $(LDFLAGS) -o test demo/demo.o $(LIBNAME) test_standalone: $(LIBNAME) demo/demo.o $(CC) $(CFLAGS) -c demo/demo.c -o demo/demo.o - $(LT) --mode=link $(CC) $(LDFLAGS) -o test demo/demo.o $(LIBNAME) + $(LIBTOOL) --mode=link $(CC) $(LDFLAGS) -o test demo/demo.o $(LIBNAME) mtest: cd mtest ; $(CC) $(CFLAGS) $(LDFLAGS) mtest.c -o mtest -timing: $(LIBNAME) - $(LT) --mode=link $(CC) $(CFLAGS) $(LDFLAGS) -DTIMER demo/timing.c $(LIBNAME) -o ltmtest +timing: $(LIBNAME) demo/timing.c + $(LIBTOOL) --mode=link $(CC) $(CFLAGS) $(LDFLAGS) -DTIMER demo/timing.c $(LIBNAME) -o timing diff --git a/libtommath/makefile_include.mk b/libtommath/makefile_include.mk index 45a4895..c4ba8db 100644 --- a/libtommath/makefile_include.mk +++ b/libtommath/makefile_include.mk @@ -17,15 +17,34 @@ ifndef CROSS_COMPILE CROSS_COMPILE= endif -ifeq ($(CC),cc) - CC = $(CROSS_COMPILE)gcc +# We only need to go through this dance of determining the right compiler if we're using +# cross compilation, otherwise $(CC) is fine as-is. +ifneq (,$(CROSS_COMPILE)) +ifeq ($(origin CC),default) +CSTR := "\#ifdef __clang__\nCLANG\n\#endif\n" +ifeq ($(PLATFORM),FreeBSD) + # XXX: FreeBSD needs extra escaping for some reason + CSTR := $$$(CSTR) endif +ifneq (,$(shell echo $(CSTR) | $(CC) -E - | grep CLANG)) + CC := $(CROSS_COMPILE)clang +else + CC := $(CROSS_COMPILE)gcc +endif # Clang +endif # cc is Make's default +endif # CROSS_COMPILE non-empty + LD=$(CROSS_COMPILE)ld AR=$(CROSS_COMPILE)ar RANLIB=$(CROSS_COMPILE)ranlib ifndef MAKE - MAKE=make +# BSDs refer to GNU Make as gmake +ifneq (,$(findstring $(PLATFORM),FreeBSD OpenBSD DragonFly NetBSD)) + MAKE=gmake +else + MAKE=make +endif endif CFLAGS += -I./ -Wall -Wsign-compare -Wextra -Wshadow @@ -67,10 +86,16 @@ ifeq ($(PLATFORM), Darwin) CFLAGS += -Wno-nullability-completeness endif +ifeq ($(PLATFORM),FreeBSD) + _ARCH := $(shell sysctl -b hw.machine_arch) +else + _ARCH := $(shell arch) +endif + # adjust coverage set -ifneq ($(filter $(shell arch), i386 i686 x86_64 amd64 ia64),) +ifneq ($(filter $(_ARCH), i386 i686 x86_64 amd64 ia64),) COVERAGE = test_standalone timing - COVERAGE_APP = ./test && ./ltmtest + COVERAGE_APP = ./test && ./timing else COVERAGE = test_standalone COVERAGE_APP = ./test @@ -113,7 +138,7 @@ cleancov-clean: cleancov: cleancov-clean clean clean: - rm -f *.gcda *.gcno *.gcov *.bat *.o *.a *.obj *.lib *.exe *.dll etclib/*.o demo/demo.o test ltmtest mpitest mtest/mtest mtest/mtest.exe \ + rm -f *.gcda *.gcno *.gcov *.bat *.o *.a *.obj *.lib *.exe *.dll etclib/*.o demo/demo.o test timing mpitest mtest/mtest mtest/mtest.exe \ *.idx *.toc *.log *.aux *.dvi *.lof *.ind *.ilg *.ps *.log *.s mpi.c *.da *.dyn *.dpi tommath.tex `find . -type f | grep [~] | xargs` *.lo *.la rm -rf .libs/ ${MAKE} -C etc/ clean MAKE=${MAKE} diff --git a/libtommath/tommath.h b/libtommath/tommath.h index e229bc6..9cec473 100644 --- a/libtommath/tommath.h +++ b/libtommath/tommath.h @@ -9,8 +9,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://math.libtomcrypt.com */ #ifndef BN_H_ #define BN_H_ @@ -27,7 +25,7 @@ extern "C" { #endif /* MS Visual C++ doesn't have a 128bit type for words, so fall back to 32bit MPI's (where words are 64bit) */ -#if defined(_MSC_VER) || defined(__LLP64__) +#if defined(_MSC_VER) || defined(__LLP64__) || defined(__e2k__) || defined(__LCC__) # define MP_32BIT #endif @@ -39,7 +37,13 @@ extern "C" { 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)) -# define MP_64BIT +# if defined(__GNUC__) +/* we support 128bit integers only via: __attribute__((mode(TI))) */ +# define MP_64BIT +# else +/* otherwise we fall back to MP_32BIT even on 64bit platforms */ +# define MP_32BIT +# endif # endif #endif @@ -68,14 +72,7 @@ typedef uint32_t mp_word; #elif defined(MP_64BIT) /* for GCC only on supported platforms */ typedef uint64_t mp_digit; -# if defined(__GNUC__) typedef unsigned long mp_word __attribute__((mode(TI))); -# else -/* it seems you have a problem - * but we assume you can somewhere define your own uint128_t */ -typedef uint128_t mp_word; -# endif - # define DIGIT_BIT 60 #else /* this is the default case, 28-bit digits */ @@ -102,18 +99,6 @@ typedef uint_least32_t mp_min_u32; typedef mp_digit mp_min_u32; #endif -/* use arc4random on platforms that support it */ -#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__) -# define MP_GEN_RANDOM() arc4random() -# define MP_GEN_RANDOM_MAX 0xffffffffu -#endif - -/* use rand() as fall-back if there's no better rand function */ -#ifndef MP_GEN_RANDOM -# define MP_GEN_RANDOM() rand() -# define MP_GEN_RANDOM_MAX RAND_MAX -#endif - #define MP_DIGIT_BIT DIGIT_BIT #define MP_MASK ((((mp_digit)1)<<((mp_digit)DIGIT_BIT))-((mp_digit)1)) #define MP_DIGIT_MAX MP_MASK @@ -289,6 +274,14 @@ int mp_cnt_lsb(const mp_int *a); /* makes a pseudo-random int of a given size */ int mp_rand(mp_int *a, int digits); +#ifdef MP_PRNG_ENABLE_LTM_RNG +/* as last resort we will fall back to libtomcrypt's rng_get_bytes() + * in case you don't use libtomcrypt or use it w/o rng_get_bytes() + * you have to implement it somewhere else, as it's required */ +extern unsigned long (*ltm_rng)(unsigned char *out, unsigned long outlen, void (*callback)(void)); +extern void (*ltm_rng_callback)(void); +#endif + /* ---> binary operations <--- */ /* c = a XOR b */ int mp_xor(const mp_int *a, const mp_int *b, mp_int *c); @@ -299,8 +292,23 @@ int mp_or(const mp_int *a, const mp_int *b, mp_int *c); /* c = a AND b */ int mp_and(const mp_int *a, const mp_int *b, mp_int *c); +/* c = a XOR b (two complement) */ +int mp_tc_xor(const mp_int *a, const mp_int *b, mp_int *c); + +/* c = a OR b (two complement) */ +int mp_tc_or(const mp_int *a, const mp_int *b, mp_int *c); + +/* c = a AND b (two complement) */ +int mp_tc_and(const mp_int *a, const mp_int *b, mp_int *c); + +/* right shift (two complement) */ +int mp_tc_div_2d(const mp_int *a, int b, mp_int *c); + /* ---> Basic arithmetic <--- */ +/* b = ~a */ +int mp_complement(const mp_int *a, mp_int *b); + /* b = -a */ int mp_neg(const mp_int *a, mp_int *b); diff --git a/libtommath/tommath_class.h b/libtommath/tommath_class.h index f700d66..1989054 100644 --- a/libtommath/tommath_class.h +++ b/libtommath/tommath_class.h @@ -27,6 +27,7 @@ # define BN_MP_CMP_D_C # define BN_MP_CMP_MAG_C # define BN_MP_CNT_LSB_C +# define BN_MP_COMPLEMENT_C # define BN_MP_COPY_C # define BN_MP_COUNT_BITS_C # define BN_MP_DIV_C @@ -116,6 +117,10 @@ # define BN_MP_SUB_C # define BN_MP_SUB_D_C # define BN_MP_SUBMOD_C +# define BN_MP_TC_AND_C +# define BN_MP_TC_DIV_2D_C +# define BN_MP_TC_OR_C +# define BN_MP_TC_XOR_C # define BN_MP_TO_SIGNED_BIN_C # define BN_MP_TO_SIGNED_BIN_N_C # define BN_MP_TO_UNSIGNED_BIN_C @@ -147,12 +152,12 @@ # define BN_MP_INIT_MULTI_C # define BN_MP_COPY_C # define BN_MP_MOD_C +# define BN_MP_ISZERO_C # define BN_MP_SET_C # define BN_MP_DIV_2_C # define BN_MP_ISODD_C # define BN_MP_SUB_C # define BN_MP_CMP_C -# define BN_MP_ISZERO_C # define BN_MP_CMP_D_C # define BN_MP_ADD_C # define BN_MP_EXCH_C @@ -241,6 +246,11 @@ # define BN_MP_ISZERO_C #endif +#if defined(BN_MP_COMPLEMENT_C) +# define BN_MP_NEG_C +# define BN_MP_SUB_D_C +#endif + #if defined(BN_MP_COPY_C) # define BN_MP_GROW_C #endif @@ -390,7 +400,8 @@ #if defined(BN_MP_FREAD_C) # define BN_MP_ZERO_C -# define BN_MP_S_RMAP_C +# define BN_MP_S_RMAP_REVERSE_SZ_C +# define BN_MP_S_RMAP_REVERSE_C # define BN_MP_MUL_D_C # define BN_MP_ADD_D_C # define BN_MP_CMP_D_C @@ -462,9 +473,8 @@ #endif #if defined(BN_MP_INVMOD_C) -# define BN_MP_ISZERO_C -# define BN_MP_ISODD_C # define BN_MP_CMP_D_C +# define BN_MP_ISODD_C # define BN_FAST_MP_INVMOD_C # define BN_MP_INVMOD_SLOW_C #endif @@ -541,6 +551,7 @@ #endif #if defined(BN_MP_LSHD_C) +# define BN_MP_ISZERO_C # define BN_MP_GROW_C # define BN_MP_RSHD_C #endif @@ -714,6 +725,8 @@ #if defined(BN_MP_RADIX_SMAP_C) # define BN_MP_S_RMAP_C +# define BN_MP_S_RMAP_REVERSE_C +# define BN_MP_S_RMAP_REVERSE_SZ_C #endif #if defined(BN_MP_RAND_C) @@ -724,7 +737,8 @@ #if defined(BN_MP_READ_RADIX_C) # define BN_MP_ZERO_C -# define BN_MP_S_RMAP_C +# define BN_MP_S_RMAP_REVERSE_SZ_C +# define BN_MP_S_RMAP_REVERSE_C # define BN_MP_MUL_D_C # define BN_MP_ADD_D_C # define BN_MP_ISZERO_C @@ -904,6 +918,49 @@ # define BN_MP_MOD_C #endif +#if defined(BN_MP_TC_AND_C) +# define BN_MP_ISNEG_C +# define BN_MP_COUNT_BITS_C +# define BN_MP_INIT_SET_INT_C +# define BN_MP_MUL_2D_C +# define BN_MP_INIT_C +# define BN_MP_ADD_C +# define BN_MP_CLEAR_C +# define BN_MP_AND_C +# define BN_MP_SUB_C +#endif + +#if defined(BN_MP_TC_DIV_2D_C) +# define BN_MP_ISNEG_C +# define BN_MP_DIV_2D_C +# define BN_MP_ADD_D_C +# define BN_MP_SUB_D_C +#endif + +#if defined(BN_MP_TC_OR_C) +# define BN_MP_ISNEG_C +# define BN_MP_COUNT_BITS_C +# define BN_MP_INIT_SET_INT_C +# define BN_MP_MUL_2D_C +# define BN_MP_INIT_C +# define BN_MP_ADD_C +# define BN_MP_CLEAR_C +# define BN_MP_OR_C +# define BN_MP_SUB_C +#endif + +#if defined(BN_MP_TC_XOR_C) +# define BN_MP_ISNEG_C +# define BN_MP_COUNT_BITS_C +# define BN_MP_INIT_SET_INT_C +# define BN_MP_MUL_2D_C +# define BN_MP_INIT_C +# define BN_MP_ADD_C +# define BN_MP_CLEAR_C +# define BN_MP_XOR_C +# define BN_MP_SUB_C +#endif + #if defined(BN_MP_TO_SIGNED_BIN_C) # define BN_MP_TO_UNSIGNED_BIN_C #endif diff --git a/libtommath/tommath_private.h b/libtommath/tommath_private.h index 678edc4..133aea9 100644 --- a/libtommath/tommath_private.h +++ b/libtommath/tommath_private.h @@ -9,13 +9,11 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tstdenis82@gmail.com, http://math.libtomcrypt.com */ #ifndef TOMMATH_PRIV_H_ #define TOMMATH_PRIV_H_ -#include +#include "tommath.h" #include #ifndef MIN @@ -75,7 +73,7 @@ int mp_exptmod_fast(const mp_int *G, const mp_int *X, const mp_int *P, mp_int *Y int s_mp_exptmod(const mp_int *G, const mp_int *X, const mp_int *P, mp_int *Y, int redmode); void bn_reverse(unsigned char *s, int len); -extern const char *mp_s_rmap; +extern const char *const mp_s_rmap; extern const uint8_t mp_s_rmap_reverse[]; extern const size_t mp_s_rmap_reverse_sz; -- cgit v0.12 From 140cd14f15899b2d26c21a9cff7e805daf239fd9 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Mon, 22 Oct 2018 20:40:25 +0000 Subject: formatting --- libtommath/bn_mp_sqrt.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/libtommath/bn_mp_sqrt.c b/libtommath/bn_mp_sqrt.c index 84d521f..d342a32 100644 --- a/libtommath/bn_mp_sqrt.c +++ b/libtommath/bn_mp_sqrt.c @@ -21,7 +21,7 @@ int mp_sqrt(const mp_int *arg, mp_int *ret) { int res; - mp_int t1,t2; + mp_int t1, t2; int i, j, k; #ifndef NO_FLOATING_POINT volatile double d; @@ -106,30 +106,30 @@ int mp_sqrt(const mp_int *arg, mp_int *ret) #endif /* t1 > 0 */ - if ((res = mp_div(arg,&t1,&t2,NULL)) != MP_OKAY) { + if ((res = mp_div(arg, &t1, &t2, NULL)) != MP_OKAY) { goto E1; } - if ((res = mp_add(&t1,&t2,&t1)) != MP_OKAY) { + if ((res = mp_add(&t1, &t2, &t1)) != MP_OKAY) { goto E1; } - if ((res = mp_div_2(&t1,&t1)) != MP_OKAY) { + if ((res = mp_div_2(&t1, &t1)) != MP_OKAY) { goto E1; } /* And now t1 > sqrt(arg) */ do { - if ((res = mp_div(arg,&t1,&t2,NULL)) != MP_OKAY) { + if ((res = mp_div(arg, &t1, &t2, NULL)) != MP_OKAY) { goto E1; } - if ((res = mp_add(&t1,&t2,&t1)) != MP_OKAY) { + if ((res = mp_add(&t1, &t2, &t1)) != MP_OKAY) { goto E1; } - if ((res = mp_div_2(&t1,&t1)) != MP_OKAY) { + if ((res = mp_div_2(&t1, &t1)) != MP_OKAY) { goto E1; } /* t1 >= sqrt(arg) >= t2 at this point */ - } while (mp_cmp_mag(&t1,&t2) == MP_GT); + } while (mp_cmp_mag(&t1, &t2) == MP_GT); - mp_exch(&t1,ret); + mp_exch(&t1, ret); E1: mp_clear(&t2); -- cgit v0.12 From 4ad4d79d418768a1f827cb9a42297c5a8a4737a9 Mon Sep 17 00:00:00 2001 From: dgp Date: Tue, 23 Oct 2018 18:24:50 +0000 Subject: The "end-offset" type is unregistered. No need for a setFromAnyProc. Remove and simplify. --- generic/tclUtil.c | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/generic/tclUtil.c b/generic/tclUtil.c index fca9b75..451167c 100644 --- a/generic/tclUtil.c +++ b/generic/tclUtil.c @@ -113,8 +113,7 @@ static int GetEndOffsetFromObj(Tcl_Obj *objPtr, static Tcl_HashTable * GetThreadHash(Tcl_ThreadDataKey *keyPtr); static int GetWideForIndex(Tcl_Interp *interp, Tcl_Obj *objPtr, Tcl_WideInt endValue, Tcl_WideInt *widePtr); -static int SetEndOffsetFromAny(Tcl_Interp *interp, - Tcl_Obj *objPtr); +static int SetEndOffsetFromAny(Tcl_Obj *objPtr); static int FindElement(Tcl_Interp *interp, const char *string, int stringLength, const char *typeStr, const char *typeCode, const char **elementPtr, @@ -127,7 +126,8 @@ static int FindElement(Tcl_Interp *interp, const char *string, * stored directly in the wideValue, so no memory management is required * for it. This is a caching intrep, keeping the result of a parse * around. This type is only created from a pre-existing string, so an - * updateStringProc will never be called and need not exist. + * updateStringProc will never be called and need not exist. The type + * is unregistered, so has no need of a setFromAnyProc either. */ static const Tcl_ObjType endOffsetType = { @@ -135,7 +135,7 @@ static const Tcl_ObjType endOffsetType = { NULL, /* freeIntRepProc */ NULL, /* dupIntRepProc */ NULL, /* updateStringProc */ - SetEndOffsetFromAny + NULL /* setFromAnyProc */ }; /* @@ -3930,7 +3930,7 @@ GetEndOffsetFromObj( Tcl_WideInt *widePtr) /* Location filled in with an integer * representing an index. */ { - if (SetEndOffsetFromAny(NULL, objPtr) == TCL_OK) { + if (SetEndOffsetFromAny(objPtr) == TCL_OK) { Tcl_WideInt offset = objPtr->internalRep.wideValue; if ((endValue ^ offset) < 0) { @@ -3965,19 +3965,14 @@ GetEndOffsetFromObj( * Results: * Returns TCL_OK if ok, TCL_ERROR if the string was badly formed. * - * Side effects: - * If interp is not NULL, stores an error message in the interpreter - * result. - * *---------------------------------------------------------------------- */ static int SetEndOffsetFromAny( - Tcl_Interp *interp, /* Tcl interpreter or NULL */ Tcl_Obj *objPtr) /* Pointer to the object to parse */ { - Tcl_WideInt offset; /* Offset in the "end-offset" expression */ + Tcl_WideInt offset; /* Offset in the "end-offset" expression */ register const char *bytes; /* String rep of the object */ int length; /* Length of the object's string rep */ @@ -3996,13 +3991,6 @@ SetEndOffsetFromAny( bytes = TclGetStringFromObj(objPtr, &length); if ((*bytes != 'e') || (strncmp(bytes, "end", (size_t)((length > 3) ? 3 : length)) != 0)) { - - badIndexFormat: - if (interp != NULL) { - Tcl_SetObjResult(interp, Tcl_ObjPrintf( - "bad index \"%s\": must be end?[+-]integer?", bytes)); - Tcl_SetErrorCode(interp, "TCL", "VALUE", "INDEX", NULL); - } return TCL_ERROR; } @@ -4021,11 +4009,11 @@ SetEndOffsetFromAny( int t; if (TclIsSpaceProc(bytes[4])) { - goto badIndexFormat; + return TCL_ERROR; } if (TclParseNumber(NULL, objPtr, NULL, bytes+4, length-4, NULL, TCL_PARSE_INTEGER_ONLY) != TCL_OK) { - goto badIndexFormat; + return TCL_ERROR; } TclGetNumberFromObj(NULL, objPtr, &cd, &t); if (t == TCL_NUMBER_BIG) { @@ -4043,7 +4031,7 @@ SetEndOffsetFromAny( } } } else { - goto badIndexFormat; + return TCL_ERROR; } /* -- cgit v0.12 From 7e67cf48ebc00a5378ef2ef349aa3ba613d127d9 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Tue, 23 Oct 2018 18:37:54 +0000 Subject: Branch [https://github.com/libtom/libtommath/commits/no-stdint-h] from libtommath, by karel-m. --- libtommath/bn_mp_radix_smap.c | 2 +- libtommath/tommath.h | 17 ++++++++--------- libtommath/tommath_private.h | 2 +- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/libtommath/bn_mp_radix_smap.c b/libtommath/bn_mp_radix_smap.c index 6e9f64a..caba69f 100644 --- a/libtommath/bn_mp_radix_smap.c +++ b/libtommath/bn_mp_radix_smap.c @@ -15,7 +15,7 @@ /* chars used in radix conversions */ const char *const mp_s_rmap = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/"; -const uint8_t mp_s_rmap_reverse[] = { +const unsigned char mp_s_rmap_reverse[] = { 0xff, 0xff, 0xff, 0x3e, 0xff, 0xff, 0xff, 0x3f, /* ()*+,-./ */ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, /* 01234567 */ 0x08, 0x09, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 89:;<=>? */ diff --git a/libtommath/tommath.h b/libtommath/tommath.h index 9cec473..5c90b90 100644 --- a/libtommath/tommath.h +++ b/libtommath/tommath.h @@ -15,7 +15,6 @@ #include #include -#include #include #include @@ -56,30 +55,30 @@ extern "C" { * [any size beyond that is ok provided it doesn't overflow the data type] */ #ifdef MP_8BIT -typedef uint8_t mp_digit; -typedef uint16_t mp_word; +typedef unsigned char mp_digit; +typedef unsigned short mp_word; # define MP_SIZEOF_MP_DIGIT 1 # ifdef DIGIT_BIT # error You must not define DIGIT_BIT when using MP_8BIT # endif #elif defined(MP_16BIT) -typedef uint16_t mp_digit; -typedef uint32_t mp_word; +typedef unsigned short mp_digit; +typedef unsigned int mp_word; # define MP_SIZEOF_MP_DIGIT 2 # ifdef DIGIT_BIT # error You must not define DIGIT_BIT when using MP_16BIT # endif #elif defined(MP_64BIT) /* for GCC only on supported platforms */ -typedef uint64_t mp_digit; +typedef unsigned long long mp_digit; typedef unsigned long mp_word __attribute__((mode(TI))); # define DIGIT_BIT 60 #else /* this is the default case, 28-bit digits */ /* this is to make porting into LibTomCrypt easier :-) */ -typedef uint32_t mp_digit; -typedef uint64_t mp_word; +typedef unsigned int mp_digit; +typedef unsigned long long mp_word; # ifdef MP_31BIT /* this is an extension that uses 31-bit digits */ @@ -94,7 +93,7 @@ typedef uint64_t mp_word; /* otherwise the bits per digit is calculated automatically from the size of a mp_digit */ #ifndef DIGIT_BIT # define DIGIT_BIT (((CHAR_BIT * MP_SIZEOF_MP_DIGIT) - 1)) /* bits per digit */ -typedef uint_least32_t mp_min_u32; +typedef unsigned long mp_min_u32; #else typedef mp_digit mp_min_u32; #endif diff --git a/libtommath/tommath_private.h b/libtommath/tommath_private.h index 133aea9..e9dbd5b 100644 --- a/libtommath/tommath_private.h +++ b/libtommath/tommath_private.h @@ -74,7 +74,7 @@ int s_mp_exptmod(const mp_int *G, const mp_int *X, const mp_int *P, mp_int *Y, i void bn_reverse(unsigned char *s, int len); extern const char *const mp_s_rmap; -extern const uint8_t mp_s_rmap_reverse[]; +extern const unsigned char mp_s_rmap_reverse[]; extern const size_t mp_s_rmap_reverse_sz; /* Fancy macro to set an MPI from another type. -- cgit v0.12 From a883ddbe3e214ba2ffa048e61a6f4641519c460b Mon Sep 17 00:00:00 2001 From: dgp Date: Tue, 23 Oct 2018 18:49:36 +0000 Subject: Refactor the SetEndOffsetFromAny() routine into its only caller. --- generic/tclUtil.c | 161 ++++++++++++++++++++---------------------------------- 1 file changed, 59 insertions(+), 102 deletions(-) diff --git a/generic/tclUtil.c b/generic/tclUtil.c index 451167c..954caff 100644 --- a/generic/tclUtil.c +++ b/generic/tclUtil.c @@ -113,7 +113,6 @@ static int GetEndOffsetFromObj(Tcl_Obj *objPtr, static Tcl_HashTable * GetThreadHash(Tcl_ThreadDataKey *keyPtr); static int GetWideForIndex(Tcl_Interp *interp, Tcl_Obj *objPtr, Tcl_WideInt endValue, Tcl_WideInt *widePtr); -static int SetEndOffsetFromAny(Tcl_Obj *objPtr); static int FindElement(Tcl_Interp *interp, const char *string, int stringLength, const char *typeStr, const char *typeCode, const char **elementPtr, @@ -3930,119 +3929,77 @@ GetEndOffsetFromObj( Tcl_WideInt *widePtr) /* Location filled in with an integer * representing an index. */ { - if (SetEndOffsetFromAny(objPtr) == TCL_OK) { - Tcl_WideInt offset = objPtr->internalRep.wideValue; - - if ((endValue ^ offset) < 0) { - /* Different signs, sum cannot overflow */ - *widePtr = endValue + offset; - } else if (endValue >= 0) { - if (endValue < LLONG_MAX - offset) { - *widePtr = endValue + offset; - } else { - *widePtr = LLONG_MAX; - } - } else { - if (endValue > LLONG_MIN - offset) { - *widePtr = endValue + offset; - } else { - *widePtr = LLONG_MIN; - } - } - return TCL_OK; - } - return TCL_ERROR; -} - -/* - *---------------------------------------------------------------------- - * - * SetEndOffsetFromAny -- - * - * Look for a string of the form "end[+-]offset" and convert it to an - * internal representation holding the offset. - * - * Results: - * Returns TCL_OK if ok, TCL_ERROR if the string was badly formed. - * - *---------------------------------------------------------------------- - */ - -static int -SetEndOffsetFromAny( - Tcl_Obj *objPtr) /* Pointer to the object to parse */ -{ Tcl_WideInt offset; /* Offset in the "end-offset" expression */ - register const char *bytes; /* String rep of the object */ - int length; /* Length of the object's string rep */ - - /* - * If it's already the right type, we're fine. - */ - - if (objPtr->typePtr == &endOffsetType) { - return TCL_OK; - } - - /* - * Check for a string rep of the right form. - */ - - bytes = TclGetStringFromObj(objPtr, &length); - if ((*bytes != 'e') || (strncmp(bytes, "end", - (size_t)((length > 3) ? 3 : length)) != 0)) { - return TCL_ERROR; - } - - /* - * Convert the string rep. - */ - if (length <= 3) { - offset = 0; - } else if ((length > 4) && ((bytes[3] == '-') || (bytes[3] == '+'))) { - /* - * This is our limited string expression evaluator. Pass everything - * after "end-" to TclParseNumber. - */ - ClientData cd; - int t; + if (objPtr->typePtr != &endOffsetType) { + int length; + const char *bytes = TclGetStringFromObj(objPtr, &length); - if (TclIsSpaceProc(bytes[4])) { - return TCL_ERROR; - } - if (TclParseNumber(NULL, objPtr, NULL, bytes+4, length-4, NULL, - TCL_PARSE_INTEGER_ONLY) != TCL_OK) { + if ((*bytes != 'e') || (strncmp(bytes, "end", + (size_t)((length > 3) ? 3 : length)) != 0)) { return TCL_ERROR; } - TclGetNumberFromObj(NULL, objPtr, &cd, &t); - if (t == TCL_NUMBER_BIG) { - /* Truncate to the signed wide range. */ - if (mp_isneg((mp_int *)cd)) { - offset = (bytes[3] == '-') ? LLONG_MAX : LLONG_MIN; + + if (length <= 3) { + offset = 0; + } else if ((length > 4) && ((bytes[3] == '-') || (bytes[3] == '+'))) { + /* + * This is our limited string expression evaluator. Pass everything + * after "end-" to TclParseNumber. + */ + ClientData cd; + int t; + + if (TclIsSpaceProc(bytes[4])) { + return TCL_ERROR; + } + if (TclParseNumber(NULL, objPtr, NULL, bytes+4, length-4, NULL, + TCL_PARSE_INTEGER_ONLY) != TCL_OK) { + return TCL_ERROR; + } + TclGetNumberFromObj(NULL, objPtr, &cd, &t); + if (t == TCL_NUMBER_BIG) { + /* Truncate to the signed wide range. */ + if (mp_isneg((mp_int *)cd)) { + offset = (bytes[3] == '-') ? LLONG_MAX : LLONG_MIN; + } else { + offset = (bytes[3] == '-') ? LLONG_MIN : LLONG_MAX; + } } else { - offset = (bytes[3] == '-') ? LLONG_MIN : LLONG_MAX; + /* assert (t == TCL_NUMBER_INT); */ + offset = (*(Tcl_WideInt *)cd); + if (bytes[3] == '-') { + offset = (offset == LLONG_MIN) ? LLONG_MAX : -offset; + } } } else { - /* assert (t == TCL_NUMBER_INT); */ - offset = (*(Tcl_WideInt *)cd); - if (bytes[3] == '-') { - offset = (offset == LLONG_MIN) ? LLONG_MAX : -offset; - } + return TCL_ERROR; } - } else { - return TCL_ERROR; - } - /* - * The conversion succeeded. Free the old internal rep and set the new - * one. - */ + /* Success. Free the old internal rep and set the new one. */ + TclFreeIntRep(objPtr); + objPtr->internalRep.wideValue = offset; + objPtr->typePtr = &endOffsetType; + } - TclFreeIntRep(objPtr); - objPtr->internalRep.wideValue = offset; - objPtr->typePtr = &endOffsetType; + offset = objPtr->internalRep.wideValue; + if ((endValue ^ offset) < 0) { + /* Different signs, sum cannot overflow */ + *widePtr = endValue + offset; + } else if (endValue >= 0) { + if (endValue < LLONG_MAX - offset) { + *widePtr = endValue + offset; + } else { + *widePtr = LLONG_MAX; + } + } else { + if (endValue > LLONG_MIN - offset) { + *widePtr = endValue + offset; + } else { + *widePtr = LLONG_MIN; + } + } return TCL_OK; } -- cgit v0.12 From 9db751daebe489baa4dd45c402a87af1428b439c Mon Sep 17 00:00:00 2001 From: dgp Date: Tue, 23 Oct 2018 19:01:55 +0000 Subject: End the deprecated practice of accepting "e" and "en" as valid index values. --- generic/tclUtil.c | 8 +++++--- tests/util.test | 8 ++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/generic/tclUtil.c b/generic/tclUtil.c index 954caff..7996703 100644 --- a/generic/tclUtil.c +++ b/generic/tclUtil.c @@ -3935,12 +3935,14 @@ GetEndOffsetFromObj( int length; const char *bytes = TclGetStringFromObj(objPtr, &length); - if ((*bytes != 'e') || (strncmp(bytes, "end", - (size_t)((length > 3) ? 3 : length)) != 0)) { + if ((length < 3) || (length == 4)) { + return TCL_ERROR; + } + if ((*bytes != 'e') || (strncmp(bytes, "end", 3) != 0)) { return TCL_ERROR; } - if (length <= 3) { + if (length == 3) { offset = 0; } else if ((length > 4) && ((bytes[3] == '-') || (bytes[3] == '+'))) { /* diff --git a/tests/util.test b/tests/util.test index 9422fc3..5079a89 100644 --- a/tests/util.test +++ b/tests/util.test @@ -586,14 +586,14 @@ test util-9.2.1 {TclGetIntForIndex} -body { test util-9.2.2 {TclGetIntForIndex} -body { string index abcd {end } } -returnCodes error -match glob -result * -test util-9.3 {TclGetIntForIndex} { +test util-9.3 {TclGetIntForIndex} -body { # Deprecated string index abcd en -} d -test util-9.4 {TclGetIntForIndex} { +} -returnCodes error -match glob -result * +test util-9.4 {TclGetIntForIndex} -body { # Deprecated string index abcd e -} d +} -returnCodes error -match glob -result * test util-9.5.0 {TclGetIntForIndex} { string index abcd end-1 } c -- cgit v0.12 From 7e4b0ec8523a556113f2fa662ed0b0b053d325b8 Mon Sep 17 00:00:00 2001 From: dgp Date: Tue, 23 Oct 2018 19:11:13 +0000 Subject: rework the logic a bit --- generic/tclUtil.c | 57 ++++++++++++++++++++++++++----------------------------- 1 file changed, 27 insertions(+), 30 deletions(-) diff --git a/generic/tclUtil.c b/generic/tclUtil.c index 7996703..6197790 100644 --- a/generic/tclUtil.c +++ b/generic/tclUtil.c @@ -3929,7 +3929,7 @@ GetEndOffsetFromObj( Tcl_WideInt *widePtr) /* Location filled in with an integer * representing an index. */ { - Tcl_WideInt offset; /* Offset in the "end-offset" expression */ + Tcl_WideInt offset = 0; /* Offset in the "end-offset" expression */ if (objPtr->typePtr != &endOffsetType) { int length; @@ -3942,40 +3942,37 @@ GetEndOffsetFromObj( return TCL_ERROR; } - if (length == 3) { - offset = 0; - } else if ((length > 4) && ((bytes[3] == '-') || (bytes[3] == '+'))) { - /* - * This is our limited string expression evaluator. Pass everything - * after "end-" to TclParseNumber. - */ - ClientData cd; - int t; + if (length > 4) { + if ((bytes[3] == '-') || (bytes[3] == '+')) { + ClientData cd; + int t; - if (TclIsSpaceProc(bytes[4])) { - return TCL_ERROR; - } - if (TclParseNumber(NULL, objPtr, NULL, bytes+4, length-4, NULL, - TCL_PARSE_INTEGER_ONLY) != TCL_OK) { - return TCL_ERROR; - } - TclGetNumberFromObj(NULL, objPtr, &cd, &t); - if (t == TCL_NUMBER_BIG) { - /* Truncate to the signed wide range. */ - if (mp_isneg((mp_int *)cd)) { - offset = (bytes[3] == '-') ? LLONG_MAX : LLONG_MIN; + /* Pass everything after "end-" to TclParseNumber. */ + if (TclIsSpaceProc(bytes[4])) { + return TCL_ERROR; + } + if (TCL_OK != TclParseNumber(NULL, objPtr, NULL, + bytes+4, length-4, NULL, TCL_PARSE_INTEGER_ONLY)) { + return TCL_ERROR; + } + TclGetNumberFromObj(NULL, objPtr, &cd, &t); + if (t == TCL_NUMBER_BIG) { + /* Truncate to the signed wide range. */ + if (mp_isneg((mp_int *)cd)) { + offset = (bytes[3] == '-') ? LLONG_MAX : LLONG_MIN; + } else { + offset = (bytes[3] == '-') ? LLONG_MIN : LLONG_MAX; + } } else { - offset = (bytes[3] == '-') ? LLONG_MIN : LLONG_MAX; + /* assert (t == TCL_NUMBER_INT); */ + offset = (*(Tcl_WideInt *)cd); + if (bytes[3] == '-') { + offset = (offset == LLONG_MIN) ? LLONG_MAX : -offset; + } } } else { - /* assert (t == TCL_NUMBER_INT); */ - offset = (*(Tcl_WideInt *)cd); - if (bytes[3] == '-') { - offset = (offset == LLONG_MIN) ? LLONG_MAX : -offset; - } + return TCL_ERROR; } - } else { - return TCL_ERROR; } /* Success. Free the old internal rep and set the new one. */ -- cgit v0.12 From 6457b295e175efa7dd344fc28355da283b64bcbc Mon Sep 17 00:00:00 2001 From: dgp Date: Tue, 23 Oct 2018 23:09:48 +0000 Subject: Streamline and comment combined routine. --- generic/tclUtil.c | 58 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/generic/tclUtil.c b/generic/tclUtil.c index 6197790..fa8c925 100644 --- a/generic/tclUtil.c +++ b/generic/tclUtil.c @@ -3936,42 +3936,52 @@ GetEndOffsetFromObj( const char *bytes = TclGetStringFromObj(objPtr, &length); if ((length < 3) || (length == 4)) { + /* Too short to be "end" or to be "end-$integer" */ return TCL_ERROR; } if ((*bytes != 'e') || (strncmp(bytes, "end", 3) != 0)) { + /* Value doesn't start with "end" */ return TCL_ERROR; } if (length > 4) { - if ((bytes[3] == '-') || (bytes[3] == '+')) { - ClientData cd; - int t; + ClientData cd; + int t; - /* Pass everything after "end-" to TclParseNumber. */ - if (TclIsSpaceProc(bytes[4])) { - return TCL_ERROR; - } - if (TCL_OK != TclParseNumber(NULL, objPtr, NULL, + /* Parse for the "end-..." or "end+..." formats */ + + if ((bytes[3] != '-') && (bytes[3] != '+')) { + /* No operator where we need one */ + return TCL_ERROR; + } + if (TclIsSpaceProc(bytes[4])) { + /* Space after + or - not permitted. */ + return TCL_ERROR; + } + + /* Parse the integer offset */ + if (TCL_OK != TclParseNumber(NULL, objPtr, NULL, bytes+4, length-4, NULL, TCL_PARSE_INTEGER_ONLY)) { - return TCL_ERROR; - } - TclGetNumberFromObj(NULL, objPtr, &cd, &t); - if (t == TCL_NUMBER_BIG) { - /* Truncate to the signed wide range. */ - if (mp_isneg((mp_int *)cd)) { - offset = (bytes[3] == '-') ? LLONG_MAX : LLONG_MIN; - } else { - offset = (bytes[3] == '-') ? LLONG_MIN : LLONG_MAX; - } + /* Not a recognized integer format */ + return TCL_ERROR; + } + + /* Got an integer offset; pull it from where parser left it. */ + TclGetNumberFromObj(NULL, objPtr, &cd, &t); + + if (t == TCL_NUMBER_BIG) { + /* Truncate to the signed wide range. */ + if (mp_isneg((mp_int *)cd)) { + offset = (bytes[3] == '-') ? LLONG_MAX : LLONG_MIN; } else { - /* assert (t == TCL_NUMBER_INT); */ - offset = (*(Tcl_WideInt *)cd); - if (bytes[3] == '-') { - offset = (offset == LLONG_MIN) ? LLONG_MAX : -offset; - } + offset = (bytes[3] == '-') ? LLONG_MIN : LLONG_MAX; } } else { - return TCL_ERROR; + /* assert (t == TCL_NUMBER_INT); */ + offset = (*(Tcl_WideInt *)cd); + if (bytes[3] == '-') { + offset = (offset == LLONG_MIN) ? LLONG_MAX : -offset; + } } } -- cgit v0.12 From 125b29bfe3ceb7ff21f83db0e6b4dd79d28328c3 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Fri, 26 Oct 2018 18:41:35 +0000 Subject: tclWinReg.c: Code cleanup. Eliminate some unnecessary variables. tclWinDde.c: Backport improvements (support for TCL_UTF_MAX=6) from androwish: Both androwish and tclsh (all versions) can now use the same dde.dll. dde: bump version --- library/dde/pkgIndex.tcl | 4 +- tests/registry.test | 8 +- tests/winDde.test | 4 +- win/Makefile.in | 4 +- win/makefile.vc | 2 +- win/tclWinDde.c | 294 +++++++++++++++++++++++++---------------------- win/tclWinReg.c | 32 ++---- 7 files changed, 178 insertions(+), 170 deletions(-) diff --git a/library/dde/pkgIndex.tcl b/library/dde/pkgIndex.tcl index 4cf73d0..7aa67fa 100644 --- a/library/dde/pkgIndex.tcl +++ b/library/dde/pkgIndex.tcl @@ -1,7 +1,7 @@ if {([info commands ::tcl::pkgconfig] eq "") || ([info sharedlibextension] ne ".dll")} return if {[::tcl::pkgconfig get debug]} { - package ifneeded dde 1.4.0 [list load [file join $dir tcldde14g.dll] dde] + package ifneeded dde 1.4.1 [list load [file join $dir tcldde14g.dll] dde] } else { - package ifneeded dde 1.4.0 [list load [file join $dir tcldde14.dll] dde] + package ifneeded dde 1.4.1 [list load [file join $dir tcldde14.dll] dde] } diff --git a/tests/registry.test b/tests/registry.test index b6be074..539ba2d 100644 --- a/tests/registry.test +++ b/tests/registry.test @@ -283,7 +283,7 @@ test registry-4.7 {GetKeyNames: Unicode} {win reg english} { registry delete HKEY_CURRENT_USER\\TclFoobar set result } "baz\u00c7bar blat" -test registry-4.8 {GetKeyNames: Unicode} {win reg nt} { +test registry-4.8 {GetKeyNames: Unicode} {win reg} { registry delete HKEY_CURRENT_USER\\TclFoobar registry set HKEY_CURRENT_USER\\TclFoobar\\baz\u30b7bar registry set HKEY_CURRENT_USER\\TclFoobar\\blat @@ -487,7 +487,7 @@ test registry-6.17 {GetValue: Unicode value names} {win reg} { registry delete HKEY_CURRENT_USER\\TclFoobar set result } foobar -test registry-6.18 {GetValue: values with Unicode strings} {win reg nt} { +test registry-6.18 {GetValue: values with Unicode strings} {win reg} { registry set HKEY_CURRENT_USER\\TclFoobar val1 {foo ba\u30b7r baz} multi_sz set result [registry get HKEY_CURRENT_USER\\TclFoobar val1] registry delete HKEY_CURRENT_USER\\TclFoobar @@ -505,7 +505,7 @@ test registry-6.20 {GetValue: values with Unicode strings with embedded nulls} { registry delete HKEY_CURRENT_USER\\TclFoobar set result } "foo ba r baz" -test registry-6.21 {GetValue: very long value names and values} {pcOnly reg} { +test registry-6.21 {GetValue: very long value names and values} {win reg} { registry set HKEY_CURRENT_USER\\TclFoobar [string repeat k 16383] [string repeat x 16383] multi_sz set result [registry get HKEY_CURRENT_USER\\TclFoobar [string repeat k 16383]] registry delete HKEY_CURRENT_USER\\TclFoobar @@ -604,7 +604,7 @@ test registry-9.3 {ParseKeyName: bad keys} -constraints {win reg} -body { test registry-9.4 {ParseKeyName: bad keys} -constraints {win reg} -body { registry values \\\\\\ } -returnCodes error -result {bad root name "": must be HKEY_LOCAL_MACHINE, HKEY_USERS, HKEY_CLASSES_ROOT, HKEY_CURRENT_USER, HKEY_CURRENT_CONFIG, HKEY_PERFORMANCE_DATA, or HKEY_DYN_DATA} -test registry-9.5 {ParseKeyName: bad keys} -constraints {win reg english nt} -body { +test registry-9.5 {ParseKeyName: bad keys} -constraints {win reg english} -body { registry values \\\\\\HKEY_CLASSES_ROOT } -returnCodes error -result {unable to open key: The network address is invalid.} test registry-9.6 {ParseKeyName: bad keys} -constraints {win reg} -body { diff --git a/tests/winDde.test b/tests/winDde.test index f04fb45..1fa7e86 100644 --- a/tests/winDde.test +++ b/tests/winDde.test @@ -20,7 +20,7 @@ testConstraint dde 0 if {[testConstraint win]} { if {![catch { ::tcltest::loadTestedCommands - set ::ddever [package require dde 1.4.0] + set ::ddever [package require dde 1.4.1] set ::ddelib [lindex [package ifneeded dde $::ddever] 1]}]} { testConstraint dde 1 } @@ -104,7 +104,7 @@ proc createChildProcess {ddeServerName args} { # ------------------------------------------------------------------------- test winDde-1.0 {check if we are testing the right dll} {win dde} { set ::ddever -} {1.4.0} +} {1.4.1} test winDde-1.1 {Settings the server's topic name} -constraints dde -body { list [dde servername foobar] [dde servername] [dde servername self] diff --git a/win/Makefile.in b/win/Makefile.in index a8d487b..8ce57f2 100644 --- a/win/Makefile.in +++ b/win/Makefile.in @@ -712,14 +712,14 @@ test-tcl: binaries $(TCLSH) $(CAT32) $(TEST_DLL_FILE) TCL_LIBRARY="$(LIBRARY_DIR)"; export TCL_LIBRARY; \ ./$(TCLSH) "$(ROOT_DIR_NATIVE)/tests/all.tcl" $(TESTFLAGS) \ -load "package ifneeded Tcltest ${VERSION}@TCL_PATCH_LEVEL@ [list load [file normalize ${TEST_DLL_FILE}] Tcltest]; \ - package ifneeded dde 1.4.0 [list load [file normalize ${DDE_DLL_FILE}] dde]; \ + package ifneeded dde 1.4.1 [list load [file normalize ${DDE_DLL_FILE}] dde]; \ package ifneeded registry 1.3.3 [list load [file normalize ${REG_DLL_FILE}] registry]" | ./$(CAT32) # Useful target to launch a built tclsh with the proper path,... runtest: binaries $(TCLSH) $(TEST_DLL_FILE) @TCL_LIBRARY="$(LIBRARY_DIR)"; export TCL_LIBRARY; \ ./$(TCLSH) $(TESTFLAGS) -load "package ifneeded Tcltest ${VERSION}@TCL_PATCH_LEVEL@ [list load [file normalize ${TEST_DLL_FILE}] Tcltest]; \ - package ifneeded dde 1.4.0 [list load [file normalize ${DDE_DLL_FILE}] dde]; \ + package ifneeded dde 1.4.1 [list load [file normalize ${DDE_DLL_FILE}] dde]; \ package ifneeded registry 1.3.3 [list load [file normalize ${REG_DLL_FILE}] registry]" $(SCRIPT) # This target can be used to run tclsh from the build directory via diff --git a/win/makefile.vc b/win/makefile.vc index 337a894..0e1e1fd 100644 --- a/win/makefile.vc +++ b/win/makefile.vc @@ -384,7 +384,7 @@ test: test-core test-pkgs test-core: setup $(TCLTEST) dlls $(CAT32) set TCL_LIBRARY=$(ROOT:\=/)/library $(DEBUGGER) $(TCLTEST) "$(ROOT:\=/)/tests/all.tcl" $(TESTFLAGS) -loadfile << - package ifneeded dde 1.4.0 [list load "$(TCLDDELIB:\=/)" dde] + package ifneeded dde 1.4.1 [list load "$(TCLDDELIB:\=/)" dde] package ifneeded registry 1.3.3 [list load "$(TCLREGLIB:\=/)" registry] << diff --git a/win/tclWinDde.c b/win/tclWinDde.c index ce0b413..6908fdf 100644 --- a/win/tclWinDde.c +++ b/win/tclWinDde.c @@ -18,15 +18,6 @@ #include #include -#ifndef UNICODE -# undef CP_WINUNICODE -# define CP_WINUNICODE CP_WINANSI -# undef Tcl_WinTCharToUtf -# define Tcl_WinTCharToUtf(a,b,c) Tcl_ExternalToUtfDString(NULL,a,b,c) -# undef Tcl_WinUtfToTChar -# define Tcl_WinUtfToTChar(a,b,c) Tcl_UtfToExternalDString(NULL,a,b,c) -#endif - #if !defined(NDEBUG) /* test POKE server Implemented for debug mode only */ # undef CBF_FAIL_POKES @@ -34,16 +25,6 @@ #endif /* - * TCL_STORAGE_CLASS is set unconditionally to DLLEXPORT because the Dde_Init - * declaration is in the source file itself, which is only accessed when we - * are building a library. DO NOT MOVE BEFORE ANY #include LINES. ONLY USE - * EXTERN TO INDICATE EXPORTED FUNCTIONS FROM NOW ON. - */ - -#undef TCL_STORAGE_CLASS -#define TCL_STORAGE_CLASS DLLEXPORT - -/* * The following structure is used to keep track of the interpreters * registered by this process. */ @@ -69,7 +50,7 @@ typedef struct Conversation { Tcl_Obj *returnPackagePtr; /* The result package for this conversation. */ } Conversation; -typedef struct DdeEnumServices { +typedef struct { Tcl_Interp *interp; int result; ATOM service; @@ -77,7 +58,7 @@ typedef struct DdeEnumServices { HWND hwnd; } DdeEnumServices; -typedef struct ThreadSpecificData { +typedef struct { Conversation *currentConversations; /* A list of conversations currently being * processed. */ @@ -97,7 +78,7 @@ static DWORD ddeInstance; /* The application instance handle given to us * by DdeInitialize. */ static int ddeIsServer = 0; -#define TCL_DDE_VERSION "1.4.0" +#define TCL_DDE_VERSION "1.4.1" #define TCL_DDE_PACKAGE_NAME "dde" #define TCL_DDE_SERVICE_NAME TEXT("TclEval") #define TCL_DDE_EXECUTE_RESULT TEXT("$TCLEVAL$EXECUTE$RESULT") @@ -114,7 +95,7 @@ TCL_DECLARE_MUTEX(ddeMutex) static LRESULT CALLBACK DdeClientWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); -static int DdeCreateClient(struct DdeEnumServices *es); +static int DdeCreateClient(DdeEnumServices *es); static BOOL CALLBACK DdeEnumWindowsCallback(HWND hwndTarget, LPARAM lParam); static void DdeExitProc(ClientData clientData); @@ -135,8 +116,9 @@ static int DdeObjCmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); -EXTERN int Dde_Init(Tcl_Interp *interp); -EXTERN int Dde_SafeInit(Tcl_Interp *interp); + +DLLEXPORT int Dde_Init(Tcl_Interp *interp); +DLLEXPORT int Dde_SafeInit(Tcl_Interp *interp); /* *---------------------------------------------------------------------- @@ -162,13 +144,6 @@ Dde_Init( return TCL_ERROR; } -#ifdef UNICODE - if (TclWinGetPlatformId() < VER_PLATFORM_WIN32_NT) { - Tcl_SetObjResult(interp, Tcl_NewStringObj( - "Win32s and Windows 9x are not supported platforms", -1)); - return TCL_ERROR; - } -#endif Tcl_CreateObjCommand(interp, "dde", DdeObjCmd, NULL, NULL); Tcl_CreateExitHandler(DdeExitProc, NULL); return Tcl_PkgProvide(interp, TCL_DDE_PACKAGE_NAME, TCL_DDE_VERSION); @@ -399,7 +374,7 @@ DdeSetServerName( Tcl_DString ds; Tcl_ListObjIndex(interp, srvPtrPtr[n], 1, &namePtr); - Tcl_WinUtfToTChar(Tcl_GetString(namePtr), -1, &ds); + Tcl_WinUtfToTChar(Tcl_GetString(namePtr), -1, &ds); if (_tcscmp(actualName, (TCHAR *)Tcl_DStringValue(&ds)) == 0) { suffix++; Tcl_DStringFree(&ds); @@ -414,9 +389,9 @@ DdeSetServerName( * We have found a unique name. Now add it to the registry. */ - riPtr = ckalloc(sizeof(RegisteredInterp)); + riPtr = (RegisteredInterp *) Tcl_Alloc(sizeof(RegisteredInterp)); riPtr->interp = interp; - riPtr->name = ckalloc((_tcslen(actualName) + 1) * sizeof(TCHAR)); + riPtr->name = (TCHAR *) Tcl_Alloc((_tcslen(actualName) + 1) * sizeof(TCHAR)); riPtr->nextPtr = tsdPtr->interpListPtr; riPtr->handlerPtr = handlerPtr; if (riPtr->handlerPtr != NULL) { @@ -517,7 +492,7 @@ DeleteProc( prevPtr->nextPtr = searchPtr->nextPtr; } } - ckfree(riPtr->name); + Tcl_Free((char *) riPtr->name); if (riPtr->handlerPtr) { Tcl_DecrRefCount(riPtr->handlerPtr); } @@ -555,7 +530,7 @@ ExecuteRemoteObject( Tcl_Obj *returnPackagePtr; int result = TCL_OK; - if (riPtr->handlerPtr == NULL && Tcl_IsSafe(riPtr->interp)) { + if ((riPtr->handlerPtr == NULL) && Tcl_IsSafe(riPtr->interp)) { Tcl_SetObjResult(riPtr->interp, Tcl_NewStringObj("permission denied: " "a handler procedure must be defined for use in a safe " "interp", -1)); @@ -637,7 +612,7 @@ DdeServerProc( /* Transaction-dependent data. */ { Tcl_DString dString; - int len; + size_t len; DWORD dlen; TCHAR *utilString; Tcl_Obj *ddeObjectPtr; @@ -687,7 +662,7 @@ DdeServerProc( for (riPtr = tsdPtr->interpListPtr; riPtr != NULL; riPtr = riPtr->nextPtr) { if (_tcsicmp(riPtr->name, utilString) == 0) { - convPtr = ckalloc(sizeof(Conversation)); + convPtr = (Conversation *) Tcl_Alloc(sizeof(Conversation)); convPtr->nextPtr = tsdPtr->currentConversations; convPtr->returnPackagePtr = NULL; convPtr->hConv = hConv; @@ -717,7 +692,7 @@ DdeServerProc( if (convPtr->returnPackagePtr != NULL) { Tcl_DecrRefCount(convPtr->returnPackagePtr); } - ckfree(convPtr); + Tcl_Free((char *) convPtr); break; } } @@ -743,22 +718,24 @@ DdeServerProc( } if (convPtr != NULL) { + Tcl_DString dsBuf; char *returnString; len = DdeQueryString(ddeInstance, ddeItem, NULL, 0, CP_WINUNICODE); Tcl_DStringInit(&dString); + Tcl_DStringInit(&dsBuf); Tcl_DStringSetLength(&dString, (len + 1) * sizeof(TCHAR) - 1); utilString = (TCHAR *) Tcl_DStringValue(&dString); DdeQueryString(ddeInstance, ddeItem, utilString, (DWORD) len + 1, CP_WINUNICODE); if (_tcsicmp(utilString, TCL_DDE_EXECUTE_RESULT) == 0) { - if (uFmt == CF_TEXT) { - returnString = - Tcl_GetStringFromObj(convPtr->returnPackagePtr, &len); - } else { - returnString = (char *) - Tcl_GetUnicodeFromObj(convPtr->returnPackagePtr, &len); - len = sizeof(TCHAR) * len + 1; + returnString = + Tcl_GetString(convPtr->returnPackagePtr); + len = convPtr->returnPackagePtr->length; + if (uFmt != CF_TEXT) { + Tcl_WinUtfToTChar(returnString, len, &dsBuf); + returnString = Tcl_DStringValue(&dsBuf); + len = Tcl_DStringLength(&dsBuf) + sizeof(TCHAR) - 1; } ddeReturn = DdeCreateDataHandle(ddeInstance, (BYTE *)returnString, (DWORD) len+1, 0, ddeItem, uFmt, 0); @@ -768,18 +745,18 @@ DdeServerProc( } else { Tcl_DString ds; Tcl_Obj *variableObjPtr; + Tcl_WinTCharToUtf(utilString, -1, &ds); variableObjPtr = Tcl_GetVar2Ex( convPtr->riPtr->interp, Tcl_DStringValue(&ds), NULL, TCL_GLOBAL_ONLY); if (variableObjPtr != NULL) { - if (uFmt == CF_TEXT) { - returnString = Tcl_GetStringFromObj( - variableObjPtr, &len); - } else { - returnString = (char *) Tcl_GetUnicodeFromObj( - variableObjPtr, &len); - len = sizeof(TCHAR) * len + 1; + returnString = Tcl_GetString(variableObjPtr); + len = variableObjPtr->length; + if (uFmt != CF_TEXT) { + Tcl_WinUtfToTChar(returnString, len, &dsBuf); + returnString = Tcl_DStringValue(&dsBuf); + len = Tcl_DStringLength(&dsBuf) + sizeof(TCHAR) - 1; } ddeReturn = DdeCreateDataHandle(ddeInstance, (BYTE *)returnString, (DWORD) len+1, 0, ddeItem, @@ -790,6 +767,7 @@ DdeServerProc( Tcl_DStringFree(&ds); } } + Tcl_DStringFree(&dsBuf); Tcl_DStringFree(&dString); } return ddeReturn; @@ -814,26 +792,30 @@ DdeServerProc( } if (convPtr && !Tcl_IsSafe(convPtr->riPtr->interp)) { - Tcl_DString ds; + Tcl_DString ds, ds2; Tcl_Obj *variableObjPtr; + DWORD len2; - len = DdeQueryString(ddeInstance, ddeItem, NULL, 0, CP_WINUNICODE); Tcl_DStringInit(&dString); + Tcl_DStringInit(&ds2); + len = DdeQueryString(ddeInstance, ddeItem, NULL, 0, CP_WINUNICODE); Tcl_DStringSetLength(&dString, (len + 1) * sizeof(TCHAR) - 1); utilString = (TCHAR *) Tcl_DStringValue(&dString); DdeQueryString(ddeInstance, ddeItem, utilString, (DWORD) len + 1, CP_WINUNICODE); Tcl_WinTCharToUtf(utilString, -1, &ds); - utilString = (TCHAR *) DdeAccessData(hData, &dlen); - if (uFmt == CF_TEXT) { - variableObjPtr = Tcl_NewStringObj((char *)utilString, -1); - } else { - variableObjPtr = Tcl_NewUnicodeObj(utilString, -1); + utilString = (TCHAR *) DdeAccessData(hData, &len2); + len = len2; + if (uFmt != CF_TEXT) { + Tcl_WinTCharToUtf(utilString, -1, &ds2); + utilString = (TCHAR *) Tcl_DStringValue(&ds2); } + variableObjPtr = Tcl_NewStringObj((char *)utilString, -1); Tcl_SetVar2Ex(convPtr->riPtr->interp, Tcl_DStringValue(&ds), NULL, variableObjPtr, TCL_GLOBAL_ONLY); + Tcl_DStringFree(&ds2); Tcl_DStringFree(&ds); Tcl_DStringFree(&dString); ddeReturn = (HDDEDATA) DDE_FACK; @@ -874,8 +856,12 @@ DdeServerProc( ddeObjectPtr = Tcl_NewStringObj(string, dlen); } else { /* unicode */ - dlen >>= 1; - ddeObjectPtr = Tcl_NewUnicodeObj((Tcl_UniChar *)utilString, dlen - 1); + Tcl_DString dsBuf; + + Tcl_WinTCharToUtf(utilString, dlen - sizeof(TCHAR), &dsBuf); + ddeObjectPtr = Tcl_NewStringObj(Tcl_DStringValue(&dsBuf), + Tcl_DStringLength(&dsBuf)); + Tcl_DStringFree(&dsBuf); } Tcl_IncrRefCount(ddeObjectPtr); DdeUnaccessData(hData); @@ -1040,7 +1026,7 @@ MakeDdeConnection( static int DdeCreateClient( - struct DdeEnumServices *es) + DdeEnumServices *es) { WNDCLASSEX wc; static const TCHAR *szDdeClientClassName = TEXT("TclEval client class"); @@ -1050,7 +1036,7 @@ DdeCreateClient( wc.cbSize = sizeof(wc); wc.lpfnWndProc = DdeClientWindowProc; wc.lpszClassName = szDdeClientClassName; - wc.cbWndExtra = sizeof(struct DdeEnumServices *); + wc.cbWndExtra = sizeof(DdeEnumServices *); /* * Register and create the callback window. @@ -1072,8 +1058,8 @@ DdeClientWindowProc( switch (uMsg) { case WM_CREATE: { LPCREATESTRUCT lpcs = (LPCREATESTRUCT) lParam; - struct DdeEnumServices *es = - (struct DdeEnumServices *) lpcs->lpCreateParams; + DdeEnumServices *es = + (DdeEnumServices *) lpcs->lpCreateParams; #ifdef _WIN64 SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR) es); @@ -1098,18 +1084,18 @@ DdeServicesOnAck( HWND hwndRemote = (HWND)wParam; ATOM service = (ATOM)LOWORD(lParam); ATOM topic = (ATOM)HIWORD(lParam); - struct DdeEnumServices *es; + DdeEnumServices *es; TCHAR sz[255]; Tcl_DString dString; #ifdef _WIN64 - es = (struct DdeEnumServices *) GetWindowLongPtr(hwnd, GWLP_USERDATA); + es = (DdeEnumServices *) GetWindowLongPtr(hwnd, GWLP_USERDATA); #else - es = (struct DdeEnumServices *) GetWindowLong(hwnd, GWL_USERDATA); + es = (DdeEnumServices *) GetWindowLong(hwnd, GWL_USERDATA); #endif - if ((es->service == (ATOM)0 || es->service == service) - && (es->topic == (ATOM)0 || es->topic == topic)) { + if (((es->service == (ATOM)0) || (es->service == service)) + && ((es->topic == (ATOM)0) || (es->topic == topic))) { Tcl_Obj *matchPtr = Tcl_NewListObj(0, NULL); Tcl_Obj *resultPtr = Tcl_GetObjResult(es->interp); @@ -1156,7 +1142,7 @@ DdeEnumWindowsCallback( LPARAM lParam) { DWORD_PTR dwResult = 0; - struct DdeEnumServices *es = (struct DdeEnumServices *) lParam; + DdeEnumServices *es = (DdeEnumServices *) lParam; SendMessageTimeout(hwndTarget, WM_DDE_INITIATE, (WPARAM)es->hwnd, MAKELONG(es->service, es->topic), SMTO_ABORTIFHUNG, 1000, @@ -1170,7 +1156,7 @@ DdeGetServicesList( const TCHAR *serviceName, const TCHAR *topicName) { - struct DdeEnumServices es; + DdeEnumServices es; es.interp = interp; es.result = TCL_OK; @@ -1291,7 +1277,8 @@ DdeObjCmd( "-binary", NULL }; - int index, i, length, argIndex; + int index, i, argIndex; + int length; int flags = 0, result = TCL_OK, firstArg = 0; HSZ ddeService = NULL, ddeTopic = NULL, ddeItem = NULL, ddeCookie = NULL; HDDEDATA ddeData = NULL, ddeItemData = NULL, ddeReturn; @@ -1300,6 +1287,7 @@ DdeObjCmd( const char *string; DWORD ddeResult; Tcl_Obj *objPtr, *handlerPtr = NULL; + Tcl_DString serviceBuf, topicBuf, itemBuf; /* * Initialize DDE server/client @@ -1315,6 +1303,9 @@ DdeObjCmd( return TCL_ERROR; } + Tcl_DStringInit(&serviceBuf); + Tcl_DStringInit(&topicBuf); + Tcl_DStringInit(&itemBuf); switch ((enum DdeSubcommands) index) { case DDE_SERVERNAME: for (i = 2; i < objc; i++) { @@ -1364,7 +1355,7 @@ DdeObjCmd( if (objc == 5) { firstArg = 2; break; - } else if (objc >= 6 && objc <= 7) { + } else if ((objc >= 6) && (objc <= 7)) { firstArg = objc - 3; for (i = 2; i < firstArg; i++) { if (Tcl_GetIndexFromObj(interp, objv[i], ddeExecOptions, @@ -1449,11 +1440,12 @@ DdeObjCmd( Initialize(); if (firstArg != 1) { -#ifdef UNICODE - serviceName = Tcl_GetUnicodeFromObj(objv[firstArg], &length); -#else - serviceName = Tcl_GetStringFromObj(objv[firstArg], &length); -#endif + const char *src = Tcl_GetString(objv[firstArg]); + + length = objv[firstArg]->length; + Tcl_WinUtfToTChar(src, length, &serviceBuf); + serviceName = (TCHAR *) Tcl_DStringValue(&serviceBuf); + length = Tcl_DStringLength(&serviceBuf) / sizeof(TCHAR); } else { length = 0; } @@ -1466,11 +1458,11 @@ DdeObjCmd( } if ((index != DDE_SERVERNAME) && (index != DDE_EVAL)) { -#ifdef UNICODE - topicName = (TCHAR *) Tcl_GetUnicodeFromObj(objv[firstArg + 1], &length); -#else - topicName = Tcl_GetStringFromObj(objv[firstArg + 1], &length); -#endif + const char *src = Tcl_GetString(objv[firstArg + 1]); + + length = objv[firstArg + 1]->length; + topicName = Tcl_WinUtfToTChar(src, length, &topicBuf); + length = Tcl_DStringLength(&topicBuf) / sizeof(TCHAR); if (length == 0) { topicName = NULL; } else { @@ -1484,11 +1476,12 @@ DdeObjCmd( serviceName = DdeSetServerName(interp, serviceName, flags, handlerPtr); if (serviceName != NULL) { -#ifdef UNICODE - Tcl_SetObjResult(interp, Tcl_NewUnicodeObj((Tcl_UniChar *) serviceName, -1)); -#else - Tcl_SetObjResult(interp, Tcl_NewStringObj(serviceName, -1)); -#endif + Tcl_DString dsBuf; + + Tcl_WinTCharToUtf(serviceName, -1, &dsBuf); + Tcl_SetObjResult(interp, Tcl_NewStringObj(Tcl_DStringValue(&dsBuf), + Tcl_DStringLength(&dsBuf))); + Tcl_DStringFree(&dsBuf); } else { Tcl_ResetResult(interp); } @@ -1496,20 +1489,27 @@ DdeObjCmd( case DDE_EXECUTE: { int dataLength; - const Tcl_UniChar *dataString; + const void *dataString; + Tcl_DString dsBuf; + Tcl_DStringInit(&dsBuf); if (flags & DDE_FLAG_BINARY) { - dataString = (const Tcl_UniChar *) + dataString = Tcl_GetByteArrayFromObj(objv[firstArg + 2], &dataLength); } else { - dataString = - Tcl_GetUnicodeFromObj(objv[firstArg + 2], &dataLength); - dataLength = (dataLength + 1) * sizeof(Tcl_UniChar); + const char *src; + + src = Tcl_GetString(objv[firstArg + 2]); + dataLength = objv[firstArg + 2]->length; + dataString = (const TCHAR *) + Tcl_WinUtfToTChar(src, dataLength, &dsBuf); + dataLength = Tcl_DStringLength(&dsBuf) + sizeof(TCHAR); } - if (dataLength <= 0) { + if (dataLength + 1 < 2) { Tcl_SetObjResult(interp, Tcl_NewStringObj("cannot execute null data", -1)); + Tcl_DStringFree(&dsBuf); Tcl_SetErrorCode(interp, "TCL", "DDE", "NULL", NULL); result = TCL_ERROR; break; @@ -1519,6 +1519,7 @@ DdeObjCmd( DdeFreeStringHandle(ddeInstance, ddeTopic); if (hConv == NULL) { + Tcl_DStringFree(&dsBuf); SetDdeError(interp); result = TCL_ERROR; break; @@ -1544,16 +1545,17 @@ DdeObjCmd( SetDdeError(interp); result = TCL_ERROR; } + Tcl_DStringFree(&dsBuf); break; } case DDE_REQUEST: { -#ifdef UNICODE - const TCHAR *itemString = (TCHAR *) Tcl_GetUnicodeFromObj(objv[firstArg + 2], - &length); -#else - const TCHAR *itemString = Tcl_GetStringFromObj(objv[firstArg + 2], - &length); -#endif + const TCHAR *itemString; + const char *src; + + src = Tcl_GetString(objv[firstArg + 2]); + length = objv[firstArg + 2]->length; + itemString = Tcl_WinUtfToTChar(src, length, &itemBuf); + length = Tcl_DStringLength(&itemBuf) / sizeof(TCHAR); if (length == 0) { Tcl_SetObjResult(interp, @@ -1581,18 +1583,23 @@ DdeObjCmd( result = TCL_ERROR; } else { DWORD tmp; - const Tcl_UniChar *dataString = (const Tcl_UniChar *) DdeAccessData(ddeData, &tmp); + TCHAR *dataString = (TCHAR *) DdeAccessData(ddeData, &tmp); if (flags & DDE_FLAG_BINARY) { returnObjPtr = - Tcl_NewByteArrayObj((BYTE *) dataString, (int) tmp); + Tcl_NewByteArrayObj((BYTE *) dataString, tmp); } else { - tmp >>= 1; - if (tmp && !dataString[(tmp-1)]) { - --tmp; + Tcl_DString dsBuf; + + if ((tmp >= sizeof(TCHAR)) + && !dataString[tmp / sizeof(TCHAR) - 1]) { + tmp -= sizeof(TCHAR); } - returnObjPtr = Tcl_NewUnicodeObj(dataString, - (int) tmp); + Tcl_WinTCharToUtf(dataString, tmp, &dsBuf); + returnObjPtr = + Tcl_NewStringObj(Tcl_DStringValue(&dsBuf), + Tcl_DStringLength(&dsBuf)); + Tcl_DStringFree(&dsBuf); } DdeUnaccessData(ddeData); DdeFreeDataHandle(ddeData); @@ -1603,19 +1610,18 @@ DdeObjCmd( result = TCL_ERROR; } } - break; } case DDE_POKE: { -#ifdef UNICODE - const TCHAR *itemString = (TCHAR *) Tcl_GetUnicodeFromObj(objv[firstArg + 2], - &length); -#else - const TCHAR *itemString = Tcl_GetStringFromObj(objv[firstArg + 2], - &length); -#endif + Tcl_DString dsBuf; + const TCHAR *itemString; BYTE *dataString; + const char *src; + src = Tcl_GetString(objv[firstArg + 2]); + length = objv[firstArg + 2]->length; + itemString = Tcl_WinUtfToTChar(src, length, &itemBuf); + length = Tcl_DStringLength(&itemBuf) / sizeof(TCHAR); if (length == 0) { Tcl_SetObjResult(interp, Tcl_NewStringObj("cannot have a null item", -1)); @@ -1623,13 +1629,17 @@ DdeObjCmd( result = TCL_ERROR; goto cleanup; } + Tcl_DStringInit(&dsBuf); if (flags & DDE_FLAG_BINARY) { dataString = (BYTE *) Tcl_GetByteArrayFromObj(objv[firstArg + 3], &length); } else { + const char *data = + Tcl_GetString(objv[firstArg + 3]); + length = objv[firstArg + 3]->length; dataString = (BYTE *) - Tcl_GetUnicodeFromObj(objv[firstArg + 3], &length); - length = 2 * length + 1; + Tcl_WinUtfToTChar(data, length, &dsBuf); + length = Tcl_DStringLength(&dsBuf) + sizeof(TCHAR); } hConv = DdeConnect(ddeInstance, ddeService, ddeTopic, NULL); @@ -1654,6 +1664,7 @@ DdeObjCmd( result = TCL_ERROR; } } + Tcl_DStringFree(&dsBuf); break; } @@ -1712,7 +1723,7 @@ DdeObjCmd( * referring to deallocated objects. */ - if (Tcl_IsSafe(riPtr->interp) && riPtr->handlerPtr == NULL) { + if (Tcl_IsSafe(riPtr->interp) && (riPtr->handlerPtr == NULL)) { Tcl_SetObjResult(riPtr->interp, Tcl_NewStringObj( "permission denied: a handler procedure must be" " defined for use in a safe interp", -1)); @@ -1757,8 +1768,7 @@ DdeObjCmd( objPtr = Tcl_GetVar2Ex(sendInterp, "errorInfo", NULL, TCL_GLOBAL_ONLY); if (objPtr) { - string = Tcl_GetStringFromObj(objPtr, &length); - Tcl_AddObjErrorInfo(interp, string, length); + Tcl_AppendObjToErrorInfo(interp, objPtr); } objPtr = Tcl_GetVar2Ex(sendInterp, "errorCode", NULL, @@ -1772,6 +1782,8 @@ DdeObjCmd( Tcl_Release(riPtr); Tcl_Release(sendInterp); } else { + Tcl_DString dsBuf; + /* * This is a non-local request. Send the script to the server and * poll it for a result. @@ -1787,9 +1799,14 @@ DdeObjCmd( } objPtr = Tcl_ConcatObj(objc, objv); - string = (const char *) Tcl_GetUnicodeFromObj(objPtr, &length); - ddeItemData = DdeCreateDataHandle(ddeInstance, - (BYTE *) string, (DWORD) 2*length+2, 0, 0, CF_UNICODETEXT, 0); + string = Tcl_GetString(objPtr); + length = objPtr->length; + Tcl_WinUtfToTChar(string, length, &dsBuf); + string = Tcl_DStringValue(&dsBuf); + length = Tcl_DStringLength(&dsBuf) + sizeof(TCHAR); + ddeItemData = DdeCreateDataHandle(ddeInstance, (BYTE *) string, + (DWORD) length, 0, 0, CF_UNICODETEXT, 0); + Tcl_DStringFree(&dsBuf); if (flags & DDE_FLAG_ASYNC) { ddeData = DdeClientTransaction((LPBYTE) ddeItemData, @@ -1818,7 +1835,7 @@ DdeObjCmd( if (!(flags & DDE_FLAG_ASYNC)) { Tcl_Obj *resultPtr; - Tcl_UniChar *ddeDataString; + TCHAR *ddeDataString; /* * The return handle has a two or four element list in it. The @@ -1829,13 +1846,17 @@ DdeObjCmd( * variable "errorInfo". */ - resultPtr = Tcl_NewObj(); length = DdeGetData(ddeData, NULL, 0, 0); - ddeDataString = ckalloc(length); + ddeDataString = (TCHAR *) Tcl_Alloc(length); DdeGetData(ddeData, (BYTE *) ddeDataString, (DWORD) length, 0); - length = (length >> 1) - 1; - resultPtr = Tcl_NewUnicodeObj(ddeDataString, length); - ckfree(ddeDataString); + if (length > sizeof(TCHAR)) { + length -= sizeof(TCHAR); + } + Tcl_WinTCharToUtf(ddeDataString, length, &dsBuf); + resultPtr = Tcl_NewStringObj(Tcl_DStringValue(&dsBuf), + Tcl_DStringLength(&dsBuf)); + Tcl_DStringFree(&dsBuf); + Tcl_Free((char *) ddeDataString); if (Tcl_ListObjIndex(NULL, resultPtr, 0, &objPtr) != TCL_OK) { Tcl_DecrRefCount(resultPtr); @@ -1853,9 +1874,7 @@ DdeObjCmd( Tcl_DecrRefCount(resultPtr); goto invalidServerResponse; } - length = -1; - string = Tcl_GetStringFromObj(objPtr, &length); - Tcl_AddObjErrorInfo(interp, string, length); + Tcl_AppendObjToErrorInfo(interp, objPtr); Tcl_ListObjIndex(NULL, resultPtr, 2, &objPtr); Tcl_SetObjErrorCode(interp, objPtr); @@ -1887,6 +1906,9 @@ DdeObjCmd( if (hConv != NULL) { DdeDisconnect(hConv); } + Tcl_DStringFree(&itemBuf); + Tcl_DStringFree(&topicBuf); + Tcl_DStringFree(&serviceBuf); return result; } diff --git a/win/tclWinReg.c b/win/tclWinReg.c index f3d7a07..0d2cd94 100644 --- a/win/tclWinReg.c +++ b/win/tclWinReg.c @@ -492,7 +492,6 @@ DeleteValue( { HKEY key; char *valueName; - size_t length; DWORD result; Tcl_DString ds; @@ -506,8 +505,7 @@ DeleteValue( } valueName = Tcl_GetString(valueNameObj); - length = valueNameObj->length; - Tcl_WinUtfToTChar(valueName, length, &ds); + Tcl_WinUtfToTChar(valueName, valueNameObj->length, &ds); result = RegDeleteValue(key, (const TCHAR *)Tcl_DStringValue(&ds)); Tcl_DStringFree(&ds); if (result != ERROR_SUCCESS) { @@ -647,7 +645,6 @@ GetType( Tcl_DString ds; const char *valueName; const TCHAR *nativeValue; - size_t length; /* * Attempt to open the key for reading. @@ -663,8 +660,7 @@ GetType( */ valueName = Tcl_GetString(valueNameObj); - length = valueNameObj->length; - nativeValue = Tcl_WinUtfToTChar(valueName, length, &ds); + nativeValue = Tcl_WinUtfToTChar(valueName, valueNameObj->length, &ds); result = RegQueryValueEx(key, nativeValue, NULL, &type, NULL, NULL); Tcl_DStringFree(&ds); @@ -720,7 +716,6 @@ GetValue( const TCHAR *nativeValue; DWORD result, length, type; Tcl_DString data, buf; - size_t nameLen; /* * Attempt to open the key for reading. @@ -746,8 +741,7 @@ GetValue( length = TCL_DSTRING_STATIC_SIZE/sizeof(TCHAR) - 1; valueName = Tcl_GetString(valueNameObj); - nameLen = valueNameObj->length; - nativeValue = Tcl_WinUtfToTChar(valueName, nameLen, &buf); + nativeValue = Tcl_WinUtfToTChar(valueName, valueNameObj->length, &buf); result = RegQueryValueEx(key, nativeValue, NULL, &type, (BYTE *) Tcl_DStringValue(&data), &length); @@ -936,13 +930,11 @@ OpenKey( HKEY *keyPtr) /* Returned HKEY. */ { char *keyName, *buffer, *hostName; - size_t length; HKEY rootKey; DWORD result; keyName = Tcl_GetString(keyNameObj); - length = keyNameObj->length; - buffer = Tcl_Alloc(length + 1); + buffer = Tcl_Alloc(keyNameObj->length + 1); strcpy(buffer, keyName); result = ParseKeyName(interp, buffer, &hostName, &rootKey, &keyName); @@ -1244,7 +1236,6 @@ SetValue( REGSAM mode) /* Mode flags to pass. */ { int type; - size_t length; DWORD result; HKEY key; const char *valueName; @@ -1265,8 +1256,7 @@ SetValue( } valueName = Tcl_GetString(valueNameObj); - length = valueNameObj->length; - valueName = (char *) Tcl_WinUtfToTChar(valueName, length, &nameBuf); + valueName = (char *) Tcl_WinUtfToTChar(valueName, valueNameObj->length, &nameBuf); if (type == REG_DWORD || type == REG_DWORD_BIG_ENDIAN) { int value; @@ -1301,8 +1291,7 @@ SetValue( for (i = 0; i < objc; i++) { const char *bytes = Tcl_GetString(objv[i]); - length = objv[i]->length; - Tcl_DStringAppend(&data, bytes, length); + Tcl_DStringAppend(&data, bytes, objv[i]->length); /* * Add a null character to separate this value from the next. @@ -1322,18 +1311,16 @@ SetValue( Tcl_DString buf; const char *data = Tcl_GetString(dataObj); - length = dataObj->length; - data = (char *) Tcl_WinUtfToTChar(data, length, &buf); + data = (char *) Tcl_WinUtfToTChar(data, dataObj->length, &buf); /* * Include the null in the length, padding if needed for WCHAR. */ Tcl_DStringSetLength(&buf, Tcl_DStringLength(&buf)+1); - length = Tcl_DStringLength(&buf) + 1; result = RegSetValueEx(key, (TCHAR *) valueName, 0, - (DWORD) type, (BYTE *) data, (DWORD) length); + (DWORD) type, (BYTE *) data, (DWORD) Tcl_DStringLength(&buf) + 1); Tcl_DStringFree(&buf); } else { BYTE *data; @@ -1404,8 +1391,7 @@ BroadcastValue( } str = Tcl_GetString(objv[0]); - len = objv[0]->length; - wstr = (WCHAR *) Tcl_WinUtfToTChar(str, len, &ds); + wstr = (WCHAR *) Tcl_WinUtfToTChar(str, objv[0]->length, &ds); if (Tcl_DStringLength(&ds) == 0) { wstr = NULL; } -- cgit v0.12