Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove nullfunc_t and make INVALID_FUNCTION the same as null. #912

Merged
merged 1 commit into from
Oct 20, 2023
Merged

Conversation

dvander
Copy link
Member

@dvander dvander commented Oct 9, 2023

INVALID_FUNCTION was proving to be a major pain; setting it to -1 might be one of the dumbest things I've done. It had a few problems all boiling down to "there is no support in the compiler for non-zero false values". Eg, f1 == f2 is false below:

    Function f1;
    Function f2 = INVALID_FUNCTION;

We could have gone through and fixed all the edge cases like this throughout the compiler, but it seems counter-productive.

The other oddity is that because null is 0, INVALID_FUNCTION needed a separate unit type, which we called nullfunc_t.

Rather than keep propping up all this weirdness, this patch normalizes INVALID_FUNCTION by making it equivalent to null. Its value is 0, and its type is null_t.

This will break compatibility with cross-plugin interactions, so plugins sharing a scripted API will need to be recompiled.

It will also break C++ code relying on a -1 value. To help assist with this breakage, three functions have been added to IPluginContext:

  • GetNullFunctionValue()
  • IsNullFunctionId()
  • GetFunctionByIdOrNull().

INVALID_FUNCTION was proving to be a major pain; setting it to -1 might
be one of the dumbest things I've done. It had a few problems all
boiling down to "there is no support in the compiler for non-zero false
values". Eg, `f1 == f2` is false below:

        Function f1;
        Function f2 = INVALID_FUNCTION;

We could have gone through and fixed all the edge cases like this
throughout the compiler, but it seems counter-productive.

The other oddity is that because `null` is 0, `INVALID_FUNCTION` needed
a separate unit type, which we called `nullfunc_t`.

Rather than keep propping up all this weirdness, this patch normalizes
`INVALID_FUNCTION` by making it equivalent to `null`. Its value is 0,
and its type is `null_t`.

This will break compatibility with cross-plugin interactions, so plugins
sharing a scripted API will need to be recompiled.

It will also break C++ code relying on a -1 value. To help assist with
this breakage, three functions have been added to `IPluginContext`:

 - `GetNullFunctionValue()`
 - `IsNullFunctionId()`
 - `GetFunctionByIdOrNull()`.
@dvander dvander merged commit fe28b35 into master Oct 20, 2023
19 checks passed
@dvander dvander deleted the infn branch October 20, 2023 05:38
@Sikarii
Copy link

Sikarii commented Oct 28, 2023

I take this fixes #469 so the issue can most likely be closed.

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