Commit Graph

2650 Commits

Author SHA1 Message Date
Darryl L. Miles c6896e2a74 oa: apply code-review feedback — strcpy_s link fallback + argv cleanup
Follow-up to review-master-upstream-20249999-oa-dcff2f64-6535a4e1.md:

- strcpy_s: add an inline fallback implementation right after the declaration,
  guarded by #ifndef __STDC_LIB_EXT1__.  glibc never defines that macro and does
  not provide the C11 Annex K interfaces, so the bare declaration was an
  unresolved symbol at link time; the fallback makes magicOA.o self-contained
  (strcpy_s becomes a defined symbol) while a real Annex K libc still wins.
- magicInit.cpp / magicOA.cpp: use `char argvbuf[] = "tclsh"` for the mutable
  argv string instead of `char[32]` + snprintf.
2026-07-09 10:41:12 -04:00
Darryl L. Miles f3f824a6bb magicOA.c: strcpy_s declaration (FIXME remove/move this) 2026-07-09 10:41:12 -04:00
Darryl L. Miles dfa28d1cd3 oa: replace strcpy() with strcpy_s() 2026-07-09 10:41:12 -04:00
Darryl L. Miles e5d6d3f429 oa/fake_oa_stub (header file oaDB.h) 2026-07-09 10:41:12 -04:00
Darryl L. Miles 9ae91bb4c9 oa: make it build (against stub) 2026-07-09 10:41:12 -04:00
Darryl L. Miles d9e76f372b .gitignore: add .deps/ 2026-07-09 10:41:12 -04:00
Darryl L. Miles fd676c5b10 git rm -rf oa/.deps/* 2026-07-09 10:41:12 -04:00
R. Timothy Edwards 767cde0efc Two fixes: One by Claude Fable 5 which identified the two possible
degenerate cases when attempting to find resistors in triangle
topologies in ResMerge, which fixes the segfault in github issue
diagnostic message.  The other fix is part of github issue #538,
which found an error in the check for tied transistor sources and
drains.  However, the other part of that issue, having to do with
nondeterminism in the "extresist" output, has not yet been addressed.
2026-07-08 13:25:01 -04:00
R. Timothy Edwards 07d98a33c2 Fixed a negative tile width calculation in ResMakeRes.c, as
pointed out by github user "LegumeEmittingDiode".  I agree with
the suggested fix and have implemented it exactly as suggested
in github issue #537.
2026-07-08 09:51:37 -04:00
Intubun d6438387ad Fixed a second emscripten 6.0.2 regression in the WASM build, this one at runtime rather than at compile time. emscripten 6.0.2 removed wasmBinary (along with a batch of GL/SDL members) from the default INCOMING_MODULE_JS_API list. The JS loaders in npm/examples pass Module.wasmBinary to embed the .wasm binary, and because the WASM build links with -sASSERTIONS=1, the now-unrecognized member triggers a hard runtime abort: "`Module.wasmBinary` was supplied but `wasmBinary` not included in INCOMING_MODULE_JS_API", failing every example test. Fixed by explicitly setting -sINCOMING_MODULE_JS_API in toolchains/emscripten/defs.mak to emscripten's full default list plus wasmBinary. Spelling out the whole default (rather than only the members our own loaders use) keeps external consumers of the npm package working if they supply locateFile, arguments, and similar Module options. 2026-07-08 09:48:10 -04:00
Intubun 28483435f1 Fixed the WASM (emscripten) build, which broke starting with emscripten 6.0.2. The failure is not in magic itself but in the TCL dependency build: emscripten 6.0.2 began shipping a <sys/epoll.h> stub in its sysroot (6.0.1 did not), so TCL's configure now detects epoll on the Linux CI host via AC_CHECK_HEADERS([sys/epoll.h]), defines NOTIFIER_EPOLL, and compiles tclEpollNotfy.c. That file also requires <sys/queue.h>, which emscripten does not provide, so the build died with "fatal error: 'sys/queue.h' file not found". Fixed by passing ac_cv_header_sys_epoll_h=no to TCL's configure in toolchains/emscripten/build-tcl-wasm.sh, which forces the select()-based notifier. That notifier is the correct choice for single-threaded WASM anyway (emscripten's epoll is only a stub), and overriding the autoconf cache variable avoids patching the read-only TCL source tree and keeps the build working across future emscripten versions. 2026-07-08 09:48:10 -04:00
R. Timothy Edwards 718e02ec3f Claude Fable 5 implemented capacitance checking at shape corners,
after much discussion about the implementation.  Since it is not
exactly clear what the field lines do at corners, the implementation
depends largely on an unknown and presumably global constant
multiplier;  this has provisionally been set to 1 but needs to be
determined empirically with a field equation solver.  At least one
rational approximation suggests a value of pi/2 instead of 1.  The
corner capacitance can be considered a refinement of existing
parasitic capacitance extraction, and since it takes a non-trivial
additional amount of computation, it is left as an option to
"extract" that can be turned on when a more accurate result is
preferred at the expense of a longer extraction time.
2026-07-08 09:13:07 -04:00
R. Timothy Edwards 443045b331 Fixed a known issue in which the output of "vendor" (read-only) GDS
can become corrupted if the name of the cell in magic changes from
the name of the structure in GDS pointed to by the GDS_FILE property,
and the new name is a different length from the original name.
Fixed by Claude Fable 5 and checked for all name-change scenarios
for both compressed and uncompressed output.
2026-07-06 16:06:07 -04:00
R. Timothy Edwards 4b39363a3b Adding some standard files and paths used by Claude Code so that
AI metadata doesn't end up in the repository.
2026-07-06 11:14:19 -04:00
R. Timothy Edwards f7d9385c87 Corrected the "char" casting of SigInterruptOnSigIO, which (1) must
be able to hold the value -1, and (2) defaults to "unsigned char" on
some systems.  Explicitly casting this as "signed char" should avoid
the problem.
2026-07-06 09:17:32 -04:00
R. Timothy Edwards dcff2f64b8 Corrected the HTML text of the "property" command documentation,
which had mismatched delimiters, causing most of the entry to be
displayed in boldface.
2026-07-03 16:47:58 -04:00
Mohamed Gaber 2f23be9dc3 hack: make flexible union members work on gcc≤14
In GCC <= 14, flexible arrays are not supported in unions because of a parserlimitation.

This is a hack that declares an anonymous struct, which itself can contain a flexible array but still be a member of a union. Another empty element is included because structs that only contain a flexible array are also invalid.
2026-07-01 12:37:44 -04:00
Mohamed Gaber 6638949233 codebase-wide: use flexible arrays where appropriate
In platforms with bounds-checking enabled, placeholder values for array sizes in structs that may be exceeded always result in a sigtrap.

This patch updates the following classes to use flexible arrays at the end of structs:
- database
  - Label
  - PropertyRecord (union of three flexible arrays and a pointer*)
  - cellUE
- extflat
  - HierName
  - EFAttr
  - Dev
- utils
  - HashEntry (union of two flexible arrays and a pointer*)
   - internalUndoEvent: Was a plain int, replaced with a flexible char array

Additionally, the database struct editUE, which would have just a single flexible-array member, was removed and simply replaced with a character pointer.

Where possible, allocation size macros have been introduced.

---

* It is noted flexible-length arrays as part of unions are not part of the C language spec and are a GNU99 extension, however, it is supported by both GCC and Clang.
2026-07-01 12:37:44 -04:00
R. Timothy Edwards dc2ecf35f8 Corrected a crash condition in extresist where ResNodeList is not
checked for being NULL before inserting a new node at the front of
it.
2026-07-01 11:53:47 -04:00
R. Timothy Edwards 60061ea33f Missed one additional place where an "#ifdef MAGIC_NO_TK" block
was needed, in the last commit.  This fix should make the CI run
clean again.
2026-06-25 09:23:09 -04:00
R. Timothy Edwards e7b8e89d2f Added a few lines to ResMerge.c which avoid a crash condition when
a resistor subnet has been linked to itself (or something like that).
Otherwise it leads to a double-free and a crash.  This commit does
not address why the subnet was linked to itself, and the crash was
preceded by another internal diagnostic message "Missing rptr at ..."
which has been noted before but still needs to be tracked down and
fixed.  It is likely that a bad output netlist was created, but at
least magic doesn't segfault.
2026-06-24 13:51:40 -04:00
R. Timothy Edwards b266ec6272 Implemented the resistor "pi" model, which evenly splits the
capacitance of a resistor device between the two terminals.  If
the resistor device model contains the capacitance, then the
resistor type should not be included in types that generate
parasitics.  If not, then the "pi" model is used.  The "tee" model
is still available using "ext2spice resistor tee on".  What this
update does is to default to the "pi" model instead of ignoring
the capacitance of the resistor type (e.g., "rm1"), and because
the capacitance of that node is removed after distributing it
between the two terminals, it will no longer produce a "floating"
node in the netlist output.
2026-06-24 10:34:23 -04:00
R. Timothy Edwards 338b3899bf I broke the CI again for the "wasm" build by adding a Tk routine
to the code (Tk_RestrictEvents()) without an "#ifndef MAGIC_NO_TK"
around it.  This commit fixes that error.
2026-06-24 09:20:06 -04:00
R. Timothy Edwards 3b272cc8d2 Corrected two "extresist" issues: (1) Prevent a segfault when
reading a resistor device which uses the syntax where the resistor
is given a value directly and not as a parameter;  (2) allow the
use of "extresist minres 0" (allow resistors in the output no
matter how small).  Thanks to Torleif Skaar for finding the issue
with the resistor syntax.
2026-06-23 19:41:53 -04:00
R. Timothy Edwards 06f0ce4259 One correction to the previous commit to avoid running
Tk_RestrictEvents() when in batch mode (no graphics, therefore no
Tk);  otherwise, this causes magic to segfault.
2026-06-23 10:53:47 -04:00
R. Timothy Edwards d8046fba2d Corrected the other issue with timers in magic, which is that the
"progress report" of percent completion on certain long-running
processes (namely extraction, DEF reads, and GDS/CIF writes) was
allowing Tcl/Tk events to be processed so that the display would
be repainted and the console window updated to show the progress
instead of hanging.  But that was allowing any key macros or
commands to be entered and executed, potentially corrupting the
database while the process was running.  I have used
Tk_RestrictEvents() to prevent key and button events from being
processed until afterward.  This preserves the display updates
(which do not alter the database) while preventing commands from
being run during one of these long-running processes.  Also:
Previously, whenever a long-running process printed the status,
it would not update at the end, leaving output like "52% complete"
being the last output, leaving the impression that the process
never finished.  Changed the code so that if any partial progress
is printed, then it will always finish up with the output "100%
complete" so that it is clear to the user that everything went
according to plan.
2026-06-23 10:08:31 -04:00
R. Timothy Edwards 5cf1a46061 Corrected two errors with the crash backup mechanism, one minor, one
very major.  The filename created had two slashes in the string
("/tmp//MAG...") because the temporary directory already has a slash
in the string.  This makes no practical difference but looks odd when
printed to the terminal.  The major error is that the Tcl script
that re-establishes the timer after a backup had a typo that caused
the timer never to be reset, resulting in crash backup files that are
created and written once but never again.  This egregious error has
now finally been fixed.
2026-06-22 21:52:06 -04:00
R. Timothy Edwards f4b210a9c0 Made a correction to the last commit, which is that when searching
a shielded substrate area for devices with terminals connecting to
substrate, search the entire cell hierarchy down to the bottom in
that area, not just the immediate child cell.  Also:  Reduced the
number of types being searched to ignore types in non-substrate
areas like nwell, although it should not make a practical difference
because those areas should not be searched.
2026-06-22 20:03:30 -04:00
R. Timothy Edwards 381714e2d5 Modified behavior with regard to substrate shield types being inside
a subcell:  A further check is done to see if there are any devices
that interact with the substrate in the shielded area in the same
subcell.  If not, then this is a trivial case where a different
substrate area exists but does not impact the subcell and should be
ignored.  This change prevents some extraction errors where a substrate
area can get isolated because there was an unrelated substrate area
nearby.  Also:  Corrected parsing of "dsubckt" types when reading .ext
files;  this applies to any device where the optional substrate is
omitted.  There are apparently two conflicting methods when a device
doesn't have a substrate:  (1) Output "None" for the substrate, or
(2) don't output anything.  The 2nd method can be detected by counting
the number of arguments on the line in the .ext file.  The extflat/
EFread.c code handles both methods.  ResReadExtFile() now does too,
but probably code should be changed to just use method (1) always.
Also:  Prevented the "tile not visited" error message in "extresist"
from printing duplicate messages for every device associated with the
same tile.  The message can appear when a labeled net has unconnected
regions, and "extract do unique" is not used.
2026-06-13 16:08:05 -04:00
R. Timothy Edwards d44aeaa1d1 Incremented the version to go along with, and to test, the merge
of pull request #527 from Enno, which allows the AppImage workflow
to trigger on a version update when the version number doesn't
start with a "v", as is the case for the repositories on
opencircuitdesign.com.
2026-06-10 08:54:50 -04:00
Enno Schnackenberg a7f2a38d32 Accept release tags without v prefix in the WASM npm publish gate.
The AppImage release workflows trigger on any tag (the project tags
releases as e.g. 8.3.662, without a v prefix), but the npm publish
gate in main-wasm.yml required a v-prefixed tag, so a normal release
tag built the AppImages but never published the npm package to GitHub
Packages.  The gate now accepts both forms, so a single tag releases
everything.
2026-06-10 11:40:15 +02:00
R. Timothy Edwards a38fa29dac Added a check for exts_globSubstratePlane == -1 in ExtBasic.c,
because this is the default value used if no substrate types are
declared in the tech file;  and if so, this would cause an out-
of-bounds check.  See Issue #523 on github from Darryl Miles.
2026-06-09 17:41:28 -04:00
R. Timothy Edwards 295ec7e492 Corrected the hash tables recently added to the code in resis/,
which used "HT_CLIENTKEYS" when they were intended to use
"HT_WORDKEYS".  See github issue #525 raised by Darryl Miles.
2026-06-09 17:37:51 -04:00
R. Timothy Edwards f650248764 Revised the code of PR #487 (previous merge) to follow the
formatting used for other subroutines.
2026-06-09 16:17:57 -04:00
Gon Solo 8466279b6c Fix K%R in DBbound.c. 2026-06-09 16:16:21 -04:00
R. Timothy Edwards 7296aca107 Updated the version to go along with the merge of pull request #519
from Enno Schnackenberg (adding Tcl support for WASM builds).
2026-06-09 16:09:14 -04:00
Enno Schnackenberg 50320a055a npm: surface readable diagnostics on WASM test failures
The example/suite runners discarded e.stack via console.error(e.message ?? e),
hiding the wasm-function offsets that emsymbolizer needs to map an abort back
to C source. A failing test only printed a terse message like "memory access
out of bounds" with no trace.

- Add reportError() to helpers.js/helpers-tcl.js; print the full stack
  (falling back to the message).
- Wrap command execution in runScript() to name the command that aborted
  before the error propagates.
- Use reportError() in all standalone runners and in all.js/all-tcl.js
  (full stack to stderr, one-line PASS/FAIL summary kept; tests still run
  independently).
- build.sh: run the --test step in a subshell so its cd does not leak into
  the --pack step.
2026-06-09 16:07:53 -04:00
Enno Schnackenberg d37793e7d0 update build.sh and readme.md 2026-06-09 16:07:53 -04:00
Intubun 4669fa9a9f Changed versioning scheme for npm package and update Readme.md 2026-06-09 16:07:53 -04:00
Intubun 4fe8f12595 update npm versioning, build.sh and delete tcl.ref and fix to latest stable 2026-06-09 16:07:53 -04:00
Intubun bc340fba16 build-tcl-wasm.sh: guard against missing tclConfig.sh after emconfigure 2026-06-09 16:07:53 -04:00
Intubun c4923d44a2 fix: sscanf length bound in TclmagicRegisterCommands; show output-tcl in CI
Add explicit length limit to sscanf in TclmagicRegisterCommands: %92s
instead of %s prevents a potential stack overwrite if a command name
were ever longer than the buffer. Matches the available space (keyword[100]
minus the 7-byte "magic::" prefix minus null).

Extend the CI output-display step to also iterate over output-tcl/ so
that TCL-variant test regressions are visible in the job log without
downloading artifacts.
2026-06-09 16:07:53 -04:00
Intubun 1ca85fa372 fix: three correctness fixes before PR
tclmagic.c: remove stray /*-----*/ line left over from a previous edit
that left a duplicate comment opener before TclmagicRegisterCommands.

