Skip to content

Fix K&R in DBbound.c.#487

Closed
gonsolo wants to merge 1 commit into
RTimothyEdwards:masterfrom
gonsolo:dbbound_kandr
Closed

Fix K&R in DBbound.c.#487
gonsolo wants to merge 1 commit into
RTimothyEdwards:masterfrom
gonsolo:dbbound_kandr

Conversation

@gonsolo

@gonsolo gonsolo commented Jan 23, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@RTimothyEdwards RTimothyEdwards left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of about a thousand such updates that needs to be made. Thanks for the PR.

@RTimothyEdwards

Copy link
Copy Markdown
Owner

Pulled and merged to the repository at opencircuitdesign.com (github mirror will be updated overnight).

@gonsolo

gonsolo commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

One of about a thousand such updates that needs to be made. Thanks for the PR.

1162, to be precise. 😉

gonsolo added a commit to gonsolo/magic that referenced this pull request Jun 9, 2026
Convert 1162 old-style (K&R) function definitions to modern ANSI C
prototypes across the tree, following the pattern of PR RTimothyEdwards#487, and
remove the -Wno-implicit-int flag that was suppressing the related
warnings in the emscripten target.

GCC 16 defaults to C23, where "()" means "(void)" rather than
"unspecified arguments", which broke the build independently of the
K&R conversion.  Add -std=gnu17 (in the gcc SHLIB_CFLAGS block and the
emscripten target of scripts/configure[.in]) to restore C17 semantics
so the many remaining legacy "()" declarations keep compiling.  The
emscripten/clang toolchain also defaults to C23 and silently ignores
the "--std=" long form some CI scripts pass, so it needs the single-dash
-std=gnu17 explicitly.

Fix the errors the ANSI conversion then exposed:

  - Type forward/header declarations that conflicted with the now-typed
    definitions.  Under C, an empty "()" declaration is incompatible
    with a prototype whose parameters undergo default promotion (bool,
    float), so these had to be given explicit signatures.  The database
    module's declarations live in the generated header database.h, so
    these changes are made in its source template database.h.in (editing
    the generated database.h directly is lost on a clean build).
  - Add struct-tag forward declarations (MagWindow, GrGlyph, TxCommand,
    NLNetList, cellUE, struct inarg) where the type was not visible at
    the point of use, including to break circular header includes.
  - Revert over-typed generic callback pointers (WindAddClient,
    WindSearch, GrLockPtr/GrUnlockPtr) back to "()": their callbacks
    have intentionally varying return types and they take no promotable
    scalar arguments.
  - Fix genuine latent mismatches surfaced by stricter checking:
    "extern int wind*Cmd()" declarations that should be void, the
    DebugSet bool/int parameter mismatch, the typed func pointers in
    CmdCD and PlowRules3, and comparator/callback casts for qsort,
    extEnumTilePerim, and the Tk/TOGL lock pointers.

Result: the tree compiles cleanly under GCC 16 and tclmagic.so links
and loads successfully.

Verification
------------
  - Clean-from-scratch native build (make clean + make -j -k): 0 errors,
    exit 0.  The only warnings are 18 benign -Wdiscarded-qualifiers
    (const pointers passed to the newly-typed prototypes, which do not
    declare const; the callees do not mutate the data).
  - Re-verified with bool defined as _Bool (-DHAVE_STDBOOL_H=1, matching
    the CI runners where stdbool.h is detected): 0 errors.  Locally
    autoconf 2.69's C99 stdbool test fails under GCC 16 so bool falls
    back to signed char; both configurations now build.
  - WASM build reproduced locally with emscripten (emconfigure ./configure
    --host=asmjs-unknown-emscripten ... ; emmake make depend modules libs
    techs mains): 0 errors, produces magic.js and magic.wasm.
  - tclmagic.so loads and magic::initialize -dnull -noconsole succeeds.
  - Functional smoke test against the generated scmos.tech exercised the
    most heavily-converted files, all producing correct results:
      * tech load (DBtech*.c)
      * paint poly/metal1/pcontact, with pcontact correctly forming
        polycontact (DBpaint.c, DBtpaint.c, DBtcontact.c)
      * drc check (DRCbasic.c, DRCtech.c)
      * extract all -> realtest.ext (ExtBasic.c/ExtMain.c, including the
        extEnumTilePerim callback cast)
      * save -> reload disk round-trip preserving all layer types
        (DBio.c read and write)

Not covered by the smoke test (compiled and loaded, but not executed):
the routers (grouter/mzrouter/garouter/irouter), GDS/CIF/LEF I/O,
plotting, and 3D.  A valid-but-wrong type in one of those untested
paths would not have been caught at runtime, though the clean build
rules out most mis-typings (which surface as compile errors).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Intubun pushed a commit to Intubun/magic that referenced this pull request Jun 10, 2026
… the

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants