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

Consolidate information from the three RFCs it is based on #11

Merged
merged 4 commits into from
Jan 28, 2025

Conversation

derickr
Copy link
Member

@derickr derickr commented Dec 4, 2024

No description provided.

@derickr
Copy link
Member Author

derickr commented Dec 4, 2024

I've finally started doing some work on consolidating the content in these files - it would be helpful if you could have a look to make sure I didn't change the meaning. The original document used "should" as the RFC 2119 "MUST", which is rather unfortunate. I believe I have conveyed the original meaning though. Comments welcome! Once you're OK too, I'll put up a short RFC to ack/back this PR (and the ones for the other documents).

@Crell @iluuu1994 @Girgias

@derickr derickr requested a review from iluuu1994 December 4, 2024 11:22
Copy link
Member

@Girgias Girgias left a comment

Choose a reason for hiding this comment

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

From my PoV this follows the established guidelines.

or on GitHub.

Extensions may move between these three categories over time. ``hash`` and
``json`` recently moved from "bundled" to "required" (though I believe
Copy link
Contributor

Choose a reason for hiding this comment

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

Recently as of when? The example should fix a release in which the move happened, for clarity.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've updated that.


Extensions may move between these three categories over time. ``hash`` and
``json`` recently moved from "bundled" to "required" (though I believe
extensions never move out of the "required" category). ``sodium`` and ``ffi``
Copy link
Contributor

Choose a reason for hiding this comment

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

The parenthetical also seems too personal for a policy document.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've updated that.

@derickr derickr force-pushed the consolidate-coding-standards branch from a104093 to 8b81759 Compare December 11, 2024 12:13
Copy link
Member

@iluuu1994 iluuu1994 left a comment

Choose a reason for hiding this comment

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

Looks good overall

Copy link
Member

@iluuu1994 iluuu1994 left a comment

Choose a reason for hiding this comment

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

LGTM!

@derickr
Copy link
Member Author

derickr commented Dec 16, 2024

@Crell, @iluuu1994, @Girgias — I have now also integrated CODING_STANDARDS.md too.

I originally hadn't realised that the Policy Repository RFC referred to that as well. This text has been copied over mostly verbatim, but could potentially use some tweaks.

(``int8_t``, ``int16_t``, ``int32_t``, ``int64_t`` and their unsigned
counterparts) are supposed to be available.

#. Functions that are given pointers to resources MUST NOT free them.
Copy link
Member

Choose a reason for hiding this comment

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

This is kind of a silly rule. We often transfer ownership of a value to some other function. I agree that this should be documented, the programmer currently usually needs to read the implementation to understand whether ownership is transferred. We may potentially improve this with annotations. Clang has some annotations, but they are not particularly well documented. https://releases.llvm.org/15.0.0/tools/clang/docs/AttributeReference.html#id686

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree that we should change this, but this PR isn't about changing existing coding standards.

with ``strlen()``. Write your functions in such a way so that they'll take
advantage of the length property, both for efficiency and in order for them
to be binary-safe. Functions that change strings and obtain their new lengths
while doing so, should return that new length, so it doesn't have to be
Copy link
Member

Choose a reason for hiding this comment

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

This is very outdated, since we have zend_string.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, it is. CODING_STANDARDS hadn't been updated for a while, I suppose.

while doing so, should return that new length, so it doesn't have to be
recalculated with ``strlen()`` (e.g. ``php_addslashes()``).

#. You MUST NOT use ``strncat()``. If you're absolutely sure you know what
Copy link
Member

Choose a reason for hiding this comment

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

Weird call-out, there are so many other dangerous C functions. 🙂

Copy link
Member Author

Choose a reason for hiding this comment

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

It was in the original document. It probably has a 20 year old history as to why it is here!

Be generous with whitespace and braces. Keep one empty line between the variable
declaration section and the statements in a block, as well as between logical
statement groups in a block. Maintain at least one empty line between two
functions, preferably two. Always prefer:
Copy link
Member

Choose a reason for hiding this comment

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

preferably two

We don't do this anywhere. Can we drop that?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm okay dropping that, but this PR isn't about changing existing rules. Perhaps it makes sense to put these changes in the RFC that I will send to internals?

MUST follow the standard prefixing conventions during their initial
implementation.

The file labelled ``EXPERIMENTAL`` SHOULD include the following information:
Copy link
Member

Choose a reason for hiding this comment

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

  1. It's unclear to me whether this refers to internal or user functions.
  2. We have never done this in practice, and I think we should completely drop this section.

Copy link
Member

Choose a reason for hiding this comment

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

We had a lot of extensions marked as EXPERIMENTAL in the olden days, but that should no longer happen. Only stable extensions should be added to php-src. New functions go into master only, and master is somewhat "experimental" anyway, so I agree that there is no need for this section.

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree. I think we should rewrite this section, and rewrite it to:

New extensions MUST start out as third-party extensions, or in an experimental branch, until an RFC is passed to add them to the core distribution.

Copy link
Member Author

@derickr derickr left a comment

Choose a reason for hiding this comment

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

I also saw a few of these legacy comments. But I didn't want to make changes in this PR just yet.

I suppose the best way is to list all the changes on top of the consolidation in the RFC that I will send to internals. And only then make these as suggested in separate commits?

(``int8_t``, ``int16_t``, ``int32_t``, ``int64_t`` and their unsigned
counterparts) are supposed to be available.

#. Functions that are given pointers to resources MUST NOT free them.
Copy link
Member Author

Choose a reason for hiding this comment

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

I agree that we should change this, but this PR isn't about changing existing coding standards.

with ``strlen()``. Write your functions in such a way so that they'll take
advantage of the length property, both for efficiency and in order for them
to be binary-safe. Functions that change strings and obtain their new lengths
while doing so, should return that new length, so it doesn't have to be
Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, it is. CODING_STANDARDS hadn't been updated for a while, I suppose.

while doing so, should return that new length, so it doesn't have to be
recalculated with ``strlen()`` (e.g. ``php_addslashes()``).

#. You MUST NOT use ``strncat()``. If you're absolutely sure you know what
Copy link
Member Author

Choose a reason for hiding this comment

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

It was in the original document. It probably has a 20 year old history as to why it is here!

Be generous with whitespace and braces. Keep one empty line between the variable
declaration section and the statements in a block, as well as between logical
statement groups in a block. Maintain at least one empty line between two
functions, preferably two. Always prefer:
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm okay dropping that, but this PR isn't about changing existing rules. Perhaps it makes sense to put these changes in the RFC that I will send to internals?

MUST follow the standard prefixing conventions during their initial
implementation.

The file labelled ``EXPERIMENTAL`` SHOULD include the following information:
Copy link
Member Author

Choose a reason for hiding this comment

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

I agree. I think we should rewrite this section, and rewrite it to:

New extensions MUST start out as third-party extensions, or in an experimental branch, until an RFC is passed to add them to the core distribution.

@iluuu1994
Copy link
Member

I'm not too stoked discussing changes of this document with internals, because it's really not relevant to the vast majority of people...

@cmb69
Copy link
Member

cmb69 commented Dec 18, 2024

Maybe we need a real-internals mailing list. ;)

