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

Add /*<type>*/ annotations everwhere #2986

Merged
merged 1 commit into from Sep 11, 2022
Merged

Conversation

wingdeans
Copy link
Contributor

@wingdeans wingdeans commented Aug 28, 2022

Addresses #2981

Your checklist for this pull request

  • I've read the guidelines for contributing to this repository
  • I made sure to follow the project's coding style
  • I've documented or updated the documentation of every function and struct this PR changes. If not so I've explained why.
  • I've added tests that prove my fix is effective or that my feature works (if possible)
  • I've updated the rizin book with the relevant information (if needed)

Detailed description

This commit adds /*<type>*/ annotations to almost all RzList, RzVector, RzPVector, and RzGraph occurrences in function declarations. The missing annotations were detected using a libclang python script and the types were then manually added.

There are a few non-comment changes which shouldn't affect any functionality. Let me know if I should revert them.

  • removed unused intern_table arguments in pyc_dis.c, pyc_dis.h, asm_pyc.c
  • removed unused classes argument from place_nodes in agraph.c
  • removed unused recurse and recurse_bb functions in canalysis.c
  • removed unused vars field from RzPrint struct
  • removed unused RzAnalysisType* structs from rz_analysis.h
  • removed unused list field from RzEgg struct
  • fixed bug in bp_plugin.c where duplication checking logic iterates over the wrong list
  • removed unused q_regs field from RzDebug struct
  • removed unused backtrace field from RzDebugPlugin struct
  • removed unused classes_list field from RzBinNXOObj struct
  • removed unused methods_list and classes_list fields from RzBinZimgObj struct

TODO

  • extend checks to struct members

Test plan

The annotations are currently only for developer ergonomics and are not verified in any way. rz-bindgen utilizes them, but only from a limited subset of the headers, so there is no way to verify their correctness.

@wingdeans
Copy link
Contributor Author

wingdeans commented Aug 30, 2022

Not sure what the RzDebugPlugin fields tids and kill_list are supposed to return, but they actually have usages (returning null) unlike the other things I removed.

Do these function pointers have a specified return type, or should I or remove them (or annotate with void*)?

@XVilka
Copy link
Member

XVilka commented Aug 31, 2022

@wingdeans annotate with void * for now.

@wingdeans
Copy link
Contributor Author

wingdeans commented Sep 5, 2022

Only errors are due to inconsistencies in rz-hexagon (PR here)

Missing type comment at <rizin/librz/asm/arch/hexagon/hexagon.h:151:10> (token is not a comment)
Mismatched function annotation for hex_const_ext_free at <rizin/librz/asm/arch/hexagon/hexagon_arch.h:69:13> : None (was RZ_NULLABLE at <rizin/librz/asm/arch/hexagon/hexagon_arch.c:226:13>
Missing type comment at <rizin/librz/asm/arch/hexagon/hexagon_arch.c:787:59> (token is not a comment)

@XVilka
Copy link
Member

XVilka commented Sep 7, 2022

@wingdeans what is the status of this PR? Could you please update and rebase it on top of the latest dev?

@wingdeans
Copy link
Contributor Author

Only errors are due to inconsistencies in rz-hexagon (PR here)

Missing type comment at <rizin/librz/asm/arch/hexagon/hexagon.h:151:10> (token is not a comment)
Mismatched function annotation for hex_const_ext_free at <rizin/librz/asm/arch/hexagon/hexagon_arch.h:69:13> : None (was RZ_NULLABLE at <rizin/librz/asm/arch/hexagon/hexagon_arch.c:226:13>
Missing type comment at <rizin/librz/asm/arch/hexagon/hexagon_arch.c:787:59> (token is not a comment)

The linter is ready, it just needs rizinorg/rz-hexagon#78 in rz-hexagon to address the emitted warnings.

@wingdeans
Copy link
Contributor Author

* removed unused `intern_table` arguments in `pyc_dis.c`, `pyc_dis.h`, `asm_pyc.c`
* removed unused `classes` argument from `place_nodes` in `agraph.c`
* removed unused `recurse` and `recurse_bb` functions in `canalysis.c`
* removed unused `vars` field from `RzPrint` struct
* removed unused `RzAnalysisType*` structs from `rz_analysis.h`
* removed unused `list` field from `RzEgg` struct
* fixed bug in `bp_plugin.c` where duplication checking logic iterates over the wrong list
* removed unused `q_regs` field from `RzDebug` struct
* removed unused `backtrace` field from `RzDebugPlugin` struct
* removed unused `classes_list` field from `RzBinNXOObj` struct
* removed unused `methods_list` and `classes_list` fields from `RzBinZimgObj` struct

There are a lot of non-comment changes, for generic types I couldn't infer the specializations for since they weren't being used.

@wargio
Copy link
Member

wargio commented Sep 7, 2022

RzBinNXOObj

why you are exporting plugin headers? the only headers that should be exported are those in the rzlib/include folder

@XVilka
Copy link
Member

XVilka commented Sep 7, 2022

@wingdeans yes, step by step. Having the linter opens the potential to improve the inference and detection.

@wingdeans
Copy link
Contributor Author

RzBinNXOObj

why you are exporting plugin headers? the only headers that should be exported are those in the rzlib/include folder

The goal is to add type annotations everywhere and make sure that they are consistent between definition and declaration, with the linter checking this. I can take them out if it's too much but I think it's useful for development (and maybe adding actual typechecking in the future).

Copy link
Member

@wargio wargio left a comment

Choose a reason for hiding this comment

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

Nice cleanup

@wargio wargio requested a review from XVilka September 8, 2022 20:10
@XVilka
Copy link
Member

XVilka commented Sep 11, 2022

@wingdeans LGTM, but please rebase and fix the conflicts.

Adds /*<type>*/ comments and a linter check from rz-bindgen to enforce
their existence and consistency

Also includes the following fixes made when adding the annotations:
* removed unused intern_table arguments in pyc_dis.c, pyc_dis.h, asm_pyc.c
* removed unused classes argument from place_nodes in agraph.c
* removed unused recurse and recurse_bb functions in canalysis.c
* removed unused vars field from RzPrint struct
* removed unused RzAnalysisType* structs from rz_analysis.h
* removed unused list field from RzEgg struct
* fixed bug in bp_plugin.c where duplication checking logic iterates over the wrong list
* removed unused q_regs field from RzDebug struct
* removed unused backtrace field from RzDebugPlugin struct
* removed unused classes_list field from RzBinNXOObj struct
* removed unused methods_list and classes_list fields from RzBinZimgObj struct
Copy link
Member

@XVilka XVilka left a comment

Choose a reason for hiding this comment

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

Lets merge this and fix the hexagon issue separately.

@XVilka XVilka merged commit 59b38e6 into rizinorg:dev Sep 11, 2022
@XVilka
Copy link
Member

XVilka commented Sep 11, 2022

I merged it as is then and created a separate issue to fix those warnings: #3020
Please address it as soon as possible. Thank you!

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.

None yet

3 participants