mercurial/util.h
author Adrian Buehlmann <adrian@cadifra.com>
Wed, 13 May 2015 18:57:38 +0200
changeset 25026 80d28a88137f
parent 24829 8e9f8d2a2c0c
child 25076 14bf7679fb68
permissions -rw-r--r--
util.h: kill no longer needed definitions for Python < 2.5 see e1fb276d4619
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11358
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
     1
/*
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
     2
 util.h - utility functions for interfacing with the various python APIs.
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
     3
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
     4
 This software may be used and distributed according to the terms of
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
     5
 the GNU General Public License, incorporated herein by reference.
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
     6
*/
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
     7
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
     8
#ifndef _HG_UTIL_H_
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
     9
#define _HG_UTIL_H_
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    10
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    11
#if PY_MAJOR_VERSION >= 3
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    12
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    13
#define IS_PY3K
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    14
#define PyInt_FromLong PyLong_FromLong
11534
9777a3b19efe util.h: Add a PyInt_AsLong definition for usage in the inotify module.
Renato Cunha <renatoc@gmail.com>
parents: 11358
diff changeset
    15
#define PyInt_AsLong PyLong_AsLong
11358
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    16
11535
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    17
/*
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    18
 Mapping of some of the python < 2.x PyString* functions to py3k's PyUnicode.
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    19
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    20
 The commented names below represent those that are present in the PyBytes
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    21
 definitions for python < 2.6 (below in this file) that don't have a direct
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    22
 implementation.
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    23
*/
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    24
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    25
#define PyStringObject PyUnicodeObject
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    26
#define PyString_Type PyUnicode_Type
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    27
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    28
#define PyString_Check PyUnicode_Check
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    29
#define PyString_CheckExact PyUnicode_CheckExact
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    30
#define PyString_CHECK_INTERNED PyUnicode_CHECK_INTERNED
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    31
#define PyString_AS_STRING PyUnicode_AsLatin1String
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    32
#define PyString_GET_SIZE PyUnicode_GET_SIZE
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    33
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    34
#define PyString_FromStringAndSize PyUnicode_FromStringAndSize
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    35
#define PyString_FromString PyUnicode_FromString
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    36
#define PyString_FromFormatV PyUnicode_FromFormatV
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    37
#define PyString_FromFormat PyUnicode_FromFormat
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    38
/* #define PyString_Size PyUnicode_GET_SIZE */
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    39
/* #define PyString_AsString */
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    40
/* #define PyString_Repr */
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    41
#define PyString_Concat PyUnicode_Concat
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    42
#define PyString_ConcatAndDel PyUnicode_AppendAndDel
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    43
#define _PyString_Resize PyUnicode_Resize
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    44
/* #define _PyString_Eq */
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    45
#define PyString_Format PyUnicode_Format
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    46
/* #define _PyString_FormatLong */
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    47
/* #define PyString_DecodeEscape */
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    48
#define _PyString_Join PyUnicode_Join
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    49
#define PyString_Decode PyUnicode_Decode
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    50
#define PyString_Encode PyUnicode_Encode
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    51
#define PyString_AsEncodedObject PyUnicode_AsEncodedObject
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    52
#define PyString_AsEncodedString PyUnicode_AsEncodedString
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    53
#define PyString_AsDecodedObject PyUnicode_AsDecodedObject
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    54
#define PyString_AsDecodedString PyUnicode_AsDecodedUnicode
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    55
/* #define PyString_AsStringAndSize */
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    56
#define _PyString_InsertThousandsGrouping _PyUnicode_InsertThousandsGrouping
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    57
11358
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    58
#endif /* PY_MAJOR_VERSION */
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    59
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    60
/* Backports from 2.6 */
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    61
#if PY_VERSION_HEX < 0x02060000
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    62
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    63
#define Py_TYPE(ob) (ob)->ob_type
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    64
#define Py_SIZE(ob) (ob)->ob_size
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    65
#define PyVarObject_HEAD_INIT(type, size) PyObject_HEAD_INIT(type) size,
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    66
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    67
/* Shamelessly stolen from bytesobject.h */
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    68
#define PyBytesObject PyStringObject
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    69
#define PyBytes_Type PyString_Type
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    70
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    71
#define PyBytes_Check PyString_Check
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    72
#define PyBytes_CheckExact PyString_CheckExact
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    73
#define PyBytes_CHECK_INTERNED PyString_CHECK_INTERNED
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    74
#define PyBytes_AS_STRING PyString_AS_STRING
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    75
#define PyBytes_GET_SIZE PyString_GET_SIZE
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    76
#define Py_TPFLAGS_BYTES_SUBCLASS Py_TPFLAGS_STRING_SUBCLASS
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    77
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    78
#define PyBytes_FromStringAndSize PyString_FromStringAndSize
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    79
#define PyBytes_FromString PyString_FromString
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    80
#define PyBytes_FromFormatV PyString_FromFormatV
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    81
#define PyBytes_FromFormat PyString_FromFormat
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    82
#define PyBytes_Size PyString_Size
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    83
#define PyBytes_AsString PyString_AsString
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    84
#define PyBytes_Repr PyString_Repr
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    85
#define PyBytes_Concat PyString_Concat
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    86
#define PyBytes_ConcatAndDel PyString_ConcatAndDel
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    87
#define _PyBytes_Resize _PyString_Resize
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    88
#define _PyBytes_Eq _PyString_Eq
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    89
#define PyBytes_Format PyString_Format
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    90
#define _PyBytes_FormatLong _PyString_FormatLong
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    91
#define PyBytes_DecodeEscape PyString_DecodeEscape
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    92
#define _PyBytes_Join _PyString_Join
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    93
#define PyBytes_Decode PyString_Decode
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    94
#define PyBytes_Encode PyString_Encode
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    95
#define PyBytes_AsEncodedObject PyString_AsEncodedObject
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    96
#define PyBytes_AsEncodedString PyString_AsEncodedString
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    97
#define PyBytes_AsDecodedObject PyString_AsDecodedObject
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    98
#define PyBytes_AsDecodedString PyString_AsDecodedString
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    99
#define PyBytes_AsStringAndSize PyString_AsStringAndSize
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
   100
