summaryrefslogtreecommitdiffstats
path: root/Include/pyport.h
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2000-07-08 04:17:21 (GMT)
committerTim Peters <tim.peters@gmail.com>2000-07-08 04:17:21 (GMT)
commit7d3a511a40a8c90eac66d3d59edbbe3c3d4559b1 (patch)
treeb2a404e6604682d51adf242e1ac51ac225e6a0bc /Include/pyport.h
parent5639ba4896fa7a4e29f11bf0c42f6e3125785654 (diff)
downloadcpython-7d3a511a40a8c90eac66d3d59edbbe3c3d4559b1.zip
cpython-7d3a511a40a8c90eac66d3d59edbbe3c3d4559b1.tar.gz
cpython-7d3a511a40a8c90eac66d3d59edbbe3c3d4559b1.tar.bz2
Cray J90 fixes for long ints.
This was a convenient excuse to create the pyport.h file recently discussed! Please use new Py_ARITHMETIC_RIGHT_SHIFT when right-shifting a signed int and you *need* sign-extension. This is #define'd in pyport.h, keying off new config symbol SIGNED_RIGHT_SHIFT_ZERO_FILLS. If you're running on a platform that needs that symbol #define'd, the std tests never would have worked for you (in particular, at least test_long would have failed). The autoconfig stuff got added to Python after my Unix days, so I don't know how that works. Would someone please look into doing & testing an auto-config of the SIGNED_RIGHT_SHIFT_ZERO_FILLS symbol? It needs to be defined if & only if, e.g., (-1) >> 3 is not -1.
Diffstat (limited to 'Include/pyport.h')
-rw-r--r--Include/pyport.h57
1 files changed, 57 insertions, 0 deletions
diff --git a/Include/pyport.h b/Include/pyport.h
new file mode 100644
index 0000000..558b17d
--- /dev/null
+++ b/Include/pyport.h
@@ -0,0 +1,57 @@
+/***********************************************************
+Copyright (c) 2000, BeOpen.com.
+All rights reserved.
+
+See the file "Misc/COPYRIGHT" for information on usage and
+redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
+******************************************************************/
+
+#ifndef Py_PYPORT_H
+#define Py_PYPORT_H 1
+
+/**************************************************************************
+Symbols and macros to supply platform-independent interfaces to basic
+C-language operations whose spellings vary across platforms.
+
+Please try to make documentation here as clear as possible: by definition,
+the stuff here is trying to illuminate C's darkest corners.
+
+Config #defines referenced here:
+
+SIGNED_RIGHT_SHIFT_ZERO_FILLS
+Meaning: To be defined iff i>>j does not extend the sign bit when i is a
+ signed integral type and i < 0.
+Used in: Py_ARITHMETIC_RIGHT_SHIFT
+**************************************************************************/
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Py_ARITHMETIC_RIGHT_SHIFT
+ * C doesn't define whether a right-shift of a signed integer sign-extends
+ * or zero-fills. Here a macro to force sign extension:
+ * Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J)
+ * Return I >> J, forcing sign extension.
+ * Requirements:
+ * I is of basic signed type TYPE (char, short, int, long, or long long).
+ * TYPE is one of char, short, int, long, or long long, although long long
+ * must not be used except on platforms that support it.
+ * J is an integer >= 0 and strictly less than the number of bits in TYPE
+ * (because C doesn't define what happens for J outside that range either).
+ * Caution:
+ * I may be evaluated more than once.
+ */
+#ifdef SIGNED_RIGHT_SHIFT_ZERO_FILLS
+#define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) \
+ ((I) < 0 ? ~((~(unsigned TYPE)(I)) >> (J)) : (I) >> (J))
+#else
+#define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) ((I) >> (J))
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* Py_PYPORT_H */