Skip to content
/ server Public

MDEV-35461 Remove redundant checks for standard library functions #4017

Open
longjinvan wants to merge 1 commit intoMariaDB:mainfrom
longjinvan:MDEV-35461
Open

MDEV-35461 Remove redundant checks for standard library functions #4017
longjinvan wants to merge 1 commit intoMariaDB:mainfrom
longjinvan:MDEV-35461

Conversation

@longjinvan
Copy link

@longjinvan longjinvan commented Apr 25, 2025

Description

This commit removes function checks for standard library functions that are guaranteed to be available when using C99 standards[1]. These include:

  • ldiv
  • memcpy
  • memmove
  • perror
  • setlocale
  • strcoll
  • strerror
  • strpbrk
  • strtoll
  • strtoul
  • strtoull
  • vsnprintf

For memcpy and vsnprintf, the global checks are removed but the defines are still passed locally to third-party libraries (zlib and readline) via their respective CMakeLists.txt, since those libraries still reference them internally.

The corresponding cached values in cmake/os/WindowsCache.cmake are also removed where the checks no longer exist.

All new code of the whole pull request, including one or several files that are either new files or modified ones, are contributed under the BSD-new license. I am contributing on behalf of my employer Amazon Web Services, Inc.

[1] https://www.dii.uchile.cl/~daespino/files/Iso_C_1999_definition.pdf

How can this PR be tested?

✅ Build succeed.
✅ All MTR tests pass.

Basing the PR against the correct MariaDB version

This is a code change related to build performance improvement applicable to multiple versions, and the PR is based against the latest MariaDB development branch.

PR quality check

✅ I have checked the CODING_STANDARDS.md file and my PR conforms to this where appropriate.
✅ For any trivial modifications to the PR, I am ok with the reviewer making the changes themselves.

Copyright

All new code of the whole pull request, including one or several files that are either new files or modified ones, are contributed under the BSD-new license. I am contributing on behalf of my employer Amazon Web Services, Inc.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@svoj svoj added the External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements. label Apr 25, 2025
@svoj
Copy link
Contributor

svoj commented Apr 25, 2025

@vuvova in MDEV-35461 you suggested that these checks should be removed. Which means they have to be removed along with compatibility code spread across other files.

Could you confirm it is still your preference?

@vuvova
Copy link
Member

vuvova commented Apr 26, 2025

Yes, sure, why would we want garbage like #ifdef HAVE_PERROR in the code, when PERROR is always defined?

@svoj svoj self-requested a review April 26, 2025 11:54
Copy link
Contributor

@svoj svoj left a comment

Choose a reason for hiding this comment

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

Please cleanup compatibility code as well.

@svoj
Copy link
Contributor

svoj commented Jul 9, 2025

@longjinvan Hi! It's been over 2 months since changes were requested. Are you still interested in completing this task?

@longjinvan
Copy link
Author

Hi @svoj, I'm still working on this task, I will submit a new PR as soon as possible. Thanks!

@svoj
Copy link
Contributor

svoj commented Jul 9, 2025

@longjinvan alright. It'd be better to update this pull request though, rather than creating new one. I will convert this one to draft so that it is off of our radar. Reset draft status once it is updated.

@svoj svoj marked this pull request as draft July 9, 2025 19:22
@grooverdan
Copy link
Member

(windows)

include\m_string.h(167,30): fatal error C1012: unmatched parenthesis: missing '('
#if defined(NO_STRTOLL_PROTO))
                             ^

@longjinvan longjinvan requested a review from svoj October 14, 2025 17:06
@longjinvan longjinvan marked this pull request as ready for review October 14, 2025 17:07
Copy link
Contributor

@svoj svoj left a comment

Choose a reason for hiding this comment

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

git grep HAVE_ALLOCA and git grep HAVE_MEMCPY still return quite a few items that should be cleaned up, right?

SET(HAVE_STRTOUL 1 CACHE INTERNAL "")
SET(HAVE_STRTOULL 1 CACHE INTERNAL "")
SET(HAVE_VSNPRINTF 1 CACHE INTERNAL "")
ENDIF() No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

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

Given that you removed all occurrences of these defines, why do you have to keep this file? There must be no point in having them in WindowsCache.cmake either.

Copy link
Author

Choose a reason for hiding this comment

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

Fixed.

#else
vsprintf (msg_buf, format, args);
msg_buf[sizeof(msg_buf) - 1] = '\0'; /* overflow? */
#endif
Copy link
Contributor

Choose a reason for hiding this comment

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

readline is a third party library. It would be good to keep it intact and add -DHAVE_VSNPRINTF to extra/readline/CMakeLists.txt instead. Along with all other required definitions.

The very same point applies to zlib, its CMakeLists.txt should be updated.

Copy link
Author

Choose a reason for hiding this comment

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

Fixed.

@longjinvan longjinvan force-pushed the MDEV-35461 branch 2 times, most recently from bd04ca2 to 1119725 Compare March 4, 2026 23:10
@gkodinov gkodinov changed the title MDEV-35461 Remove redundant checks for standard library functions MDEV-35461 Remove redundant checks for standard library functions Mar 18, 2026
Copy link
Member

@gkodinov gkodinov left a comment

Choose a reason for hiding this comment

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

Thank you for your submission. I'm terribly sorry that it is taking that long for the review to conclude. I hope that you're still willing to work on this.

The diff LGTM.

Please stand by for the final review.

Remove function checks that are guaranteed by C99 standards to reduce
the excessive time spent during CMake configuration step. Also, clean
up related compatibility code.

All new code of the whole pull request, including one or several files
that are either new files or modified ones, are contributed under the
BSD-new license. I am contributing on behalf of my employer Amazon Web
Services, Inc.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements.

Development

Successfully merging this pull request may close these issues.

6 participants