Coverage Report

Created: 2026-08-19 06:33

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/snappy/snappy-stubs-internal.h
Line
Count
Source
1
// Copyright 2011 Google Inc. All Rights Reserved.
2
//
3
// Redistribution and use in source and binary forms, with or without
4
// modification, are permitted provided that the following conditions are
5
// met:
6
//
7
//     * Redistributions of source code must retain the above copyright
8
// notice, this list of conditions and the following disclaimer.
9
//     * Redistributions in binary form must reproduce the above
10
// copyright notice, this list of conditions and the following disclaimer
11
// in the documentation and/or other materials provided with the
12
// distribution.
13
//     * Neither the name of Google Inc. nor the names of its
14
// contributors may be used to endorse or promote products derived from
15
// this software without specific prior written permission.
16
//
17
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
//
29
// Various stubs for the open-source version of Snappy.
30
31
#ifndef THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_INTERNAL_H_
32
#define THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_INTERNAL_H_
33
34
#if HAVE_CONFIG_H
35
#include "config.h"
36
#endif
37
38
#include <stdint.h>
39
40
#include <cassert>
41
#include <cstdlib>
42
#include <cstring>
43
#include <limits>
44
#include <string>
45
46
#if HAVE_SYS_MMAN_H
47
#include <sys/mman.h>
48
#endif
49
50
#if HAVE_UNISTD_H
51
#include <unistd.h>
52
#endif
53
54
#if defined(_MSC_VER)
55
#include <intrin.h>
56
#endif  // defined(_MSC_VER)
57
58
#ifndef __has_feature
59
#define __has_feature(x) 0
60
#endif
61
62
#if __has_feature(memory_sanitizer)
63
#include <sanitizer/msan_interface.h>
64
#define SNAPPY_ANNOTATE_MEMORY_IS_INITIALIZED(address, size) \
65
    __msan_unpoison((address), (size))
66
#else
67
#define SNAPPY_ANNOTATE_MEMORY_IS_INITIALIZED(address, size) /* empty */
68
#endif  // __has_feature(memory_sanitizer)
69
70
#include "snappy-stubs-public.h"
71
72
// Used to enable 64-bit optimized versions of some routines.
73
#if defined(__PPC64__) || defined(__powerpc64__)
74
#define ARCH_PPC 1
75
#elif defined(__aarch64__) || defined(_M_ARM64)
76
#define ARCH_ARM 1
77
#endif
78
79
// Needed by OS X, among others.
80
#ifndef MAP_ANONYMOUS
81
#define MAP_ANONYMOUS MAP_ANON
82
#endif
83
84
// The size of an array, if known at compile-time.
85
// Will give unexpected results if used on a pointer.
86
// We undefine it first, since some compilers already have a definition.
87
#ifdef ARRAYSIZE
88
#undef ARRAYSIZE
89
#endif
90
#define ARRAYSIZE(a) int{sizeof(a) / sizeof(*(a))}
91
92
// Static prediction hints.
93
#if HAVE_BUILTIN_EXPECT
94
143M
#define SNAPPY_PREDICT_FALSE(x) (__builtin_expect(x, 0))
95
17.2M
#define SNAPPY_PREDICT_TRUE(x) (__builtin_expect(!!(x), 1))
96
#else
97
#define SNAPPY_PREDICT_FALSE(x) x
98
#define SNAPPY_PREDICT_TRUE(x) x
99
#endif  // HAVE_BUILTIN_EXPECT
100
101
// Inlining hints.
102
#if HAVE_ATTRIBUTE_ALWAYS_INLINE
103
#define SNAPPY_ATTRIBUTE_ALWAYS_INLINE __attribute__((always_inline))
104
#else
105
#define SNAPPY_ATTRIBUTE_ALWAYS_INLINE
106
#endif  // HAVE_ATTRIBUTE_ALWAYS_INLINE
107
108
#if HAVE_BUILTIN_PREFETCH
109
11.4M
#define SNAPPY_PREFETCH(ptr) __builtin_prefetch(ptr, 0, 3)
110
#else
111
#define SNAPPY_PREFETCH(ptr) (void)(ptr)
112
#endif
113
114
// Stubbed version of ABSL_FLAG.
115
//
116
// In the open source version, flags can only be changed at compile time.
117
#define SNAPPY_FLAG(flag_type, flag_name, default_value, help) \
118
  flag_type FLAGS_ ## flag_name = default_value
119
120
namespace snappy {
121
122
// Stubbed version of absl::GetFlag().
123
template <typename T>
124
inline T GetFlag(T flag) { return flag; }
125
126
static const uint32_t kuint32max = std::numeric_limits<uint32_t>::max();
127
static const int64_t kint64max = std::numeric_limits<int64_t>::max();
128
129
// Potentially unaligned loads and stores.
130
131
0
inline uint16_t UNALIGNED_LOAD16(const void *p) {
132
0
  // Compiles to a single movzx/ldrh on clang/gcc/msvc.
133
0
  uint16_t v;
134
0
  std::memcpy(&v, p, sizeof(v));
135
0
  return v;
136
0
}
137
138
0
inline uint32_t UNALIGNED_LOAD32(const void *p) {
139
0
  // Compiles to a single mov/ldr on clang/gcc/msvc.
140
0
  uint32_t v;
141
0
  std::memcpy(&v, p, sizeof(v));
142
0
  return v;
143
0
}
144
145
65.0M
inline uint64_t UNALIGNED_LOAD64(const void *p) {
146
  // Compiles to a single mov/ldr on clang/gcc/msvc.
147
65.0M
  uint64_t v;
148
65.0M
  std::memcpy(&v, p, sizeof(v));
149
65.0M
  return v;
150
65.0M
}
151
152
0
inline void UNALIGNED_STORE16(void *p, uint16_t v) {
153
0
  // Compiles to a single mov/strh on clang/gcc/msvc.
154
0
  std::memcpy(p, &v, sizeof(v));
155
0
}
156
157
0
inline void UNALIGNED_STORE32(void *p, uint32_t v) {
158
0
  // Compiles to a single mov/str on clang/gcc/msvc.
159
0
  std::memcpy(p, &v, sizeof(v));
160
0
}
161
162
0
inline void UNALIGNED_STORE64(void *p, uint64_t v) {
163
0
  // Compiles to a single mov/str on clang/gcc/msvc.
164
0
  std::memcpy(p, &v, sizeof(v));
165
0
}
166
167
// Convert to little-endian storage, opposite of network format.
168
// Convert x from host to little endian: x = LittleEndian.FromHost(x);
169
// convert x from little endian to host: x = LittleEndian.ToHost(x);
170
//
171
//  Store values into unaligned memory converting to little endian order:
172
//    LittleEndian.Store16(p, x);
173
//
174
//  Load unaligned values stored in little endian converting to host order:
175
//    x = LittleEndian.Load16(p);
176
class LittleEndian {
177
 public:
178
  // Functions to do unaligned loads and stores in little-endian order.
179
0
  static inline uint16_t Load16(const void *ptr) {
180
0
    // Compiles to a single mov/str on recent clang and gcc.
181
0
#if SNAPPY_IS_BIG_ENDIAN
182
0
    const uint8_t* const buffer = reinterpret_cast<const uint8_t*>(ptr);
183
0
    return (static_cast<uint16_t>(buffer[0])) |
184
0
            (static_cast<uint16_t>(buffer[1]) << 8);
185
0
#else
186
0
    // memcpy() turns into a single instruction early in the optimization
187
0
    // pipeline (relatively to a series of byte accesses). So, using memcpy
188
0
    // instead of byte accesses may lead to better decisions in more stages of
189
0
    // the optimization pipeline.
190
0
    uint16_t value;
191
0
    std::memcpy(&value, ptr, 2);
192
0
    return value;
193
0
#endif
194
0
  }
195
196
130M
  static inline uint32_t Load32(const void *ptr) {
197
    // Compiles to a single mov/str on recent clang and gcc.
198
#if SNAPPY_IS_BIG_ENDIAN
199
    const uint8_t* const buffer = reinterpret_cast<const uint8_t*>(ptr);
200
    return (static_cast<uint32_t>(buffer[0])) |
201
            (static_cast<uint32_t>(buffer[1]) << 8) |
202
            (static_cast<uint32_t>(buffer[2]) << 16) |
203
            (static_cast<uint32_t>(buffer[3]) << 24);
204
#else
205
    // See Load16() for the rationale of using memcpy().
206
130M
    uint32_t value;
207
130M
    std::memcpy(&value, ptr, 4);
208
130M
    return value;
209
130M
#endif
210
130M
  }
211
212
45.5M
  static inline uint64_t Load64(const void *ptr) {
213
    // Compiles to a single mov/str on recent clang and gcc.
214
#if SNAPPY_IS_BIG_ENDIAN
215
    const uint8_t* const buffer = reinterpret_cast<const uint8_t*>(ptr);
216
    return (static_cast<uint64_t>(buffer[0])) |
217
            (static_cast<uint64_t>(buffer[1]) << 8) |
218
            (static_cast<uint64_t>(buffer[2]) << 16) |
219
            (static_cast<uint64_t>(buffer[3]) << 24) |
220
            (static_cast<uint64_t>(buffer[4]) << 32) |
221
            (static_cast<uint64_t>(buffer[5]) << 40) |
222
            (static_cast<uint64_t>(buffer[6]) << 48) |
223
            (static_cast<uint64_t>(buffer[7]) << 56);
224
#else
225
    // See Load16() for the rationale of using memcpy().
226
45.5M
    uint64_t value;
227
45.5M
    std::memcpy(&value, ptr, 8);
228
45.5M
    return value;
229
45.5M
#endif
230
45.5M
  }
231
232
0
  static inline void Store16(void *dst, uint16_t value) {
233
0
    // Compiles to a single mov/str on recent clang and gcc.
234
0
#if SNAPPY_IS_BIG_ENDIAN
235
0
    uint8_t* const buffer = reinterpret_cast<uint8_t*>(dst);
236
0
    buffer[0] = static_cast<uint8_t>(value);
237
0
    buffer[1] = static_cast<uint8_t>(value >> 8);
238
0
#else
239
0
    // See Load16() for the rationale of using memcpy().
240
0
    std::memcpy(dst, &value, 2);
241
0
#endif
242
0
  }
243
244
8.18M
  static void Store32(void *dst, uint32_t value) {
245
    // Compiles to a single mov/str on recent clang and gcc.
246
#if SNAPPY_IS_BIG_ENDIAN
247
    uint8_t* const buffer = reinterpret_cast<uint8_t*>(dst);
248
    buffer[0] = static_cast<uint8_t>(value);
249
    buffer[1] = static_cast<uint8_t>(value >> 8);
250
    buffer[2] = static_cast<uint8_t>(value >> 16);
251
    buffer[3] = static_cast<uint8_t>(value >> 24);
252
#else
253
    // See Load16() for the rationale of using memcpy().
254
8.18M
    std::memcpy(dst, &value, 4);
255
8.18M
#endif
256
8.18M
  }
257
258
0
  static void Store64(void* dst, uint64_t value) {
259
0
    // Compiles to a single mov/str on recent clang and gcc.
260
0
#if SNAPPY_IS_BIG_ENDIAN
261
0
    uint8_t* const buffer = reinterpret_cast<uint8_t*>(dst);
262
0
    buffer[0] = static_cast<uint8_t>(value);
263
0
    buffer[1] = static_cast<uint8_t>(value >> 8);
264
0
    buffer[2] = static_cast<uint8_t>(value >> 16);
265
0
    buffer[3] = static_cast<uint8_t>(value >> 24);
266
0
    buffer[4] = static_cast<uint8_t>(value >> 32);
267
0
    buffer[5] = static_cast<uint8_t>(value >> 40);
268
0
    buffer[6] = static_cast<uint8_t>(value >> 48);
269
0
    buffer[7] = static_cast<uint8_t>(value >> 56);
270
0
#else
271
0
    // See Load16() for the rationale of using memcpy().
272
0
    std::memcpy(dst, &value, 8);
273
0
#endif
274
0
  }
275
276
0
  static inline constexpr bool IsLittleEndian() {
277
0
#if SNAPPY_IS_BIG_ENDIAN
278
0
    return false;
279
0
#else
280
0
    return true;
281
0
#endif  // SNAPPY_IS_BIG_ENDIAN
282
0
  }
283
};
284
285
// Some bit-manipulation functions.
286
class Bits {
287
 public:
288
  // Return floor(log2(n)) for positive integer n.
289
  static int Log2FloorNonZero(uint32_t n);
290
291
  // Return floor(log2(n)) for positive integer n.  Returns -1 iff n == 0.
292
  static int Log2Floor(uint32_t n);
293
294
  // Return the first set least / most significant bit, 0-indexed.  Returns an
295
  // undefined value if n == 0.  FindLSBSetNonZero() is similar to ffs() except
296
  // that it's 0-indexed.
297
  static int FindLSBSetNonZero(uint32_t n);
298
299
  static int FindLSBSetNonZero64(uint64_t n);
300
301
 private:
302
  // No copying
303
  Bits(const Bits&);
304
  void operator=(const Bits&);
305
};
306
307
// In RISC-V,  CLZ  is supported by instructions from the ZBB bit-manipulation extension.
308
#if HAVE_BUILTIN_CTZ
309
310
73.2k
inline int Bits::Log2FloorNonZero(uint32_t n) {
311
73.2k
  assert(n != 0);
312
  // (31 ^ x) is equivalent to (31 - x) for x in [0, 31]. An easy proof
313
  // represents subtraction in base 2 and observes that there's no carry.
314
  //
315
  // GCC and Clang represent __builtin_clz on x86 as 31 ^ _bit_scan_reverse(x).
316
  // Using "31 ^" here instead of "31 -" allows the optimizer to strip the
317
  // function body down to _bit_scan_reverse(x).
318
73.2k
  return 31 ^ __builtin_clz(n);
319
73.2k
}
320
321
73.2k
inline int Bits::Log2Floor(uint32_t n) {
322
73.2k
  return (n == 0) ? -1 : Bits::Log2FloorNonZero(n);
323
73.2k
}
324
325
0
inline int Bits::FindLSBSetNonZero(uint32_t n) {
326
0
  assert(n != 0);
327
0
  return __builtin_ctz(n);
328
0
}
329
330
#elif defined(_MSC_VER)
331
332
inline int Bits::Log2FloorNonZero(uint32_t n) {
333
  assert(n != 0);
334
  // NOLINTNEXTLINE(runtime/int): The MSVC intrinsic demands unsigned long.
335
  unsigned long where;
336
  _BitScanReverse(&where, n);
337
  return static_cast<int>(where);
338
}
339
340
inline int Bits::Log2Floor(uint32_t n) {
341
  // NOLINTNEXTLINE(runtime/int): The MSVC intrinsic demands unsigned long.
342
  unsigned long where;
343
  if (_BitScanReverse(&where, n))
344
    return static_cast<int>(where);
345
  return -1;
346
}
347
348
inline int Bits::FindLSBSetNonZero(uint32_t n) {
349
  assert(n != 0);
350
  // NOLINTNEXTLINE(runtime/int): The MSVC intrinsic demands unsigned long.
351
  unsigned long where;
352
  if (_BitScanForward(&where, n))
353
    return static_cast<int>(where);
354
  return 32;
355
}
356
357
#else  // Portable versions.
358
359
inline int Bits::Log2FloorNonZero(uint32_t n) {
360
  assert(n != 0);
361
362
  int log = 0;
363
  uint32_t value = n;
364
  for (int i = 4; i >= 0; --i) {
365
    int shift = (1 << i);
366
    uint32_t x = value >> shift;
367
    if (x != 0) {
368
      value = x;
369
      log += shift;
370
    }
371
  }
372
  assert(value == 1);
373
  return log;
374
}
375
376
inline int Bits::Log2Floor(uint32_t n) {
377
  return (n == 0) ? -1 : Bits::Log2FloorNonZero(n);
378
}
379
380
inline int Bits::FindLSBSetNonZero(uint32_t n) {
381
  assert(n != 0);
382
383
  int rc = 31;
384
  for (int i = 4, shift = 1 << 4; i >= 0; --i) {
385
    const uint32_t x = n << shift;
386
    if (x != 0) {
387
      n = x;
388
      rc -= shift;
389
    }
390
    shift >>= 1;
391
  }
392
  return rc;
393
}
394
395
#endif  // End portable versions.
396
397
// In RISC-V,  CLZ  is supported by instructions from the ZBB bit-manipulation extension.
398
#if HAVE_BUILTIN_CTZ
399
400
6.73M
inline int Bits::FindLSBSetNonZero64(uint64_t n) {
401
6.73M
  assert(n != 0);
402
6.73M
  return __builtin_ctzll(n);
403
6.73M
}
404
405
#elif defined(_MSC_VER) && (defined(_M_X64) || defined(_M_ARM64))
406
// _BitScanForward64() is only available on x64 and ARM64.
407
408
inline int Bits::FindLSBSetNonZero64(uint64_t n) {
409
  assert(n != 0);
410
  // NOLINTNEXTLINE(runtime/int): The MSVC intrinsic demands unsigned long.
411
  unsigned long where;
412
  if (_BitScanForward64(&where, n))
413
    return static_cast<int>(where);
414
  return 64;
415
}
416
417
#else  // Portable version.
418
419
// FindLSBSetNonZero64() is defined in terms of FindLSBSetNonZero().
420
inline int Bits::FindLSBSetNonZero64(uint64_t n) {
421
  assert(n != 0);
422
423
  const uint32_t bottombits = static_cast<uint32_t>(n);
424
  if (bottombits == 0) {
425
    // Bottom bits are zero, so scan the top bits.
426
    return 32 + FindLSBSetNonZero(static_cast<uint32_t>(n >> 32));
427
  } else {
428
    return FindLSBSetNonZero(bottombits);
429
  }
430
}
431
432
#endif  // HAVE_BUILTIN_CTZ
433
434
// Variable-length integer encoding.
435
class Varint {
436
 public:
437
  // Maximum lengths of varint encoding of uint32_t.
438
  static const int kMax32 = 5;
439
440
  // Attempts to parse a varint32 from a prefix of the bytes in [ptr,limit-1].
441
  // Never reads a character at or beyond limit.  If a valid/terminated varint32
442
  // was found in the range, stores it in *OUTPUT and returns a pointer just
443
  // past the last byte of the varint32. Else returns NULL.  On success,
444
  // "result <= limit".
445
  static const char* Parse32WithLimit(const char* ptr, const char* limit,
446
                                      uint32_t* OUTPUT);
447
448
  // REQUIRES   "ptr" points to a buffer of length sufficient to hold "v".
449
  // EFFECTS    Encodes "v" into "ptr" and returns a pointer to the
450
  //            byte just past the last encoded byte.
451
  static char* Encode32(char* ptr, uint32_t v);
452
453
  // EFFECTS    Appends the varint representation of "value" to "*s".
454
  static void Append32(std::string* s, uint32_t value);
455
};
456
457
inline const char* Varint::Parse32WithLimit(const char* p,
458
                                            const char* l,
459
7.65k
                                            uint32_t* OUTPUT) {
460
7.65k
  const unsigned char* ptr = reinterpret_cast<const unsigned char*>(p);
461
7.65k
  const unsigned char* limit = reinterpret_cast<const unsigned char*>(l);
462
7.65k
  uint32_t b, result;
463
7.65k
  if (ptr >= limit) return NULL;
464
7.65k
  b = *(ptr++); result = b & 127;          if (b < 128) goto done;
465
4.17k
  if (ptr >= limit) return NULL;
466
4.16k
  b = *(ptr++); result |= (b & 127) <<  7; if (b < 128) goto done;
467
1.60k
  if (ptr >= limit) return NULL;
468
1.59k
  b = *(ptr++); result |= (b & 127) << 14; if (b < 128) goto done;
469
197
  if (ptr >= limit) return NULL;
470
189
  b = *(ptr++); result |= (b & 127) << 21; if (b < 128) goto done;
471
159
  if (ptr >= limit) return NULL;
472
151
  b = *(ptr++); result |= (b & 127) << 28; if (b < 16) goto done;
473
8
  return NULL;       // Value is too long to be a varint32
474
7.61k
 done:
475
7.61k
  *OUTPUT = result;
476
7.61k
  return reinterpret_cast<const char*>(ptr);
477
151
}
478
479
5.33k
inline char* Varint::Encode32(char* sptr, uint32_t v) {
480
  // Operate on characters as unsigneds
481
5.33k
  uint8_t* ptr = reinterpret_cast<uint8_t*>(sptr);
482
5.33k
  static const uint8_t B = 128;
483
5.33k
  if (v < (1 << 7)) {
484
2.47k
    *(ptr++) = static_cast<uint8_t>(v);
485
2.85k
  } else if (v < (1 << 14)) {
486
1.77k
    *(ptr++) = static_cast<uint8_t>(v | B);
487
1.77k
    *(ptr++) = static_cast<uint8_t>(v >> 7);
488
1.77k
  } else if (v < (1 << 21)) {
489
1.07k
    *(ptr++) = static_cast<uint8_t>(v | B);
490
1.07k
    *(ptr++) = static_cast<uint8_t>((v >> 7) | B);
491
1.07k
    *(ptr++) = static_cast<uint8_t>(v >> 14);
492
1.07k
  } else if (v < (1 << 28)) {
493
0
    *(ptr++) = static_cast<uint8_t>(v | B);
494
0
    *(ptr++) = static_cast<uint8_t>((v >> 7) | B);
495
0
    *(ptr++) = static_cast<uint8_t>((v >> 14) | B);
496
0
    *(ptr++) = static_cast<uint8_t>(v >> 21);
497
0
  } else {
498
0
    *(ptr++) = static_cast<uint8_t>(v | B);
499
0
    *(ptr++) = static_cast<uint8_t>((v>>7) | B);
500
0
    *(ptr++) = static_cast<uint8_t>((v>>14) | B);
501
0
    *(ptr++) = static_cast<uint8_t>((v>>21) | B);
502
0
    *(ptr++) = static_cast<uint8_t>(v >> 28);
503
0
  }
504
5.33k
  return reinterpret_cast<char*>(ptr);
505
5.33k
}
506
507
// If you know the internal layout of the std::string in use, you can
508
// replace this function with one that resizes the string without
509
// filling the new space with zeros (if applicable) --
510
// it will be non-portable but faster.
511
11.7k
inline void STLStringResizeUninitialized(std::string* s, size_t new_size) {
512
11.7k
  s->resize(new_size);
513
11.7k
}
514
515
// Return a mutable char* pointing to a string's internal buffer,
516
// which may not be null-terminated. Writing through this pointer will
517
// modify the string.
518
//
519
// string_as_array(&str)[i] is valid for 0 <= i < str.size() until the
520
// next call to a string method that invalidates iterators.
521
//
522
// As of 2006-04, there is no standard-blessed way of getting a
523
// mutable reference to a string's internal buffer. However, issue 530
524
// (http://www.open-std.org/JTC1/SC22/WG21/docs/lwg-defects.html#530)
525
// proposes this as the method. It will officially be part of the standard
526
// for C++0x. This should already work on all current implementations.
527
11.7k
inline char* string_as_array(std::string* str) {
528
11.7k
  return str->empty() ? NULL : &*str->begin();
529
11.7k
}
530
531
}  // namespace snappy
532
533
#endif  // THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_INTERNAL_H_