Skip to content

fix+feat: protect global extrasymbol buffer with mutex for local poly… - #910

Open
jodavies wants to merge 1 commit into
form-dev:masterfrom
jodavies:issue-138
Open

jodavies wants to merge 1 commit into
form-dev:masterfrom
jodavies:issue-138

Conversation

@jodavies

Copy link
Copy Markdown
Collaborator

… conversion

This fixes #138 by having local polynomial conversions hold a mutex for the duration, to avoid corruption due to concurrent modifications of the global extrasymbol buffer.

This means that we can now also allow simultaneous use of global extrasymbols (ArgToExtraSymbol, ToPolynomial/FromPolynomial) and functions which trigger local conversion to polynomials: FactArg, FactDollar, gcd_, etc. Historically this has been forbidden in both FORM and TFORM, although FORM should not ever have had an issue. Presumably it was forbidden for both for consistency.

@coveralls

coveralls commented Sep 15, 2026 •

Copy link
Copy Markdown

Coverage Status

coverage: 66.081% (+0.01%) from 66.069% — jodavies:issue-138 into form-dev:master

This fixes form-dev#138 by having local polynomial conversions use only thread-local
storage. We lock once, to store a copy of the global numxsymbol. After that
everything is local and no further locks are required for the local conversion.

This means that we can now also allow simultaneous use of global extrasymbols
(ArgToExtraSymbol, ToPolynomial/FromPolynomial) and functions which may trigger
local conversion to polynomials: FactArg, FactDollar, gcd_, etc. Historically
this has been forbidden in both FORM and TFORM, although FORM should not ever
have had an issue. Presumably it was forbidden for both for consistency.
@jodavies

Copy link
Copy Markdown
Collaborator Author

The final version of this commit does not hold a lock for the duration of the local polynomial operation. Rather, it locks just to get the current number of global extrasymbols, and then proceeds to perform the local polynomial conversion using only thread-local storage. The temporary extrasymbols are removed at the end of the operation.

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.

[tform] Wrong result from ToPolynomial and rational arithmetics with non-symbols

2 participants