Skip to content

bpo-32805: Fix compiler warnings in gcmodule.c #11010

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

Merged
merged 1 commit into from
Mar 6, 2019

Conversation

jkloth
Copy link
Contributor

@jkloth jkloth commented Dec 7, 2018

Use a C data type that matches DTrace's data type size for long.

https://bugs.python.org/issue32805

@serhiy-storchaka
Copy link
Member

serhiy-storchaka commented Dec 7, 2018

This is bpo-32805.

But changing the signature of PyDTrace_GC_DONE breaks ABI.

@jkloth
Copy link
Contributor Author

jkloth commented Dec 7, 2018

When compiled with dtrace support (on 64-bits) the signature is already a 64-bit long (see pydtrace.d). This change brings the two definitions in sync.

@serhiy-storchaka
Copy link
Member

serhiy-storchaka commented Dec 7, 2018

Should not it be C long as in pydtrace.d?

@serhiy-storchaka serhiy-storchaka changed the title bpo-9566: Fix compiler warnings in gcmodule.c bpo-32805: Fix compiler warnings in gcmodule.c Dec 7, 2018
@jkloth
Copy link
Contributor Author

jkloth commented Dec 7, 2018

Only on 64-bit platforms that have long as 64-bits wide (LP64). Platforms which use LLP64 (Windows) must use a data type that is 64-bits wide. That leaves either Py_ssize_t or Py_intptr_t or an ugly #if/else/endif block around the typedecl.

@vstinner
Copy link
Member

vstinner commented Dec 7, 2018

Do we have DTrace experts around? @ambv maybe?

@jkloth
Copy link
Contributor Author

jkloth commented Dec 7, 2018

For reference (http://dtrace.org/guide/chp-typeopexpr.html#chp-typeopexpr-2), the D programming language uses ILP32 and LP64 data models. This means we need to use a platform-agnostic signed integer type that matches those semantics since the inline functions are also used on LLP64 platforms (Win64).

@jkloth
Copy link
Contributor Author

jkloth commented Dec 11, 2018

This is the last remaining warning when compiling on Windows (64- or 32-bit). It would be great to see it disappear as well. So, to reiterate, the change does nothing to DTrace support proper, but to the dummy functions used when DTrace support is not compiled in. DTrace itself uses empty macros when generating the dummy functions, but since Python is using inline functions the function arguments need to match what is expected of the functions when DTrace is being used.

This means that the DTrace long function argument MUST map to a 32-bit signed integer type on a 32-bit build and MUST map to a 64-bit signed integer type on a 64-bit build. The choices that exist in Python headers are Py_ssize_t or Py_intptr_t (technically, an #ifdef around the function argument would work too, but that gets ugly fast).

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

LGTM.

I agree that Py_ssize_t is the right type here:

static Py_ssize_t
collect(int generation, Py_ssize_t *n_collected, Py_ssize_t *n_uncollectable,
        int nofail)
{
    ...
    Py_ssize_t m = 0; /* # objects collected */
    Py_ssize_t n = 0; /* # unreachable objects that couldn't be collected */
    ...
    if (PyDTrace_GC_DONE_ENABLED())
        PyDTrace_GC_DONE(n+m);
    ...
    return n+m;
}

@ZackerySpytz
Copy link
Contributor

FWIW, this PR is an exact duplicate of the open PR #2852.

@vstinner
Copy link
Member

vstinner commented Mar 6, 2019

Copy of @benjaminp's comment:
"We shouldn't just change the definition here. Either we need to change the type in pydtrace.d or just pass an int into the trace function in gcmodule.c."
#2852 (comment)

According to @jkloth, the current "probe gc__done(long);" is fine.

I don't know DTrace, so I cannot say. I chose to merge the PR because I really care of warnings, and this issue was the last known warning on Windows. This warning prevents me to more easily detect when I make a mistake (introduce a bug) on Windows.

I someone consider that Include/pydtrace.d should be updated to use "probe gc__done(ssize_t);", please go ahead. Sadly, I never used DTrace and I'm not sure if "ssize_t" type is available for DTrace :-(

cc @tiran

vstinner added a commit that referenced this pull request Apr 23, 2019
* bpo-9566: Fix compiler warnings in gcmodule.c (GH-11010)

Change PyDTrace_GC_DONE() argument type from int to Py_ssize_t.

(cherry picked from commit edad38e)

* bpo-30465: Fix C downcast warning on Windows in ast.c (#6593)

ast.c: fstring_fix_node_location() downcasts a pointer difference to
a C int. Replace int with Py_ssize_t to fix the compiler warning.

(cherry picked from commit fb7e799)

* bpo-9566: Fix compiler warnings in peephole.c (GH-10652)

(cherry picked from commit 028f0ef)

* bpo-27645, sqlite: Fix integer overflow on sleep (#6594)

Use the _PyTime_t type and round away from zero (ROUND_UP,
_PyTime_ROUND_TIMEOUT) the sleep duration, when converting a Python
object to seconds and then to milliseconds. Raise an OverflowError in
case of overflow.

Previously the (int)double conversion rounded towards zero
(ROUND_DOWN).

(cherry picked from commit ca40501)
@jkloth jkloth deleted the issue9566-gcmodule branch April 5, 2022 22:28
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.

6 participants