Page MenuHomeFreeBSD

Import the bc and dc programs developed by Gavin D. Howard
ClosedPublic

Authored by se on Apr 20 2019, 8:15 AM.

Details

Summary

These bc and dc programs offer a number of advantages compared to the current version in base:

  • Does not depend on external large number functions (i.e. no dependency on OpenSSL or any large number library)
  • Implements all features found in GNU bc/dc (with the exception of a function that is considered a security issue) but is BSD licensed
  • Is significantly faster than the current code in base (by a factor of 5 in a few large number tests that I have performed)
  • Should be fully compatible with all features and the behavior of the current FreeBSD version (not formally verified)
  • Supports POSIX message catalogs and comes with localized messages in French and German (more to be expected, this is a recently added feature)
  • It comes with a very detailed man-page that provides far more information than the current one

While there is no reason to replace the current code in base from a license point of view, the advantages offered by this version seem significant enough to support this change.

The programs to be imported in base are already available as a port (math/gh-bc) for easy testing.

The attached diff contains an import of the relevant files from upstream version 1.2.7 into contrib/bc, with FreeBSD build infrastructure in usr.bin/gh_bc. There are extensive regression tests that are run by the upstream before each new release is tagged. These tests could be imported into base, but are not included in this review. (They are available in the port.)

This code will only replace the standard versions in base if the world is built and installed with "MK_GH_BC=yes".

Test Plan

Build and install world with "MK_GH_BC=yes".
Perform regression tests for bc and dc.
Build universe with "MK_GH_BC=yes".
Optionally perform exp-run with these tools in base.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

Update to (not yet released) version 1.3.0.

Multiplication has been optimized and the overall performance of this version is now comparable to that of the GNU bc implementation.

se edited the summary of this revision. (Show Details)
se edited the test plan for this revision. (Show Details)

This updated diff is for a pre-release version of bc-2.1.0 (expected to be similar to the release, except for possible last minute documentation enhancements or other non-functional changes).
The man-pages have received some updates, e.g. regarding the behavior in error situations.
This version differs from the previous one in a number of optimizations that have further improved the performance which now far exceeds other bc implementations in non-trivial test cases (e.g. the bc and dc currently in FreeBSD, but GNU bc, too).
A lot of regression tests have been added and the sources included in this review have been test-built on FreeBSD with clang-8.0.1, gcc-8.3.0, and gcc-4.2.1.
Run-tests have been performed with the amd64 and i386 versions (with more planned before the commit to FreeBSD).

If there are no arguments against this import, I'd want to commit version 2.1.0 (after the release has been tagged in the GIT upstream repo), replacing the current bc and dc only if MK_GH_BC is defined.
This should allow for easy testing in -CURRENT.
Then, after 1 month, I'd like to make this bc the default in -CURRENT - but I'm not sure whether to keep the current implementation available in -CURRENT, too.
No MFC to STABLE-12 is planned, but this version will be available as a port/package for all FreeBSD versions.

Update sources to version 3.0.2 with further significant enhancements and improved speed.

The reasons that this version is far superior to the one currently in FreeBSD have been stated in the "Summary" for the previous version.
This code is actively maintained and fixes severe deviations from POSIX of the bc in FreeBSD base.
It supports the GNU extensions that are the reason some ports depend on GNU bc to be built or run.

The suggested import into FreeBSD does not prevent building of the "old" and bc/dc - MK_GH_BC must be set to yes to get the new version.

This revision is now accepted and ready to land.Jun 25 2020, 4:01 PM

Personally, I'd land this in -current and then MFC it into 12.2, but have it on by default in -current and off by default in 12.2.