#define _PyBytes_InsertThousandsGrouping _PyString_InsertThousandsGrouping
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
   101
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
   102
#endif /* PY_VERSION_HEX */
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
   103
16385
e501f45b0eba util.h: unify some common platform tweaks
Matt Mackall <mpm@selenic.com>
parents: 16384
diff changeset
   104
#ifdef _WIN32
e501f45b0eba util.h: unify some common platform tweaks
Matt Mackall <mpm@selenic.com>
parents: 16384
diff changeset
   105
#ifdef _MSC_VER
e501f45b0eba util.h: unify some common platform tweaks
Matt Mackall <mpm@selenic.com>
parents: 16384
diff changeset
   106
/* msvc 6.0 has problems */
e501f45b0eba util.h: unify some common platform tweaks
Matt Mackall <mpm@selenic.com>
parents: 16384
diff changeset
   107
#define inline __inline
19723
7999f4fa155a util.h: add stdint basic type definitions
Wei, Elson <elson.wei@gmail.com>
parents: 17616
diff changeset
   108
typedef signed char int8_t;
7999f4fa155a util.h: add stdint basic type definitions
Wei, Elson <elson.wei@gmail.com>
parents: 17616
diff changeset
   109
typedef short int16_t;
7999f4fa155a util.h: add stdint basic type definitions
Wei, Elson <elson.wei@gmail.com>
parents: 17616
diff changeset
   110
typedef long int32_t;
7999f4fa155a util.h: add stdint basic type definitions
Wei, Elson <elson.wei@gmail.com>
parents: 17616
diff changeset
   111
typedef __int64 int64_t;
17616
9535a0dc41f2 store: implement fncache basic path encoding in C
Bryan O'Sullivan <bryano@fb.com>
parents: 16629
diff changeset
   112
typedef unsigned char uint8_t;
19723
7999f4fa155a util.h: add stdint basic type definitions
Wei, Elson <elson.wei@gmail.com>
parents: 17616
diff changeset
   113
