blob: f4daebc6c5b0a7625059e3ad3ee9fadc22294b33 [file] [log] [blame]
Tim Peters7d3a5112000-07-08 04:17:21 +00001/***********************************************************
2Copyright (c) 2000, BeOpen.com.
3All rights reserved.
4
5See the file "Misc/COPYRIGHT" for information on usage and
6redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
7******************************************************************/
8
9#ifndef Py_PYPORT_H
Vladimir Marangozov14a4d882000-07-10 04:59:49 +000010#define Py_PYPORT_H
Tim Peters7d3a5112000-07-08 04:17:21 +000011
12/**************************************************************************
13Symbols and macros to supply platform-independent interfaces to basic
Tim Peters1be46842000-07-23 18:10:18 +000014C language & library operations whose spellings vary across platforms.
Tim Peters7d3a5112000-07-08 04:17:21 +000015
16Please try to make documentation here as clear as possible: by definition,
17the stuff here is trying to illuminate C's darkest corners.
18
19Config #defines referenced here:
20
21SIGNED_RIGHT_SHIFT_ZERO_FILLS
22Meaning: To be defined iff i>>j does not extend the sign bit when i is a
23 signed integral type and i < 0.
24Used in: Py_ARITHMETIC_RIGHT_SHIFT
Tim Peters1be46842000-07-23 18:10:18 +000025
Tim Peters8315ea52000-07-23 19:28:35 +000026Py_DEBUG
27Meaning: Extra checks compiled in for debug mode.
28Used in: Py_SAFE_DOWNCAST
Tim Peters7d3a5112000-07-08 04:17:21 +000029**************************************************************************/
30
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
36/* Py_ARITHMETIC_RIGHT_SHIFT
37 * C doesn't define whether a right-shift of a signed integer sign-extends
38 * or zero-fills. Here a macro to force sign extension:
39 * Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J)
40 * Return I >> J, forcing sign extension.
41 * Requirements:
42 * I is of basic signed type TYPE (char, short, int, long, or long long).
43 * TYPE is one of char, short, int, long, or long long, although long long
44 * must not be used except on platforms that support it.
45 * J is an integer >= 0 and strictly less than the number of bits in TYPE
46 * (because C doesn't define what happens for J outside that range either).
47 * Caution:
48 * I may be evaluated more than once.
49 */
50#ifdef SIGNED_RIGHT_SHIFT_ZERO_FILLS
51#define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) \
52 ((I) < 0 ? ~((~(unsigned TYPE)(I)) >> (J)) : (I) >> (J))
53#else
54#define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) ((I) >> (J))
55#endif
56
Tim Peters1be46842000-07-23 18:10:18 +000057/* Py_FORCE_EXPANSION
58 * "Simply" returns its argument. However, macro expansions within the
59 * argument are evaluated. This unfortunate trickery is needed to get
60 * token-pasting to work as desired in some cases.
61 */
62#define Py_FORCE_EXPANSION(X) X
63
Tim Peters8315ea52000-07-23 19:28:35 +000064/* Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW)
65 * Cast VALUE to type NARROW from type WIDE. In Py_DEBUG mode, this
66 * assert-fails if any information is lost.
67 * Caution:
68 * VALUE may be evaluated more than once.
69 */
70#ifdef Py_DEBUG
71#define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) \
72 (assert((WIDE)(NARROW)(VALUE) == (VALUE)), (NARROW)(VALUE))
73#else
74#define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) (NARROW)(VALUE)
75#endif
76
Thomas Wouters1e0c2f42000-07-24 16:06:23 +000077
78
79/**************************************************************************
80Prototypes that are missing from the standard include files on some systems
81(and possibly only some versions of such systems.)
82
83Please be conservative with adding new ones, document them and enclose them
84in platform-specific #ifdefs.
85**************************************************************************/
86
87#ifdef SOLARIS
88/* Unchecked */
89extern int gethostname(char *, int);
90#endif
91
92#ifdef __BEOS__
93/* Unchecked */
94/* It's in the libs, but not the headers... - [cjh] */
95int shutdown( int, int );
96#endif
97
98#ifdef HAVE__GETPTY
99/* Unchecked */
100extern 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>
108extern int openpty(int *, int *, char *, struct termios *, struct winsize *);
109extern 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 */
122extern int getrusage();
123extern int getpagesize();
124
125/* From Python/sysmodule.c and Modules/posixmodule.c */
126extern int fclose(FILE *);
127
128/* From Modules/posixmodule.c */
129extern int fdatasync(int);
130/* XXX These are supposedly for SunOS4.1.3 but "shouldn't hurt elsewhere" */
131extern int rename(const char *, const char *);
132extern int pclose(FILE *);
133extern int lstat(const char *, struct stat *);
134extern int symlink(const char *, const char *);
135extern int fsync(int fd);
136
137#endif /* 0 */
138
Tim Peters7d3a5112000-07-08 04:17:21 +0000139#ifdef __cplusplus
140}
141#endif
142
143#endif /* Py_PYPORT_H */