Skip to content

Commit 1e0c2f4

Browse files
committed
Create a new section of pyport.h to hold all external function declarations
for systems that are missing those declarations from system include files. Start by moving a pointy-haired ones from their previous locations to the new section. (The gethostname() one, for instance, breaks on several systems, because some define it as (char *, size_t) and some as (char *, int).) I purposely decided not to include the summary of used #defines like Tim did in the first section of pyport.h. In my opinion, the number of #defines likedly to be used by this section would make such an overview unwieldy. I would suggest documenting the non-obvious ones, though.
1 parent 332c59c commit 1e0c2f4

File tree

5 files changed

+66
-36
lines changed

5 files changed

+66
-36
lines changed

Include/pyport.h

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,68 @@ extern "C" {
7474
#define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) (NARROW)(VALUE)
7575
#endif
7676

77+
78+
79+
/**************************************************************************
80+
Prototypes that are missing from the standard include files on some systems
81+
(and possibly only some versions of such systems.)
82+
83+
Please be conservative with adding new ones, document them and enclose them
84+
in platform-specific #ifdefs.
85+
**************************************************************************/
86+
87+
#ifdef SOLARIS
88+
/* Unchecked */
89+
extern int gethostname(char *, int);
90+
#endif
91+
92+
#ifdef __BEOS__
93+
/* Unchecked */
94+
/* It's in the libs, but not the headers... - [cjh] */
95+
int shutdown( int, int );
96+
#endif
97+
98+
#ifdef HAVE__GETPTY
99+
/* Unchecked */
100+
extern char * _getpty(int *, int, mode_t, int);
101+
#endif
102+
103+
#if defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY)
104+
#if !defined(HAVE_PTY_H) && !defined(HAVE_LIBUTIL_H)
105+
/* BSDI does not supply a prototype for the 'openpty' and 'forkpty'
106+
functions, even though they are included in libutil. */
107+
#include <termios.h>
108+
extern int openpty(int *, int *, char *, struct termios *, struct winsize *);
109+
extern int forkpty(int *, char *, struct termios *, struct winsize *);
110+
#endif /* !defined(HAVE_PTY_H) && !defined(HAVE_LIBUTIL_H) */
111+
#endif /* defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) */
112+
113+
114+
/* These are pulled from various places. It isn't obvious on what platforms
115+
they are necessary, nor what the exact prototype should look like (which
116+
is likely to vary between platforms!) If you find you need one of these
117+
declarations, please move them to a platform-specific block and include
118+
proper prototypes. */
119+
#if 0
120+
121+
/* From Modules/resource.c */
122+
extern int getrusage();
123+
extern int getpagesize();
124+
125+
/* From Python/sysmodule.c and Modules/posixmodule.c */
126+
extern int fclose(FILE *);
127+
128+
/* From Modules/posixmodule.c */
129+
extern int fdatasync(int);
130+
/* XXX These are supposedly for SunOS4.1.3 but "shouldn't hurt elsewhere" */
131+
extern int rename(const char *, const char *);
132+
extern int pclose(FILE *);
133+
extern int lstat(const char *, struct stat *);
134+
extern int symlink(const char *, const char *);
135+
extern int fsync(int fd);
136+
137+
#endif /* 0 */
138+
77139
#ifdef __cplusplus
78140
}
79141
#endif

Modules/posixmodule.c

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,7 @@ corresponding Unix manual entries for more information on calls.";
128128
#define UNION_WAIT /* This should really be checked for by autoconf */
129129
#endif
130130

131-
#ifdef HAVE_UNISTD_H
132-
/* XXX These are for SunOS4.1.3 but shouldn't hurt elsewhere */
133-
extern int rename(const char *, const char *);
134-
extern int pclose(FILE *);
135-
extern int lstat(const char *, struct stat *);
136-
extern int symlink(const char *, const char *);
137-
extern int fsync(int fd);
138-
#else /* !HAVE_UNISTD_H */
131+
#ifndef HAVE_UNISTD_H
139132
#if defined(PYCC_VACPP)
140133
extern int mkdir(char *);
141134
#else
@@ -721,8 +714,6 @@ static char posix_fdatasync__doc__[] =
721714
force write of file with filedescriptor to disk.\n\
722715
does not force update of metadata.";
723716

