Skip to content

Fix multiple issues#226

Closed
henrygab wants to merge 19 commits intogerbv:mainfrom
henrygab:second_pass_reduction
Closed

Fix multiple issues#226
henrygab wants to merge 19 commits intogerbv:mainfrom
henrygab:second_pass_reduction

Conversation

@henrygab
Copy link
Copy Markdown

Highlights are as follows:

Fixes #195.
Fixes #211.
Fixes #212.
Fixes #213.
Fixes #214.
Fixes #215.
Fixes #216.
Fixes #217.
Fixes #218.
Fixes #219.
Fixes #220.
Fixes #221.

* Order of internal `drill_state_t` structure changed
* `drill_state_t->autod` changed to native `bool`
* `drill_state_t->autod` changed name to `autodetect_file_format`
* `drill_parse_header_is_metric_comment()` -- local variable names
   changed for increased clarity.
* Many comments added to start documenting unwritten rules
Excellon format is clear that only two values
are valid for `header_number_format`, and
which value is used depends on the units:
* Inches ==> FMT_00_0000
* Metric ==> FMT_000_000

Therefore, do not set to FMT_USER on those
occasions, but to the allowed format type.

Also added many more comments to
`drill_parse_header_is_metric()`, explaining
the implied logic.
This ensures the error message will properly report
all the junk characters, when found.
Specifically, pull out the detection for two
edge cases (hacks for bad data) into separate
functions. These new functions ensure that,
if they return false, they leave the file descriptor
pointer where it was at entry.
* !~ Enable test case for 195 ~!
* Track `leading_digits` and `trailing_digits` as separate values,
  rather than only tracking `decimals`
* Remove HID Attribute `HA_digits` ... because it doesn't store
  information necessary to properly setup state
* Add HID Attributes `HA_leading_digits` and
  `HA_trailing_digits`
* Update function `read_double()` similarly
  (parameter `decimals` --> two parameters)
* Split large function `read_double()` into
  smaller, functionally-focused parts.
* `CHK_STATE` macro calls `check_invariants()` with function/line
* `DUMP_STATE` macro dumps internal state only in debug build
* `check_floating_point()` asserts that stored floating point values
  are never NAN / INFINITE, and logs information if ever stores
  a SUBNORMAL value.
* `check_min_max_int_value()` asserts that stored int values are
  within a given range.

With static_assert() and above functions setup,
the following invariants are checked:
* `image->aperture` is a contiguous array with
  APERTURE_MAX elements
* `max_valid_tool` is set to the smaller of
  APERTURE_MAX or 99
* fp values in `state`: `curr_x`, `curr_y`, `origin_x`, `origin_y`
* `state->current_tool` in range `[0..max_valid_tool]`
* `state->unit` in range `[0..max_units]`
* `state->curr_section` in range `[0..max_file_section]`
* `state->coordinate_mode` in range `[0..max_coordinate_mode]`
* `state->number_format` in range `[0..max_number_format]`
* `state->header_number_format` in range `[0..max_number_format]`
* `state->backup_number_format` in range `[0..max_number_format]`
* `state->omit_zeros` in range `[0..max_zero_suppression]`
* `state->header_number_format` is either `FMT_00_0000` or `FMT_000_000`

Moreover, once parsing of the header portion is completed,
the following additional invariants are asserted:
* `state->unit` (inches/mm) corresponds to `state->number_format`
Two issues with the prior method:
1. `dprintf()` is already defined in `stdio.h`,
   which reduces clarity (bad form!)
2. The use of an `if` statement without braces
   can hide significant logic errors.

Example code that would have logic error:

```C
// Ensure number format is set to FMT_USER (and warn if not true).
if (state->number_format == FMT_USER)
    dprintf("Some debugging information here.")
else
    state->number_format = FMT_USER;
```

Bug in the above example:
`number_format` is never set to `FMT_USER`
* Old and new functions run in parallel to verify equivalent
* Enhanced debugging via single-line output of state
* Enhanced reliability via explicit invariant checks
@henrygab henrygab mentioned this pull request Oct 18, 2023
@henrygab
Copy link
Copy Markdown
Author

List of commits that passed CI (in case of a force-push occurs again):
901f35f
eb56a67
348d65d
25785c2
b041cd6
71604ef
7771632
39d94ac
b16ca35
7c6599e
69fb276
146ce65
730ed54
45f5dc5
05192e0
fe73732
a5e0128
92f46bd
3a013f1

@henrygab henrygab mentioned this pull request Dec 31, 2023
Closed
@henrygab
Copy link
Copy Markdown
Author

It's clear now that this software is essentially not taking pull requests, even after fixes are updated to meet previously-unwritten requirements.

See #210, opened on Sep 4, 2023.

100% success for all self-tests, and significant improvements in code maintainability, and many tiny bugs fixed.
Each commit was a stand-alone set of targeted fixes.
Tests were even updated to show the improved results.

This is now dead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment