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 assert to SvPV-ish macros #19990

Closed
wants to merge 1 commit into from
Closed

Conversation

khwilliamson
Copy link
Contributor

This is to see how many CPAN modules call these with a differently sized
'len' than the specified 'STRLEN'. See
#19983

@jkeenan
Copy link
Contributor

jkeenan commented Jul 24, 2022

This is to see how many CPAN modules call these with a differently sized 'len' than the specified 'STRLEN'. See #19983

Can you be a bit more specific as to what your battle plan is here?

For example ... are you proposing to include this in our next monthly development release, such that the volume of CPANtesters failure reports would indicate the scope of the problem?

@khwilliamson
Copy link
Contributor Author

khwilliamson commented Jul 24, 2022 via email

@@ -1902,19 +1902,22 @@ END_EXTERN_C
(((SvFLAGS(sv) & (SVf_POK|SVs_GMG)) == SVf_POK) || ((SvFLAGS(sv) & (SVf_IOK|SVp_POK|SVs_GMG)) == (SVf_IOK|SVp_POK)))

#define SvPV_flags(sv, len, flags) \
(__ASSERT_(sizeof(len) == sizeof(STRLEN)) \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why __ASSERT_() (which really isn't a name we should define, let alone use) instead of assert(...),?

Unfortunately we can't use a static assert here :(

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bram++ pointed me to a discussion about using a static assert expression. I had a go at that, and am stymied.

Yes, one can create such a thing for C, but apparently not for C++, without using lambda expressions. But I don't consider this a show stopper. For C++ compilations, just expand to nothing

The problem I run into is many compilation warnings because we enable C++ compat warnings. AFAICT the pragmas to turn those off around these are statements, not an expression

@khwilliamson
Copy link
Contributor Author

khwilliamson commented Jul 25, 2022 via email

@khwilliamson
Copy link
Contributor Author

khwilliamson commented Jul 25, 2022 via email

@tonycoz
Copy link
Contributor

tonycoz commented Jul 25, 2022

We can't use plain assert(), because on non-DEBUGGING builds, that is a syntax error.

Plain assert(), as used in a comma expression:

(assert(foo),expected result)

has been valid syntax since 2014 when the bug was fixed in 11f9ab1.

@khwilliamson
Copy link
Contributor Author

So what should we do about _ASSERT?

@tonycoz
Copy link
Contributor

tonycoz commented Jul 26, 2022

So what should we do about __ASSERT_?

I'd suggest documenting it as discouraged, don't use it in new code.

@khwilliamson
Copy link
Contributor Author

I think we would need to backport your plain assert() fix

@demerphq
Copy link
Collaborator

@tonyc I think we should remove all the uses of __ASSERT_ from our code if we don't want it to be used. When I need to create a new macro I look for one that does something similar and crib from it. If all the examples use __ASSERT_ then people will continue to use it. BTW, just for the record could you explain why that spelling/macro is problematic? Are identifiers like that reserved?

@tonyc
Copy link

tonyc commented Jul 30, 2022

@demerphq I think you pinged the wrong GH user ;)

@khwilliamson
Copy link
Contributor Author

symbols containing multiple underscores in a row or beginning with an underscore are reserved for the implementation of C itself. There's generally no problem unless our names collide, which is very unlikely. Still, it is better practice to not use those.

I do think C has reserved too large a class.

@khwilliamson
Copy link
Contributor Author

He meant @tonycoz

@tonycoz
Copy link
Contributor

tonycoz commented Jul 31, 2022

@tonyc I think we should remove all the uses of __ASSERT_ from our code if we don't want it to be used.

I was mostly considering it unnecessary churn, but removing it avoids technical debt, so removing it really isn't that unnecessary.

This is to see how many CPAN modules call these with a differently sized
'len' than the specified 'STRLEN'.  See
Perl#19983
@jkeenan
Copy link
Contributor

jkeenan commented Aug 15, 2024

@khwilliamson this p.r. has had no activity or discussion since December 2022. My impression is that people were not enthusiastic about it. Can we close it?

@jkeenan jkeenan added the Closable? We might be able to close this ticket, but we need to check with the reporter label Aug 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Closable? We might be able to close this ticket, but we need to check with the reporter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants