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

Fix Argument Processing for Non-Pointer Types in Clang Binding Script… #1157

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

famouswizard
Copy link

Problem:
The original code for processing function arguments contains a logical error when handling non-pointer types. Specifically, the following fragment assumes that every argument is a pointer type and calls get_pointee() without checking for its validity:

'inArgs': [
    {
        'name': arg.spelling,
        'type': arg.type.spelling,
    } for arg in node.get_arguments() if arg.type.get_canonical().get_pointee().is_const_qualified() or arg.type.get_canonical().is_const_qualified()
],
'outArgs': [
    {
        'name': arg.spelling,
        'type': arg.type.spelling,
    } for arg in node.get_arguments() if not (arg.type.get_canonical().get_pointee().is_const_qualified() or arg.type.get_canonical().is_const_qualified())
],

If the argument is not a pointer (e.g., int or float), get_pointee() will return None, causing an exception when attempting to call is_const_qualified().


Fix:
Add a check to ensure that get_pointee() is not None before attempting to access its methods. Updated code:

'inArgs': [
    {
        'name': arg.spelling,
        'type': arg.type.spelling,
    } for arg in node.get_arguments() if (
        arg.type.get_canonical().get_pointee() and arg.type.get_canonical().get_pointee().is_const_qualified()
    ) or arg.type.get_canonical().is_const_qualified()
],
'outArgs': [
    {
        'name': arg.spelling,
        'type': arg.type.spelling,
    } for arg in node.get_arguments() if not (
        (arg.type.get_canonical().get_pointee() and arg.type.get_canonical().get_pointee().is_const_qualified())
        or arg.type.get_canonical().is_const_qualified()
    )
],

Reasoning:

  1. Null Safety: The added condition ensures that get_pointee() is only called if it returns a valid object, preventing potential exceptions.
  2. Preserved Logic: The core logic remains intact, correctly categorizing inArgs and outArgs based on the const qualifier.

Importance:
This fix is critical for reliability. Without it, the code will fail when encountering non-pointer arguments, such as primitive types (int, float). This would make the script unusable for analyzing functions with non-pointer parameters. The adjustment ensures robust handling of all argument types, aligning the implementation with its intended functionality.

… in decls_json.py

This update resolves an issue in the argument processing logic where get_pointee() was called without checking for validity. This caused exceptions when handling non-pointer arguments (e.g., int, float). The fix ensures that the method is only called on valid pointer types, improving the reliability of the script when analyzing functions with diverse argument types.
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.

1 participant