magicWasm.c: move TxSetPoint inside the #else (non-TCL) branch of
magic_wasm_source_file and restore its explanation comment. TxSetPoint
routes TxDispatch commands to the layout window; it is irrelevant and
misleading in the Tcl_EvalFile path.

magic/Makefile: guard the TCL linker flags in the magic.js link rule
with ifneq (${TCL_LIB_DIR},). When building the non-TCL WASM variant
TCL_LIB_DIR is empty, so the unconditional -L${TCL_LIB_DIR} -ltclstub
expanded to a bare -L flag and a missing library, breaking the notcl
build.
2026-06-09 16:07:53 -04:00
Intubun 6efb44db0a fix: remove remaining intubun/tcl references and dead workflow comment
Replace the last three intubun/tcl mentions with tcltk/tcl in
npm/tcl.js, toolchains/emscripten/build-tcl-wasm.sh, and npm/tcl.ref.
Also remove the stale comment in tcl.ref that referenced a non-existent
update-tcl GitHub Actions workflow.
2026-06-09 16:07:53 -04:00
Intubun db36e896e6 refactor(tcl-examples): rename TCL scripts, drop dead pcell.tcl, fix comments and naming
Rename *-magic.tcl scripts to *-tcl.tcl to match the -tcl.js test naming
convention. Delete the old bare-command pcell.tcl (used cellname create,
no magic:: prefix) and promote pcell-magic.tcl to pcell.tcl.

