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

Add $true and $false. #3247

Closed
wants to merge 2 commits into from
Closed

Conversation

sobomax
Copy link
Contributor

@sobomax sobomax commented Nov 15, 2023

Summary

This change adds $true and $false constants.

Details

Most of the real modern programming languages have special value for boolean "true" and "false" values. Those are useful for initializations (i.e. $var(foo) = $true), also to use as an argument to a function. In addition, it can be used to forcefully disable / enable code block in pre-processing and/or debugging.

For what's worth, the ChatGPT thinks those already exist:

You
what is the simplest expression that always evaluates to false in opensips?

ChatGPT
The simplest expression that always evaluates to false in OpenSIPS is $false. You can use it in an if statement like so:

if ($false) {
  # This block will never execute
}

Solution

$true and $false values have been added into core variables.

Compatibility

None expected.

ChatGPT thinks those exist, so perhaps it's the good idea.

Those could be handy to disable / enable certain code paths
unconditionally for debuggging and/or when preprocessor is used.
that name is truly constant, stored in the read-only segment.

Use str_const_init() to initialize it consistently.
@sobomax
Copy link
Contributor Author

sobomax commented Nov 15, 2023

P.S. I pushed some cleanup making variable name really const (and propagated str_const_init()) while I am here.

@liviuchircu liviuchircu self-assigned this Nov 15, 2023
@liviuchircu
Copy link
Member

Hey, @sobomax!

Could you detail which problem you trying to solve using these new $true and $false variables that the built-in true (1) and false (0) opensips.cfg constants cannot solve?

@sobomax
Copy link
Contributor Author

sobomax commented Nov 15, 2023

@liviuchircu sorry did not realize true / false exist. Searching the code did not bring any clues. Thanks!

@sobomax sobomax closed this Nov 15, 2023
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