@derickr
Copy link
Member Author

derickr commented Dec 18, 2024 via email

@derickr derickr force-pushed the consolidate-coding-standards branch from ac8c52f to f534be7 Compare December 18, 2024 16:30
Comment on lines +384 to +385
New extensions MUST start out as third-party extensions, or in an experimental
branch, until an RFC is passed to add them to the core distribution.
Copy link
Member

Choose a reason for hiding this comment

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

I would scrap the whole section as it's just given that you cannot introduce a new extension without the RFC so the rest are just implications that don't need to be specified here.

Comment on lines +241 to +242
#. Functions that are given pointers to resources SHOULD NOT free them, unless
this is documented.
Copy link
Member

Choose a reason for hiding this comment

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

This really depends on the function and logic. I think this whole think should be removed as well as it's context dependent.

Comment on lines +276 to +277
#. You SHOULD use the ``smart_str_*`` family of functions for string creation,
instead of relying on the C-library versions, such as ``strncat()``.
Copy link
Member

Choose a reason for hiding this comment

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

smart_str_* should be used only if the string is constructed with multiple variable pieces. Otherwise basic creation should be done using zend_string_alloc and similar (e.g. short concatenations using zend_string_concat2 and zend_string_concat3).

That said I'm not really sure why this is in coding standard. This should really be part of some extension documentation like in doc/ or php internals book.

@derickr derickr merged commit bfdf93a into php:main Jan 28, 2025
1 check passed
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.

6 participants