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

Compile error with pytime.h - struct timespec declared inside parameter list #70040

Closed
jamespharvey20 mannequin opened this issue Dec 12, 2015 · 8 comments
Closed

Compile error with pytime.h - struct timespec declared inside parameter list #70040

jamespharvey20 mannequin opened this issue Dec 12, 2015 · 8 comments
Labels
build The build process and cross-build

Comments

@jamespharvey20
Copy link
Mannequin

jamespharvey20 mannequin commented Dec 12, 2015

BPO 25853
Nosy @vadmium, @iritkatriel

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2021-09-12.11:25:56.312>
created_at = <Date 2015-12-12.23:09:50.175>
labels = ['build']
title = 'Compile error with pytime.h - struct timespec declared inside parameter list'
updated_at = <Date 2021-09-12.11:25:56.310>
user = 'https://bugs.python.org/jamespharvey20'

bugs.python.org fields:

activity = <Date 2021-09-12.11:25:56.310>
actor = 'iritkatriel'
assignee = 'none'
closed = True
closed_date = <Date 2021-09-12.11:25:56.312>
closer = 'iritkatriel'
components = ['Build']
creation = <Date 2015-12-12.23:09:50.175>
creator = 'jamespharvey20'
dependencies = []
files = []
hgrepos = []
issue_num = 25853
keywords = []
message_count = 4.0
messages = ['256301', '256303', '256378', '401662']
nosy_count = 3.0
nosy_names = ['martin.panter', 'jamespharvey20', 'iritkatriel']
pr_nums = []
priority = 'normal'
resolution = 'works for me'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'compile error'
url = 'https://bugs.python.org/issue25853'
versions = ['Python 3.5']

@jamespharvey20
Copy link
Mannequin Author

jamespharvey20 mannequin commented Dec 12, 2015

When including pytime.h:

n file included from /usr/include/python3.5m/Python.h:65:0,
                 from src/package.c:25:
/usr/include/python3.5m/pytime.h:136:56: error: ‘struct timespecdeclared inside parameter list [-Werror]
 PyAPI_FUNC(int) _PyTime_AsTimespec(_PyTime_t t, struct timespec *ts);
                                                        ^
/usr/include/python3.5m/pytime.h:136:56: error: its scope is only this definition or declaration, which is probably not what you want [-Werror]
cc1: all warnings being treated as errors
error: command 'gcc' failed with exit status 1

@jamespharvey20 jamespharvey20 mannequin added stdlib Python modules in the Lib dir build The build process and cross-build labels Dec 12, 2015
@jamespharvey20
Copy link
Mannequin Author

jamespharvey20 mannequin commented Dec 12, 2015

This is using https://www.python.org/ftp/python/3.5.1/Python-3.5.1.tar.xz

GCC v5.3.0

Using Werror obviously

@vadmium
Copy link
Member

vadmium commented Dec 14, 2015

What platform, C library, etc do you have? According to Posix, struct timespec is normally defined in <time.h>, but can also be gotten via various other include files, many of which are included before "pytime.h".

In particular, <Python.h> includes "pyport.h", which has conditional code for including <time.h>, <sys/select.h> and <sys/stat.h>. All of these should define timespec. It might be useful to check your pyconfig.h file to see if stuff like the following is defined:

/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
#define TIME_WITH_SYS_TIME 1

@vadmium vadmium added build The build process and cross-build and removed stdlib Python modules in the Lib dir labels Dec 14, 2015
@iritkatriel
Copy link
Member

Closing as there isn't enough information here for us to do anything about it and there has been no response from the OP to follow-up questions.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
@alexshpilkin
Copy link

alexshpilkin commented Sep 2, 2023

This warning seems a bit temperamental as to when it will show up, but I think I have a reproducer: a test.c containing

#include <stdint.h>

#define PY_SSIZE_T_CLEAN
#include <Python.h>

static struct PyModuleDef module = {
    PyModuleDef_HEAD_INIT, "test", NULL, -1
};

PyMODINIT_FUNC
PyInit_test(void)
{
    return PyModule_Create(&module);
}

will produce the warning when compiled with gcc -std=c99 -O2 -c test.c, but will not produce one if -std=c99 is replaced with std=gnu99. And this makes sense: the ISO-described version of <time.h> does not define struct timespec until C11, and Glibc is usually careful about gating such things on __STDC_VERSION__ when __STRICT_ANSI__ is in effect.

Inserting struct timespec; before #include <Python.h> makes the warning disappear, although I’m not sure if this is legal per the ISO standard (I can see no reason why it shouldn’t be, but C99 7.1.4p2 only specifically authorizes user declarations of library functions).

Linux (NixOS), Python 3.10, GCC 12.3.0.

@iritkatriel Are you willing to reopen?

@erlend-aasland
Copy link
Contributor

@alexshpilkin, since Python require C11, this should not be a problem, IIUYC.

https://peps.python.org/pep-0007/#c-dialect

@alexshpilkin
Copy link

@erlend-aasland Ah, didn’t know that 3.11 is C11-only, thanks! Or that even 3.10 is essentially on life support. It leaves a bit of a bad taste that this (admittedly very minor) bug got waited out in this manner, but at this point yes, I agree it’s an ex-bug.

@erlend-aasland
Copy link
Contributor

@erlend-aasland Ah, didn’t know that 3.11 is C11-only, thanks! Or that even 3.10 is essentially on life support. It leaves a bit of a bad taste that this (admittedly very minor) bug got waited out in this manner, but at this point yes, I agree it’s an ex-bug.

I'll quote Irit's response on why this was closed:

Closing as there isn't enough information here for us to do anything about it and there has been no response from the OP to follow-up questions.

The OP did not include a reproducer; even basic things like platform, architecture, etc. was missing. Martin responded the day after the bug report was registered, but the reporter never responded back.

I'm not sure how to interpret your post ("bad taste", "waited out").

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build The build process and cross-build
Projects
None yet
Development

No branches or pull requests

4 participants