Skip to content

Fix problem with calculation of the 'c_ast.FuncDecl' offset#11

Merged
eerimoq merged 2 commits intoeerimoq:masterfrom
eps-id:fix_error_Struct_object_has_no_attribute_args
Oct 23, 2025
Merged

Fix problem with calculation of the 'c_ast.FuncDecl' offset#11
eerimoq merged 2 commits intoeerimoq:masterfrom
eps-id:fix_error_Struct_object_has_no_attribute_args

Conversation

@eps-id
Copy link
Contributor

@eps-id eps-id commented Oct 22, 2025

When parsing some legacy code the inspect module ended up with following error

error: 'Struct' object has no attribute 'args'

It turned out, that the reason was a wrong offset of self.file_ast.ext[i] handed over to function rename_parameters which then tried to replace functions parameters in 'Struct' objects.

The quick hack to solve this issue was to search for the first c_ast.FuncDecl in self.file_ast.ext and take this position as func_offset.

@eps-id
Copy link
Contributor Author

eps-id commented Oct 22, 2025

After a short look on the failed tests ist seems to be a problem of the supplied code in the PR.
It also turned out, that the quick fix was just solving one issue caused by the legacy code but in the meantime another code snippet broke it again.

When compiling the legacy code in WSL using Ubuntu-24.04 and gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0 some part of the code pulls the following header into our translation unit.

# 27 "/usr/include/x86_64-linux-gnu/bits/types/cookie_io_functions_t.h" 3 4
typedef __ssize_t cookie_read_function_t (void *__cookie, char *__buf,
                                          size_t __nbytes);

This is accidentally parsed as "typedef" by Nala but tagged as "ast_c.FuncDecl".

As a result this function along with some others end up to be in self.typedefs_code which leads to an error later on, as "cookie_read_function_t" also is added to self.func_names.

…where function pointer typedefs are present in the translation unit.
@eerimoq eerimoq merged commit 23ea73d into eerimoq:master Oct 23, 2025
1 of 2 checks passed
@eerimoq
Copy link
Owner

eerimoq commented Oct 23, 2025

hmm maybe I shouldn't have merged it because the testes fail =) Any change you can create a new PR with a fix?

Github actions now use Ubuntu 22.04, which fixes the weird test failures we had before.

@eps-id
Copy link
Contributor Author

eps-id commented Oct 23, 2025

I fixed a few test on my fork, but 3 are still failing. I will check tomorrow if I can fix those to.
At least one problem comes from using a modern compiler. It seems that pycparser cannot handle __typeof__() which is uses nowadays in typedefs for nullptr_t and size_t.
But this can easily be avoided by adding -std=c11 or -std=c17 on the gcc commandline.
Are ther any thoughts on using a modern AST parser like clang.cindex which also can be used together with python?

@eerimoq
Copy link
Owner

eerimoq commented Oct 23, 2025

I'm open to make pretty much any change that improves Nala. I'll not have time to make any changes myself, but can bump the version and publish new releases if needed.

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.

2 participants