724-
extern int fdatasync(int); /* Prototype just in case */
725-
726717
static PyObject *
727718
posix_fdatasync(PyObject *self, PyObject *args)
728719
{
@@ -1680,12 +1671,6 @@ posix_fork(PyObject *self, PyObject *args)
16801671
#else
16811672
#ifdef HAVE_LIBUTIL_H
16821673
#include <libutil.h>
1683-
#else
1684-
/* BSDI does not supply a prototype for the 'openpty' and 'forkpty'
1685-
functions, even though they are included in libutil. */
1686-
#include <termios.h>
1687-
extern int openpty(int *, int *, char *, struct termios *, struct winsize *);
1688-
extern int forkpty(int *, char *, struct termios *, struct winsize *);
16891674
#endif /* HAVE_LIBUTIL_H */
16901675
#endif /* HAVE_PTY_H */
16911676
#endif /* defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) */
@@ -1701,8 +1686,6 @@ posix_openpty(PyObject *self, PyObject *args)
17011686
int master_fd, slave_fd;
17021687
#ifndef HAVE_OPENPTY
17031688
char * slave_name;
1704-
/* SGI apparently needs this forward declaration */
1705-
extern char * _getpty(int *, int, mode_t, int);
17061689
#endif
17071690

17081691
if (!PyArg_ParseTuple(args, ":openpty"))
@@ -1719,7 +1702,7 @@ posix_openpty(PyObject *self, PyObject *args)
17191702
slave_fd = open(slave_name, O_RDWR);
17201703
if (slave_fd < 0)
17211704
return posix_error();
1722-
#endif /* defined(HAVE_OPENPTY) */
1705+
#endif /* HAVE_OPENPTY */
17231706

17241707
return Py_BuildValue("(ii)", master_fd, slave_fd);
17251708

@@ -3286,7 +3269,6 @@ Return an open file object connected to a file descriptor.";
32863269
static PyObject *
32873270
posix_fdopen(PyObject *self, PyObject *args)
32883271
{
3289-
extern int fclose(FILE *);
32903272
int fd;
32913273
char *mode = "r";
32923274
int bufsize = -1;

Modules/resource.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
2222
but we can't declare the prototype, to avoid errors
2323
when the header files declare it different.
2424
Worse, on some Linuxes, getpagesize() returns a size_t... */
25-
#ifndef linux
26-
int getrusage();
27-
int getpagesize();
28-
#endif
2925

3026
#define doubletime(TV) ((double)(TV).tv_sec + (TV).tv_usec * 0.000001)
3127

Modules/socketmodule.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,6 @@ Socket methods:
110110
#include <unistd.h>
111111
#endif
112112

113-
#if !defined(MS_WINDOWS) && !defined(PYOS_OS2) && !defined(__BEOS__)
114-
extern int gethostname(char *, size_t); /* For Solaris, at least */
115-
#endif
116-
117113
#if defined(PYCC_VACPP)
118114
#include <types.h>
119115
#include <io.h>
@@ -129,11 +125,6 @@ extern int gethostname(char *, size_t); /* For Solaris, at least */
129125
#include <os2.h>
130126
#endif
131127

132-
#if defined(__BEOS__)
133-
/* It's in the libs, but not the headers... - [cjh] */
134-
int shutdown( int, int );
135-
#endif
136-
137128
#include <sys/types.h>
138129
#include "mytime.h"
139130

@@ -2407,9 +2398,9 @@ shutdown() -- shut down traffic in one or both directions\n\
24072398

24082399
DL_EXPORT(void)
24092400
#if defined(MS_WINDOWS) || defined(PYOS_OS2) || defined(__BEOS__)
2410-
init_socket()
2401+
init_socket(void)
24112402
#else
2412-
initsocket()
2403+
initsocket(void)
24132404
#endif
24142405
{
24152406
PyObject *m, *d;

Python/sysmodule.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,6 @@ settrace() -- set the global debug tracing function\n\
385385
PyObject *
386386
_PySys_Init(void)
387387
{
388-
extern int fclose(FILE *);
389388
PyObject *m, *v, *sysdict;
390389
PyObject *sysin, *sysout, *syserr;
391390
char *s;

0 commit comments

Comments
 (0)