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

[3.8] bpo-37250: put back tp_print for backwards compatibility #14193

Merged
merged 4 commits into from
Jun 25, 2019

Conversation

jdemeyer
Copy link
Contributor

@jdemeyer jdemeyer commented Jun 18, 2019

PR for 3.8 only, since this is supposed to be a temporary compatibility measure.

https://bugs.python.org/issue37250

@ncoghlan
Copy link
Contributor

+1, but let's refrain from merging until there's clearer consensus on the tracker issue for the pragmatic Py3.8-only source compatibility fix.

@@ -256,6 +256,9 @@ typedef struct _typeobject {
destructor tp_finalize;
vectorcallfunc tp_vectorcall;

/* Unused, kept for backwards compatibility in CPython 3.8 only */
int (*tp_print)(PyObject *, FILE *, int);
Copy link
Contributor

@ncoghlan ncoghlan Jun 18, 2019

Choose a reason for hiding this comment

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

Does adding the Py_DEPRECATED(3.8) macro here cause the tp_print reference in the test to generate a compiler warning?

If it does, that would be a good thing to add (as long as we also have a way to disable the deprecation warning in the test suite, which I presume we do)

Reference: https://docs.python.org/3.8/c-api/intro.html#c.Py_DEPRECATED

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That works but then the deprecation warning will be shown when compiling _testcapi.c. I'll add a guard for that. If that's controversial, I'll gladly remove it.

(off-topic: since this is the only such warning shown, it seems that we never actually test deprecated functionality of the C API, which is worrying)

@@ -256,6 +256,9 @@ typedef struct _typeobject {
destructor tp_finalize;
vectorcallfunc tp_vectorcall;

/* Unused, kept for backwards compatibility in CPython 3.8 only */
Copy link
Member

Choose a reason for hiding this comment

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

Please mention that it will be removed from Python 3.8. You may add "bpo-37250: " prefix.

Modules/_testcapimodule.c Show resolved Hide resolved
Include/pyport.h Outdated
@@ -510,6 +510,7 @@ extern "C" {
* Py_DEPRECATED(3.4) typedef int T1;
* Py_DEPRECATED(3.8) PyAPI_FUNC(int) Py_OldFunction(void);
*/
#ifndef Py_DEPRECATED
Copy link
Member

Choose a reason for hiding this comment

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

Why do you modify pyport.h?

Copy link
Member

Choose a reason for hiding this comment

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

IMHO it's fine if compiling _testcapimodule.c emits a deprecation warning. If it becomes an issue, we can just remove the test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IMHO it's fine if compiling _testcapimodule.c emits a deprecation warning.

The more warnings are shown, the less value there is in those warnings. A single warning during compilation stands out, an additional warning in between many not. So we should strive for compiling CPython without any warnings.

If it becomes an issue, we can just remove the test.

I think that's the worst solution. We typically test deprecated functionality in pure Python modules, why shouldn't we test deprecated C API?

Copy link
Contributor

Choose a reason for hiding this comment

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

Reading https://stackoverflow.com/questions/13459602/how-can-i-get-rid-of-deprecated-warnings-in-deprecated-functions-in-gcc/ suggests there are a few ways we can go here:

  1. Mark the _testcapi init function itself as deprecated, so compilers won't care that it accesses deprecated symbols.
  2. Start defining compiler specific _Py_PUSH_PRAGMA_IGNORE_DEPRECATION_WARNINGS and _Py_POP_PRAGMA macros and use those to selectively silence compiler warnings
  3. Use the testcapi warnings to check that deprecated C APIs actually are deprecated (doing that long term might involve pulling out a separately compiled module for those though, so we can more easily distinguish them from actual warnings in the main interpreter and standard library build process)

For right now, I'd suggest seeing if the warning goes away if you mark the testcapi module's init function as deprecated.

Copy link
Contributor

@willingc willingc left a comment

Choose a reason for hiding this comment

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

Thanks @jdemeyer. This looks good to me. @encukou @ncoghlan Do one of you wish to review and merge?

@encukou
Copy link
Member

encukou commented Jun 25, 2019

Will do. Thanks to everyone involved!

@encukou encukou merged commit d917cfe into python:3.8 Jun 25, 2019
@jdemeyer jdemeyer deleted the define_tp_print branch June 25, 2019 11:39
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.

8 participants