typedef unsigned short uint16_t;
16385
e501f45b0eba util.h: unify some common platform tweaks
Matt Mackall <mpm@selenic.com>
parents: 16384
diff changeset
   114
typedef unsigned long uint32_t;
e501f45b0eba util.h: unify some common platform tweaks
Matt Mackall <mpm@selenic.com>
parents: 16384
diff changeset
   115
typedef unsigned __int64 uint64_t;
e501f45b0eba util.h: unify some common platform tweaks
Matt Mackall <mpm@selenic.com>
parents: 16384
diff changeset
   116
#else
e501f45b0eba util.h: unify some common platform tweaks
Matt Mackall <mpm@selenic.com>
parents: 16384
diff changeset
   117
#include <stdint.h>
e501f45b0eba util.h: unify some common platform tweaks
Matt Mackall <mpm@selenic.com>
parents: 16384
diff changeset
   118
#endif
e501f45b0eba util.h: unify some common platform tweaks
Matt Mackall <mpm@selenic.com>
parents: 16384
diff changeset
   119
#else
e501f45b0eba util.h: unify some common platform tweaks
Matt Mackall <mpm@selenic.com>
parents: 16384
diff changeset
   120
/* not windows */
e501f45b0eba util.h: unify some common platform tweaks
Matt Mackall <mpm@selenic.com>
parents: 16384
diff changeset
   121
#include <sys/types.h>
e501f45b0eba util.h: unify some common platform tweaks
Matt Mackall <mpm@selenic.com>
parents: 16384
diff changeset
   122
#if defined __BEOS__ && !defined __HAIKU__
e501f45b0eba util.h: unify some common platform tweaks
Matt Mackall <mpm@selenic.com>
parents: 16384
diff changeset
   123
#include <ByteOrder.h>
e501f45b0eba util.h: unify some common platform tweaks
Matt Mackall <mpm@selenic.com>
parents: 16384
diff changeset
   124
#else
e501f45b0eba util.h: unify some common platform tweaks
Matt Mackall <mpm@selenic.com>
parents: 16384
diff changeset
   125
#include <arpa/inet.h>
e501f45b0eba util.h: unify some common platform tweaks
Matt Mackall <mpm@selenic.com>
parents: 16384
diff changeset
   126
#endif
e501f45b0eba util.h: unify some common platform tweaks
Matt Mackall <mpm@selenic.com>
parents: 16384
diff changeset
   127
#include <inttypes.h>
e501f45b0eba util.h: unify some common platform tweaks
Matt Mackall <mpm@selenic.com>
parents: 16384
diff changeset
   128
#endif
e501f45b0eba util.h: unify some common platform tweaks
Matt Mackall <mpm@selenic.com>
parents: 16384
diff changeset
   129
e501f45b0eba util.h: unify some common platform tweaks
Matt Mackall <mpm@selenic.com>
parents: 16384
diff changeset
   130
#if defined __hpux || defined __SUNPRO_C || defined _AIX
e501f45b0eba util.h: unify some common platform tweaks
Matt Mackall <mpm@selenic.com>
parents: 16384
diff changeset
   131
#define inline
e501f45b0eba util.h: unify some common platform tweaks
Matt Mackall <mpm@selenic.com>
parents: 16384
diff changeset
   132
#endif
e501f45b0eba util.h: unify some common platform tweaks
Matt Mackall <mpm@selenic.com>
parents: 16384
diff changeset
   133
e501f45b0eba util.h: unify some common platform tweaks
Matt Mackall <mpm@selenic.com>
parents: 16384
diff changeset
   134
#ifdef __linux
e501f45b0eba util.h: unify some common platform tweaks
Matt Mackall <mpm@selenic.com>
parents: 16384
diff changeset
   135
#define inline __inline
e501f45b0eba util.h: unify some common platform tweaks
Matt Mackall <mpm@selenic.com>
parents: 16384
diff changeset
   136
#endif
e501f45b0eba util.h: unify some common platform tweaks
Matt Mackall <mpm@selenic.com>
parents: 16384
diff changeset
   137
21809
e250b8300e6e parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents: 19833
diff changeset
   138
typedef struct {
e250b8300e6e parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents: 19833
diff changeset
   139
	PyObject_HEAD
e250b8300e6e parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents: 19833
diff changeset
   140
	char state;
e250b8300e6e parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents: 19833
diff changeset
   141
	int mode;
e250b8300e6e parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents: 19833
diff changeset
   142
	int size;
e250b8300e6e parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents: 19833
diff changeset
   143
	int mtime;
e250b8300e6e parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents: 19833
diff changeset
   144
} dirstateTupleObject;
e250b8300e6e parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents: 19833
diff changeset
   145
21838
0022ee690446 util.h: declare dirstateTupleType variable instead of defining it
André Sintzoff <andre.sintzoff@gmail.com>
parents: 21809
diff changeset
   146
extern PyTypeObject dirstateTupleType;
21809
e250b8300e6e parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents: 19833
diff changeset
   147
#define dirstate_tuple_check(op) (Py_TYPE(op) == &dirstateTupleType)
e250b8300e6e parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents: 19833
diff changeset
   148
16437
d126a0d16856 util.h: replace ntohl/htonl with get/putbe32
Matt Mackall <mpm@selenic.com>
parents: 16393
diff changeset
   149
static inline uint32_t getbe32(const char *c)
d126a0d16856 util.h: replace ntohl/htonl with get/putbe32
Matt Mackall <mpm@selenic.com>
parents: 16393
diff changeset
   150
{
d126a0d16856 util.h: replace ntohl/htonl with get/putbe32
Matt Mackall <mpm@selenic.com>
parents: 16393
diff changeset
   151
	const unsigned char *d = (const unsigned char *)c;
d126a0d16856 util.h: replace ntohl/htonl with get/putbe32
Matt Mackall <mpm@selenic.com>
parents: 16393
diff changeset
   152
d126a0d16856 util.h: replace ntohl/htonl with get/putbe32
Matt Mackall <mpm@selenic.com>
parents: 16393
diff changeset
   153
	return ((d[0] << 24) |
d126a0d16856 util.h: replace ntohl/htonl with get/putbe32
Matt Mackall <mpm@selenic.com>
parents: 16393
diff changeset
   154
		(d[1] << 16) |
d126a0d16856 util.h: replace ntohl/htonl with get/putbe32
Matt Mackall <mpm@selenic.com>
parents: 16393
diff changeset
   155
		(d[2] << 8) |
d126a0d16856 util.h: replace ntohl/htonl with get/putbe32
Matt Mackall <mpm@selenic.com>
parents: 16393
diff changeset
   156
		(d[3]));
d126a0d16856 util.h: replace ntohl/htonl with get/putbe32
Matt Mackall <mpm@selenic.com>
parents: 16393
diff changeset
   157
}
d126a0d16856 util.h: replace ntohl/htonl with get/putbe32
Matt Mackall <mpm@selenic.com>
parents: 16393
diff changeset
   158
24015
e2bf959a5a0d util: add getbe{u,}int16 utility methods
Augie Fackler <augie@google.com>
parents: 21838
diff changeset
   159
static inline int16_t getbeint16(const char *c)
e2bf959a5a0d util: add getbe{u,}int16 utility methods
Augie Fackler <augie@google.com>
parents: 21838
diff changeset
   160
{
e2bf959a5a0d util: add getbe{u,}int16 utility methods
Augie Fackler <augie@google.com>
parents: 21838
diff changeset
   161
	const unsigned char *d = (const unsigned char *)c;
e2bf959a5a0d util: add getbe{u,}int16 utility methods
Augie Fackler <augie@google.com>
parents: 21838
diff changeset
   162
e2bf959a5a0d util: add getbe{u,}int16 utility methods
Augie Fackler <augie@google.com>
parents: 21838
diff changeset
   163
	return ((d[0] << 8) |
e2bf959a5a0d util: add getbe{u,}int16 utility methods
Augie Fackler <augie@google.com>
parents: 21838
diff changeset
   164
		(d[1]));
e2bf959a5a0d util: add getbe{u,}int16 utility methods
Augie Fackler <augie@google.com>
parents: 21838
diff changeset
   165
}
e2bf959a5a0d util: add getbe{u,}int16 utility methods
Augie Fackler <augie@google.com>
parents: 21838
diff changeset
   166
