Skip to content

Conversation

@SigureMo
Copy link
Member

PR Category

Execute Infrastructure

PR Types

Improvements

Description

允许用户使用宏 PADDLE_EXTENSION_NAME 来获取 extension 的 name

@paddle-bot
Copy link

paddle-bot bot commented Jul 31, 2025

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@SigureMo SigureMo requested a review from Copilot July 31, 2025 07:47
Copy link
Contributor

Copilot AI left a 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_name to 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]
Copy link

Copilot AI Jul 31, 2025

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.

Suggested change
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.")

Copilot uses AI. Check for mistakes.
# Allow user use PADDLE_EXTENSION_NAME to access shared library name
names = extension.name.split('.')
name = names[-1]
define = f'-DPADDLE_EXTENSION_NAME={name}'
Copy link

Copilot AI Jul 31, 2025

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++.

Suggested change
define = f'-DPADDLE_EXTENSION_NAME={name}'
define = f'-DPADDLE_EXTENSION_NAME="{name}"'

Copilot uses AI. Check for mistakes.
@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 14.28571% with 6 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (develop@6b610ee). Learn more about missing BASE report.

Files with missing lines Patch % Lines
...thon/paddle/utils/cpp_extension/extension_utils.py 20.00% 4 Missing ⚠️
python/paddle/utils/cpp_extension/cpp_extension.py 0.00% 2 Missing ⚠️

❌ 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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@SigureMo SigureMo merged commit 83ac718 into PaddlePaddle:develop Aug 4, 2025
79 of 82 checks passed
@SigureMo SigureMo deleted the cpp-extension/auto-define-extension-name-macro branch August 4, 2025 08:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants