Skip to content

gh-162214: Test if macros are defined in generated cases code - #162215

Open
vstinner wants to merge 2 commits into
python:mainfrom
vstinner:wundef_cases
Open

vstinner wants to merge 2 commits into
python:mainfrom
vstinner:wundef_cases

Conversation

@vstinner

@vstinner vstinner commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Example:

  • Replace "#if !_Py_TAIL_CALL_INTERP" with "#ifndef _Py_TAIL_CALL_INTERP".
  • Replace "#if _Py_TIER2" with "#ifdef _Py_TIER2".

Add "This file is generated by (...)" header to generated files.

Example:

* Replace "#if !_Py_TAIL_CALL_INTERP"
  with "#ifndef _Py_TAIL_CALL_INTERP".
* Replace "#if _Py_TIER2" with "#ifdef _Py_TIER2".

Add "This file is generated by (...)" header to generated files.
@vstinner

Copy link
Copy Markdown
Member Author

@vstinner

Copy link
Copy Markdown
Member Author

Hum, I'm not sure if my change is correct. _Py_TAIL_CALL_INTERP macro can be defined to 0 by configure.ac:

if test "$withval" = no
then
  AC_DEFINE([_Py_TAIL_CALL_INTERP], [0],
  [Define if you want to use tail-calling interpreters in CPython.])
  AC_MSG_RESULT([no])
fi

By the fault, the _Py_TIER2 is not defined. The _Py_TIER2 macro is defined by configure.ac using -D compiler flag, example: -D_Py_TIER2=1. Corresponding Windows code in PCbuild/pythoncore.vcxproj:

<PreprocessorDefinitions Condition="'$(UseTIER2)' != '' and '$(UseTIER2)' != '0'">_Py_TIER2=$(UseTIER2);%(PreprocessorDefinitions)</PreprocessorDefinitions>

_Py_TAIL_CALL_INTERP macro is not defined by default. configure.ac can defined it to 1 or to 0. Corresponding Windows code in PCbuild/pythoncore.vcxproj:

<PreprocessorDefinitions Condition="'$(UseTailCallInterp)' == 'true'">_Py_TAIL_CALL_INTERP=1;%(PreprocessorDefinitions)</PreprocessorDefinitions>

@vstinner

Copy link
Copy Markdown
Member Author

I updated the PR to test also _Py_TAIL_CALL_INTERP macro value (no only check if it's defined). For example, replace #ifdef _Py_TAIL_CALL_INTERP with #if defined(_Py_TAIL_CALL_INTERP) && _Py_TAIL_CALL_INTERP.

Maybe it would be easier to revert this change and instead remove AC_DEFINE([_Py_TAIL_CALL_INTERP], [0], ...) from configure.ac. What do you think?

@vstinner

Copy link
Copy Markdown
Member Author

This PR changes generated code (and scripts to generate the code). I created #162218 for manual changes on the same macros.

@NekoAsakura

Copy link
Copy Markdown
Member

For _Py_TAIL_CALL_INTERP, I think it's simpler to give it a default '0':

--- a/Python/ceval_macros.h
+++ b/Python/ceval_macros.h
@@ -59,3 +59,7 @@
     #define USE_COMPUTED_GOTOS 0
 #endif
 
+#ifndef _Py_TAIL_CALL_INTERP
+#   define _Py_TAIL_CALL_INTERP 0
+#endif
+

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.

2 participants