e2bf959a5a0d util: add getbe{u,}int16 utility methods
Augie Fackler <augie@google.com>
parents: 21838
diff changeset
   167
static inline uint16_t getbeuint16(const char *c)
e2bf959a5a0d util: add getbe{u,}int16 utility methods
Augie Fackler <augie@google.com>
parents: 21838
diff changeset
   168
{
e2bf959a5a0d util: add getbe{u,}int16 utility methods
Augie Fackler <augie@google.com>
parents: 21838
diff changeset
   169
	const unsigned char *d = (const unsigned char *)c;
e2bf959a5a0d util: add getbe{u,}int16 utility methods
Augie Fackler <augie@google.com>
parents: 21838
diff changeset
   170
e2bf959a5a0d util: add getbe{u,}int16 utility methods
Augie Fackler <augie@google.com>
parents: 21838
diff changeset
   171
	return ((d[0] << 8) |
e2bf959a5a0d util: add getbe{u,}int16 utility methods
Augie Fackler <augie@google.com>
parents: 21838
diff changeset
   172
		(d[1]));
e2bf959a5a0d util: add getbe{u,}int16 utility methods
Augie Fackler <augie@google.com>
parents: 21838
diff changeset
   173
}
e2bf959a5a0d util: add getbe{u,}int16 utility methods
Augie Fackler <augie@google.com>
parents: 21838
diff changeset
   174
16437
d126a0d16856 util.h: replace ntohl/htonl with get/putbe32
Matt Mackall <mpm@selenic.com>
parents: 16393
diff changeset
   175
static inline void putbe32(uint32_t x, char *c)
d126a0d16856 util.h: replace ntohl/htonl with get/putbe32
Matt Mackall <mpm@selenic.com>
parents: 16393
diff changeset
   176
{
d126a0d16856 util.h: replace ntohl/htonl with get/putbe32
Matt Mackall <mpm@selenic.com>
parents: 16393
diff changeset
   177
	c[0] = (x >> 24) & 0xff;
d126a0d16856 util.h: replace ntohl/htonl with get/putbe32
Matt Mackall <mpm@selenic.com>
parents: 16393
diff changeset
   178
	c[1] = (x >> 16) & 0xff;
d126a0d16856 util.h: replace ntohl/htonl with get/putbe32
Matt Mackall <mpm@selenic.com>
parents: 16393
diff changeset
   179
	c[2] = (x >> 8) & 0xff;
d126a0d16856 util.h: replace ntohl/htonl with get/putbe32
Matt Mackall <mpm@selenic.com>
parents: 16393
diff changeset
   180
	c[3] = (x) & 0xff;
d126a0d16856 util.h: replace ntohl/htonl with get/putbe32
Matt Mackall <mpm@selenic.com>
parents: 16393
diff changeset
   181
}
d126a0d16856 util.h: replace ntohl/htonl with get/putbe32
Matt Mackall <mpm@selenic.com>
parents: 16393
diff changeset
   182
24016
fb93721cc229 util: add getbefloat64
Augie Fackler <augie@google.com>
parents: 24015
diff changeset
   183
static inline double getbefloat64(const char *c)
fb93721cc229 util: add getbefloat64
Augie Fackler <augie@google.com>
parents: 24015
diff changeset
   184
{
fb93721cc229 util: add getbefloat64
Augie Fackler <augie@google.com>
parents: 24015
diff changeset
   185
	const unsigned char *d = (const unsigned char *)c;
fb93721cc229 util: add getbefloat64
Augie Fackler <augie@google.com>
parents: 24015
diff changeset
   186
	double ret;
fb93721cc229 util: add getbefloat64
Augie Fackler <augie@google.com>
parents: 24015
diff changeset
   187
	int i;
fb93721cc229 util: add getbefloat64
Augie Fackler <augie@google.com>
parents: 24015
diff changeset
   188
	uint64_t t = 0;
fb93721cc229 util: add getbefloat64
Augie Fackler <augie@google.com>
parents: 24015
diff changeset
   189
	for (i = 0; i < 8; i++) {
fb93721cc229 util: add getbefloat64
Augie Fackler <augie@google.com>
parents: 24015
diff changeset
   190
		t = (t<<8) + d[i];
fb93721cc229 util: add getbefloat64
Augie Fackler <augie@google.com>
parents: 24015
diff changeset
   191
	}
fb93721cc229 util: add getbefloat64
Augie Fackler <augie@google.com>
parents: 24015
diff changeset
   192
	memcpy(&ret, &t, sizeof(t));
fb93721cc229 util: add getbefloat64
Augie Fackler <augie@google.com>
parents: 24015
diff changeset
   193
	return ret;
fb93721cc229 util: add getbefloat64
Augie Fackler <augie@google.com>
parents: 24015
diff changeset
   194
}
fb93721cc229 util: add getbefloat64
Augie Fackler <augie@google.com>
parents: 24015
diff changeset
   195
