From fc21472ee84599fb3d0e6e1896ad6c59c0e68f82 Mon Sep 17 00:00:00 2001 From: Intubun <41478036+Intubun@users.noreply.github.com> Date: Mon, 4 May 2026 13:29:11 +0200 Subject: [PATCH] Add ClientData parameter to indirect-call callbacks for WASM MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit WASM call_indirect enforces an exact type match between the caller and the callee. Many Magic callbacks had K&R-style () forward declarations and a single-argument definition, but were passed to iterators that always push a trailing ClientData argument. Native builds tolerated the mismatch via loose prototypes; WASM traps with "indirect call signature mismatch". Added the missing ClientData (or, where the concrete type is known, FindRegion *) parameter to: * calma/CalmaRead.c, calma/CalmaWrite.c, calma/CalmaWriteZ.c — calmaWriteInitFunc * cif/CIFwrite.c — cifWriteInitFunc * commands/CmdSubrs.c — cmdWindSet * database/DBtimestmp.c — dbStampFunc * dbwind/DBWelement.c — dbwElementAlways1 * dbwind/DBWfdback.c — dbwfbWindFunc * dbwind/DBWhlights.c — DBWHLRedrawWind * ext2spice/ext2hier.c — spcnodeHierVisit * extract/ExtBasic.c — extSDTileFunc, extTransPerimFunc, extAnnularTileFunc, extResistorTileFunc * extract/ExtMain.c — extDefInitFunc * extract/ExtTimes.c — extTimesInitFunc Also adjusted commands/CmdE.c and commands/CmdTZ.c: SelectExpand was being called with four arguments (the legacy surroundFlag), but its real signature has been three arguments for years (the surround mode is encoded in the expandType bit). The fourth argument was redundant (DB_EXPAND_SURROUND in arg 2 is the source of truth) and rejected by WASM. Native behavior is unchanged. The added parameters are unused in the function bodies; they exist only to satisfy the indirect-call signature. --- calma/CalmaRead.c | 2 +- calma/CalmaWrite.c | 5 +++-- calma/CalmaWriteZ.c | 2 +- cif/CIFwrite.c | 5 +++-- commands/CmdE.c | 38 +++++++++++++++++++------------------- commands/CmdSubrs.c | 5 +++-- commands/CmdTZ.c | 6 +++--- database/DBtimestmp.c | 3 ++- dbwind/DBWelement.c | 4 +++- dbwind/DBWfdback.c | 4 +++- dbwind/DBWhlights.c | 3 ++- ext2spice/ext2hier.c | 3 ++- extract/ExtBasic.c | 18 +++++++++++------- extract/ExtMain.c | 5 +++-- extract/ExtTimes.c | 3 ++- 15 files changed, 61 insertions(+), 45 deletions(-) diff --git a/calma/CalmaRead.c b/calma/CalmaRead.c index 734eacc4..e0a4935f 100644 --- a/calma/CalmaRead.c +++ b/calma/CalmaRead.c @@ -112,7 +112,7 @@ bool CalmaUnique = FALSE; /* If TRUE, then if a cell exists in extern bool CalmaDoLibrary; /* Also used by GDS write */ extern void calmaUnexpected(int wanted, int got); -extern int calmaWriteInitFunc(CellDef *def); +extern int calmaWriteInitFunc(CellDef *def, ClientData cdata); /* * Scaling. diff --git a/calma/CalmaWrite.c b/calma/CalmaWrite.c index 58d75262..de718f63 100644 --- a/calma/CalmaWrite.c +++ b/calma/CalmaWrite.c @@ -96,7 +96,7 @@ typedef struct { } calmaOutputStruct; /* Forward declarations */ -extern int calmaWriteInitFunc(CellDef *def); +extern int calmaWriteInitFunc(CellDef *def, ClientData cdata); extern int calmaWritePaintFunc(Tile *tile, TileType dinfo, calmaOutputStruct *cos); extern int calmaMergePaintFunc(Tile *tile, TileType dinfo, calmaOutputStruct *cos); extern int calmaWriteUseFunc(CellUse *use, FILE *f); @@ -824,7 +824,8 @@ done: int calmaWriteInitFunc( - CellDef *def) + CellDef *def, + ClientData cdata) { def->cd_client = (ClientData) 0; return (0); diff --git a/calma/CalmaWriteZ.c b/calma/CalmaWriteZ.c index 3a56a924..775416dd 100644 --- a/calma/CalmaWriteZ.c +++ b/calma/CalmaWriteZ.c @@ -96,7 +96,7 @@ extern int calmaPaintLayerNumber; extern int calmaPaintLayerType; /* External functions from CalmaWrite.c */ -extern int calmaWriteInitFunc(CellDef *def); +extern int calmaWriteInitFunc(CellDef *def, ClientData cdata); /* Structure used by calmaWritePaintFuncZ() and others */ diff --git a/cif/CIFwrite.c b/cif/CIFwrite.c index 4599bb75..25ffa4bd 100644 --- a/cif/CIFwrite.c +++ b/cif/CIFwrite.c @@ -44,7 +44,7 @@ static const char rcsid[] __attribute__ ((unused)) = "$Header: /usr/cvsroot/magi #include "textio/textio.h" /* Forward declarations */ -extern int cifWriteInitFunc(CellDef *def); +extern int cifWriteInitFunc(CellDef *def, ClientData cdata); extern int cifWriteMarkFunc(CellUse *use); extern int cifWritePaintFunc(Tile *tile, TileType dinfo, FILE *f); extern int cifWriteLabelFunc(Tile *tile, TileType dinfo, FILE *f); @@ -206,7 +206,8 @@ CIFWrite( int cifWriteInitFunc( - CellDef *def) + CellDef *def, + ClientData cdata) { def->cd_client = (ClientData) 0; return (0); diff --git a/commands/CmdE.c b/commands/CmdE.c index 6d3c156e..df4bc2f1 100644 --- a/commands/CmdE.c +++ b/commands/CmdE.c @@ -905,7 +905,7 @@ CmdExpand( case EXPAND_SELECTION: SelectExpand(windowMask, (doToggle) ? DB_EXPAND_TOGGLE : DB_EXPAND, - (Rect *)NULL, FALSE); + (Rect *)NULL); break; case EXPAND_OVERLAP: if (doToggle) @@ -913,18 +913,18 @@ CmdExpand( DBExpandAll(rootBoxUse, &rootRect, windowMask, DB_EXPAND_TOGGLE | DB_EXPAND_OVERLAP, cmdExpandFunc, (ClientData)(pointertype)windowMask); - SelectExpand(windowMask, - DB_EXPAND_TOGGLE | DB_EXPAND_OVERLAP, - &rootRect, FALSE); + SelectExpand(windowMask, + DB_EXPAND_TOGGLE | DB_EXPAND_OVERLAP, + &rootRect); } else { DBExpandAll(rootBoxUse, &rootRect, windowMask, DB_EXPAND | DB_EXPAND_OVERLAP, cmdExpandFunc, (ClientData)(pointertype)windowMask); - SelectExpand(windowMask, - DB_EXPAND | DB_EXPAND_OVERLAP, - &rootRect, FALSE); + SelectExpand(windowMask, + DB_EXPAND | DB_EXPAND_OVERLAP, + &rootRect); } break; case EXPAND_SURROUND: @@ -933,18 +933,18 @@ CmdExpand( DBExpandAll(rootBoxUse, &rootRect, windowMask, DB_EXPAND_TOGGLE | DB_EXPAND_SURROUND, cmdExpandFunc, (ClientData)(pointertype)windowMask); - SelectExpand(windowMask, - DB_EXPAND_TOGGLE | DB_EXPAND_SURROUND, - &rootRect, TRUE); + SelectExpand(windowMask, + DB_EXPAND_TOGGLE | DB_EXPAND_SURROUND, + &rootRect); } else { DBExpandAll(rootBoxUse, &rootRect, windowMask, DB_EXPAND | DB_EXPAND_SURROUND, cmdExpandFunc, (ClientData)(pointertype)windowMask); - SelectExpand(windowMask, - DB_EXPAND | DB_EXPAND_SURROUND, - &rootRect, TRUE); + SelectExpand(windowMask, + DB_EXPAND | DB_EXPAND_SURROUND, + &rootRect); } break; case EXPAND_ALL: @@ -953,18 +953,18 @@ CmdExpand( DBExpandAll(rootBoxUse, &TiPlaneRect, windowMask, DB_EXPAND | DB_EXPAND_OVERLAP, cmdExpandFunc, (ClientData)(pointertype)windowMask); - SelectExpand(windowMask, - DB_EXPAND | DB_EXPAND_OVERLAP, - (Rect *)NULL, FALSE); + SelectExpand(windowMask, + DB_EXPAND | DB_EXPAND_OVERLAP, + (Rect *)NULL); } else { DBExpandAll(rootBoxUse, &TiPlaneRect, windowMask, DB_EXPAND | DB_EXPAND_OVERLAP, cmdExpandFunc, (ClientData)(pointertype)windowMask); - SelectExpand(windowMask, - DB_EXPAND | DB_EXPAND_OVERLAP, - (Rect *)NULL, FALSE); + SelectExpand(windowMask, + DB_EXPAND | DB_EXPAND_OVERLAP, + (Rect *)NULL); } break; } diff --git a/commands/CmdSubrs.c b/commands/CmdSubrs.c index 7a12c979..d5fc2dde 100644 --- a/commands/CmdSubrs.c +++ b/commands/CmdSubrs.c @@ -1019,7 +1019,7 @@ CmdSetWindCaption( * edit cell was selected. */ { - int cmdWindSet(MagWindow *window); + int cmdWindSet(MagWindow *window, ClientData clientData); newEditDef = (newEditUse) ? newEditUse->cu_def : NULL; newRootDef = rootDef; @@ -1055,7 +1055,8 @@ CmdSetWindCaption( int cmdWindSet( - MagWindow *window) + MagWindow *window, + ClientData clientData) { char caption[200]; CellDef *wDef; diff --git a/commands/CmdTZ.c b/commands/CmdTZ.c index b6c56300..721e832e 100644 --- a/commands/CmdTZ.c +++ b/commands/CmdTZ.c @@ -777,7 +777,7 @@ CmdUnexpand( switch (option) { case UNEXPAND_SELECTION: - SelectExpand(windowMask, DB_UNEXPAND, (Rect *)NULL, FALSE); + SelectExpand(windowMask, DB_UNEXPAND, (Rect *)NULL); break; case UNEXPAND_OVERLAP: DBExpandAll(((CellUse *)w->w_surfaceID), &rootRect, windowMask, @@ -785,7 +785,7 @@ CmdUnexpand( cmdUnexpandFunc, (ClientData)(pointertype)windowMask); SelectExpand(windowMask, DB_UNEXPAND | DB_EXPAND_OVERLAP, - &rootRect, FALSE); + &rootRect); break; case UNEXPAND_SURROUND: DBExpandAll(((CellUse *)w->w_surfaceID), &rootRect, windowMask, @@ -793,7 +793,7 @@ CmdUnexpand( cmdUnexpandFunc, (ClientData)(pointertype)windowMask); SelectExpand(windowMask, DB_UNEXPAND | DB_EXPAND_SURROUND, - &rootRect, TRUE); + &rootRect); break; case UNEXPAND_ALL: DBExpandAll(((CellUse *)w->w_surfaceID), &TiPlaneRect, windowMask, diff --git a/database/DBtimestmp.c b/database/DBtimestmp.c index 85850359..b38b2b09 100644 --- a/database/DBtimestmp.c +++ b/database/DBtimestmp.c @@ -239,8 +239,9 @@ DBUpdateStamps(def) } int -dbStampFunc(cellDef) +dbStampFunc(cellDef, cdata) CellDef *cellDef; + ClientData cdata; { CellUse *cu; CellDef *cd; diff --git a/dbwind/DBWelement.c b/dbwind/DBWelement.c index 7d8ea59a..aae0a727 100644 --- a/dbwind/DBWelement.c +++ b/dbwind/DBWelement.c @@ -868,7 +868,9 @@ dbwelemGetTransform(use, transform, cdarg) } int -dbwElementAlways1() +dbwElementAlways1(w, clientData) + MagWindow *w; /* Unused. */ + ClientData clientData; /* Unused. */ { return 1; } diff --git a/dbwind/DBWfdback.c b/dbwind/DBWfdback.c index 56d392cc..1d2300bb 100644 --- a/dbwind/DBWfdback.c +++ b/dbwind/DBWfdback.c @@ -532,7 +532,9 @@ dbwfbGetTransform(use, transform, cdarg) */ int -dbwfbWindFunc() +dbwfbWindFunc(w, clientData) + MagWindow *w; /* Unused. */ + ClientData clientData; /* Unused. */ { return 1; } diff --git a/dbwind/DBWhlights.c b/dbwind/DBWhlights.c index e1356c7e..3975ea3f 100644 --- a/dbwind/DBWhlights.c +++ b/dbwind/DBWhlights.c @@ -358,8 +358,9 @@ DBWHLRedrawPrepWindow(MagWindow *window, Rect *area) */ int -DBWHLRedrawWind(window) +DBWHLRedrawWind(window, clientData) MagWindow *window; /* Window in which to redraw highlights. */ + ClientData clientData; /* Unused. */ { int i; DBWclientRec *crec; diff --git a/ext2spice/ext2hier.c b/ext2spice/ext2hier.c index f66ed9ff..a933b863 100644 --- a/ext2spice/ext2hier.c +++ b/ext2spice/ext2hier.c @@ -1568,7 +1568,8 @@ spcnodeHierVisit( HierContext *hc, EFNode *node, int res, - double cap) + double cap, + ClientData cdata) { HierName *hierName; bool isConnected = FALSE; diff --git a/extract/ExtBasic.c b/extract/ExtBasic.c index 31fe2c30..725eabab 100644 --- a/extract/ExtBasic.c +++ b/extract/ExtBasic.c @@ -147,13 +147,13 @@ NodeRegion *temp_subsnode = NULL; /* Last subsnode found */ /* Forward declarations */ void extOutputNodes(); int extTransTileFunc(); -int extTransPerimFunc(); +int extTransPerimFunc(Boundary *, ClientData); int extTransFindSubs(); int extTransFindId(); void extTermAPFunc(); -int extAnnularTileFunc(); -int extResistorTileFunc(); +int extAnnularTileFunc(Tile *, TileType, int, FindRegion *); +int extResistorTileFunc(Tile *, TileType, int, FindRegion *); int extSpecialPerimFunc(); void extFindDuplicateLabels(); @@ -2186,10 +2186,11 @@ extDevFindParamMatch(devptr, length, width) * ---------------------------------------------------------------------------- */ int -extSDTileFunc(tile, dinfo, pNum) +extSDTileFunc(tile, dinfo, pNum, arg) Tile *tile; TileType dinfo; /* (unused) */ int pNum; + FindRegion *arg; { LinkedTile *newdevtile; @@ -3948,8 +3949,9 @@ extTermAPFunc(tile, dinfo, eapd) */ int -extTransPerimFunc(bp) +extTransPerimFunc(bp, cdata) Boundary *bp; + ClientData cdata; { TileType tinside, toutside, dinfo; Tile *tile; @@ -4226,10 +4228,11 @@ extTransPerimFunc(bp) */ int -extAnnularTileFunc(tile, dinfo, pNum) +extAnnularTileFunc(tile, dinfo, pNum, arg) Tile *tile; TileType dinfo; int pNum; + FindRegion *arg; { TileTypeBitMask mask; TileType loctype; @@ -4276,10 +4279,11 @@ extAnnularTileFunc(tile, dinfo, pNum) */ int -extResistorTileFunc(tile, dinfo, pNum) +extResistorTileFunc(tile, dinfo, pNum, arg) Tile *tile; TileType dinfo; int pNum; + FindRegion *arg; { TileTypeBitMask mask; TileType loctype; diff --git a/extract/ExtMain.c b/extract/ExtMain.c index 47e649f9..4beab80f 100644 --- a/extract/ExtMain.c +++ b/extract/ExtMain.c @@ -85,7 +85,7 @@ typedef struct _linkedDef { Stack *extDefStack; /* Forward declarations */ -int extDefInitFunc(); +int extDefInitFunc(CellDef *, ClientData); void extDefPush(); void extDefIncremental(); void extParents(); @@ -396,8 +396,9 @@ ExtAll(rootUse) * rooted at a particular def. */ int -extDefInitFunc(def) +extDefInitFunc(def, cdata) CellDef *def; + ClientData cdata; { def->cd_client = (ClientData) 0; return (0); diff --git a/extract/ExtTimes.c b/extract/ExtTimes.c index b712877a..ffec19c6 100644 --- a/extract/ExtTimes.c +++ b/extract/ExtTimes.c @@ -289,8 +289,9 @@ ExtTimes(rootUse, f) */ int -extTimesInitFunc(use) +extTimesInitFunc(use, cdata) CellUse *use; + ClientData cdata; { CellDef *def = use->cu_def; struct cellStats *cs;