-
Notifications
You must be signed in to change notification settings - Fork 5.9k
[CppExtension] Auto define PADDLE_EXTENSION_NAME macro
#74338
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
[CppExtension] Auto define PADDLE_EXTENSION_NAME macro
#74338
Conversation
|
你的PR提交成功,感谢你对开源项目的贡献! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces automatic definition of the PADDLE_EXTENSION_NAME macro for C++ extensions, allowing users to access the extension name from within their C++ code. The implementation extracts the last component of the extension's dotted name and defines it as a compilation macro.
- Adds a new function
define_paddle_extension_nameto automatically generate the macro definition - Integrates the macro definition into the extension build process by calling it for all extensions during compilation
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| python/paddle/utils/cpp_extension/extension_utils.py | Adds the define_paddle_extension_name function to extract extension name and create macro definition |
| python/paddle/utils/cpp_extension/cpp_extension.py | Integrates the macro definition into the build process by calling it for each extension |
| def define_paddle_extension_name(extension): | ||
| # Allow user use PADDLE_EXTENSION_NAME to access shared library name | ||
| names = extension.name.split('.') | ||
| name = names[-1] |
Copilot
AI
Jul 31, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The extension name is used directly in the macro definition without validation or sanitization. This could lead to injection issues if the name contains special characters or shell metacharacters. Consider validating that the name contains only safe characters (alphanumeric and underscores) before using it in the compile flag.
| name = names[-1] | |
| name = names[-1] | |
| # Validate that the name contains only alphanumeric characters and underscores | |
| if not re.match(r'^[a-zA-Z0-9_]+$', name): | |
| raise ValueError(f"Invalid extension name: {name}. Only alphanumeric characters and underscores are allowed.") |
| # Allow user use PADDLE_EXTENSION_NAME to access shared library name | ||
| names = extension.name.split('.') | ||
| name = names[-1] | ||
| define = f'-DPADDLE_EXTENSION_NAME={name}' |
Copilot
AI
Jul 31, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The macro value should be quoted to handle names that might contain spaces or special characters. Consider changing to f'-DPADDLE_EXTENSION_NAME="{name}"' to ensure the macro expands to a proper string literal in C++.
| define = f'-DPADDLE_EXTENSION_NAME={name}' | |
| define = f'-DPADDLE_EXTENSION_NAME="{name}"' |
Codecov Report❌ Patch coverage is
❌ Your patch status has failed because the patch coverage (14.28%) is below the target coverage (90.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## develop #74338 +/- ##
==========================================
Coverage ? 14.28%
==========================================
Files ? 2
Lines ? 7
Branches ? 0
==========================================
Hits ? 1
Misses ? 6
Partials ? 0 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
PR Category
Execute Infrastructure
PR Types
Improvements
Description
允许用户使用宏
PADDLE_EXTENSION_NAME来获取 extension 的 name