Staging
v0.5.1
https://github.com/python/cpython
Revision e0c3f5edc0f20cc28363258df501758c1bdb1ca7 authored by Nick Coghlan on 05 August 2012, 08:20:17 UTC, committed by Nick Coghlan on 05 August 2012, 08:20:17 UTC
1 parent 37d3ff1
Raw File
Tip revision: e0c3f5edc0f20cc28363258df501758c1bdb1ca7 authored by Nick Coghlan on 05 August 2012, 08:20:17 UTC
Close #15559: Implementing __index__ creates a nasty interaction with the bytes constructor. At least for 3.3, ipaddress objects must now be explicitly converted with int() and thus can't be passed directly to the hex() builtin.
Tip revision: e0c3f5e
typeslots.py
#!/usr/bin/python
# Usage: typeslots.py < Include/typeslots.h > typeslots.inc

import sys, re

print("/* Generated by typeslots.py */")
res = {}
for line in sys.stdin:
    m = re.match("#define Py_([a-z_]+) ([0-9]+)", line)
    if not m:
        continue
    member = m.group(1)
    if member.startswith("tp_"):
        member = "ht_type."+member
    elif member.startswith("nb_"):
        member = "as_number."+member
    elif member.startswith("mp_"):
        member = "as_mapping."+member
    elif member.startswith("sq_"):
        member = "as_sequence."+member
    elif member.startswith("bf_"):
        member = "as_buffer."+member
    res[int(m.group(2))] = member

M = max(res.keys())+1
for i in range(1,M):
    if i in res:
        print("offsetof(PyHeapTypeObject, %s)," % res[i])
    else:
        print("0,")
back to top