Fix misleading comment in magicWasm.c: Tclmagic_Init only bootstraps the
interpreter; magic:: commands are registered separately by
TclmagicRegisterCommands after magicMainInit. Align comment block
dashes in TclmagicRegisterCommands to match tclmagic.c style (62 dashes).

Replace intubun/tcl references in build scripts and CI with tcltk/tcl to
match the actual pinned repo in npm/tcl.ref. Also run both test suites
when build.sh is invoked with --test.
2026-06-09 16:07:53 -04:00
Intubun ed576b23c8 fix(pcell): use magic::load to switch cell context before painting 2026-06-09 16:07:53 -04:00
Intubun 7c71d0f3e5 test(tcl): add TCL variant test suite including PCell generation
All non-TCL tests (extract, gds, drc, cif) now also run against the TCL
variant using magic::-prefixed Tcl scripts. A new PCell test generates
two parameterized rectangle cells and verifies their GDS output.

The CI workflow runs npm run test:tcl after the TCL build and saves the
generated output files as an artifact.
2026-06-09 16:07:53 -04:00
Intubun 5801acce62 fix(tcl-wasm): register magic:: Tcl commands after C initialization completes
magic_wasm_init() called Tclmagic_Init() and magicMainInit() but never
ran the command-registration loop in _magic_initialize(), so magic::tech,
magic::load, magic::gds and all other Magic commands were missing from
the Tcl interpreter.

Add TclmagicRegisterCommands() in tclmagic.c containing the
WindNextClient/WindGetCommandTable loop and call it from magic_wasm_init()
after magicMainInit() succeeds.

Also change magic_wasm_source_file() to use Tcl_EvalFile in MAGIC_WRAPPER
mode so scripts with magic:: commands are evaluated through the Tcl
interpreter instead of the plain text dispatcher.
2026-06-09 16:07:53 -04:00
Intubun 4dd0cfd472 docs(npm): add GitHub Packages install instructions and TCL variant documentation 2026-06-09 16:07:53 -04:00
Intubun d873cd7f2b wasm: increase initial memory to 64 MB and stack to 10 MB for larger designs 2026-06-09 16:07:53 -04:00