24608
1c533e23ce95 util.h: define an enum for normcase specs
Siddharth Agarwal <sid0@fb.com>
parents: 24443
diff changeset
   196
/* This should be kept in sync with normcasespecs in encoding.py. */
1c533e23ce95 util.h: define an enum for normcase specs
Siddharth Agarwal <sid0@fb.com>
parents: 24443
diff changeset
   197
enum normcase_spec {
1c533e23ce95 util.h: define an enum for normcase specs
Siddharth Agarwal <sid0@fb.com>
parents: 24443
diff changeset
   198
	NORMCASE_LOWER = -1,
1c533e23ce95 util.h: define an enum for normcase specs
Siddharth Agarwal <sid0@fb.com>
parents: 24443
diff changeset
   199
	NORMCASE_UPPER = 1,
1c533e23ce95 util.h: define an enum for normcase specs
Siddharth Agarwal <sid0@fb.com>
parents: 24443
diff changeset
   200
	NORMCASE_OTHER = 0
1c533e23ce95 util.h: define an enum for normcase specs
Siddharth Agarwal <sid0@fb.com>
parents: 24443
diff changeset
   201
};
1c533e23ce95 util.h: define an enum for normcase specs
Siddharth Agarwal <sid0@fb.com>
parents: 24443
diff changeset
   202
24443
539b3c7eea44 phase: compute phases in C
Laurent Charignon <lcharignon@fb.com>
parents: 24442
diff changeset
   203
#define MIN(a, b) (((a)<(b))?(a):(b))
24442
98042b0e19f9 manifest: move C bool polyfill into util.h
Matt Mackall <mpm@selenic.com>
parents: 24016
diff changeset
   204
/* VC9 doesn't include bool and lacks stdbool.h based on my searching */
24829
8e9f8d2a2c0c util: fix the check for non-C99 compilers (issue4605)
Kevin Bullock <kbullock@ringworld.org>
parents: 24823
diff changeset
   205
#if defined(_MSC_VER) || __STDC_VERSION__ < 199901L
24442
98042b0e19f9 manifest: move C bool polyfill into util.h
Matt Mackall <mpm@selenic.com>
parents: 24016
diff changeset
   206
#define true 1
98042b0e19f9 manifest: move C bool polyfill into util.h
Matt Mackall <mpm@selenic.com>
parents: 24016
diff changeset
   207
#define false 0
98042b0e19f9 manifest: move C bool polyfill into util.h
Matt Mackall <mpm@selenic.com>
parents: 24016
diff changeset
   208
typedef unsigned char bool;
98042b0e19f9 manifest: move C bool polyfill into util.h
Matt Mackall <mpm@selenic.com>
parents: 24016
diff changeset
   209
#else
98042b0e19f9 manifest: move C bool polyfill into util.h
Matt Mackall <mpm@selenic.com>
parents: 24016
diff changeset
   210
#include <stdbool.h>
98042b0e19f9 manifest: move C bool polyfill into util.h
Matt Mackall <mpm@selenic.com>
parents: 24016
diff changeset
   211
#endif
98042b0e19f9 manifest: move C bool polyfill into util.h
Matt Mackall <mpm@selenic.com>
parents: 24016
diff changeset
   212
11358
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
   213
#endif /* _HG_UTIL_H_ */