Skip to content

Conversation

@svalentin
Copy link
Collaborator

It generates C code to print to stdout, but tries to preserve the error state and not affect the code it's added to.

Added test for it, but also tested this by adding
builder.debug_print(typ) in add_non_ext_class_attr_ann and it prints the class name.
It's also useful to use it like builder.debug_print("MARKER") and then to search in the generated C code for MARKER. For more complex debugging tasks, this is useful in finding your way around the generated C code and quickly looking at the interesting part.

I saw that there's already a misc op CPyDebug_Print. I haven't seen it used though. I think we can remove that one if this is proving useful.

It generates C code to print to stdout, but tries to preserve the error
state and not affect the code it's added to.

Added test for it, but also tested this by adding
`builder.debug_print(typ)` in `add_non_ext_class_attr_ann` and it prints
the class name.
It's also useful to use it like `builder.debug_print("MARKER")` and then
to search in the generated C code for MARKER. For more complex debugging
tasks, this is useful in finding your way around the generated C code
and quickly looking at the interesting part.

I saw that there's already a misc op `CPyDebug_Print`. I haven't seen it
used though. I think we can remove that one if this is proving useful.
@svalentin svalentin requested a review from JukkaL January 27, 2025 23:04
Copy link
Collaborator

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

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

Thanks, looks good!

@JukkaL JukkaL merged commit c08719d into python:master Jan 28, 2025
12 checks passed
@svalentin svalentin deleted the debug-primitive branch January 28, 2025 13:31
x612skm pushed a commit to x612skm/mypy-dev that referenced this pull request Feb 24, 2025
…ython#18552)

It generates C code to print to stdout, but tries to preserve the error
state and not affect the code it's added to.

Added test for it, but also tested this by adding
`builder.debug_print(typ)` in `add_non_ext_class_attr_ann` and it prints
the class name.
It's also useful to use it like `builder.debug_print("MARKER")` and then
to search in the generated C code for MARKER. For more complex debugging
tasks, this is useful in finding your way around the generated C code
and quickly looking at the interesting part.

I saw that there's already a misc op `CPyDebug_Print`. I haven't seen it
used though. I think we can remove that one if this is proving useful.
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