Martin v. Löwis wrote:
> M.-A. Lemburg wrote:
>> What do you think ?
> 
> I think the size could be further reduced by restricting the set of
> error codes. For example, if the COM error codes are left out, I only
> get a Python file with 60k source size (although the bytecode size
> is then 130k). I'm not sure whether GetLastError can ever return a COM
> error code, but in my experience, it never did.

I was leaving those out already - only the codes named 'ERROR_*'
get included (see attached parser and generator).

> I wouldn't want to introduce a clumsy interface just to achieve space
> savings. If people consider the space consumption of 200k disk
> size unacceptable (or would never use the module because of the runtime
> size effects), the entire idea should be dropped (IMO). OTOH, I don't
> find such a size increase unacceptable myself.

Using a lookup object is not really clumsy - you can still access
all the values by attribute access. The only difference is that
they don't live in the module namespace, but get accessed via
an object.

I'm not worried about the disk space being used. The heap
memory usage is what's worrying: the import of the module lets
the non-shared memory size of the process grow by 700kB
on my AMD64 box.

Regards,
-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, May 13 2006)
>>> Python/Zope Consulting and Support ...        http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
________________________________________________________________________

::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! ::::
#!/usr/bin/env python

""" Create the winerror module from the data found in the
    Windows Platform SDK WinError.h file.

"""
import re

WINERROR_H = './WinError.h'

MODULE_LAYOUT = """\
#
# winerror module
#
# Generated from the Windows Platform SDK include file WinError.h
#

# Error symbols
%s

# Error codes dictionary
%s
"""

ERROR_DEF_RE = re.compile('#define\s+(ERROR_[A-Z0-9_]+)\s+([0-9]+)')

def parse_defs(filename):

    file = open(filename)
    d = {}
    for line in file:
        m = ERROR_DEF_RE.match(line)
        if m is None:
            continue
        symbol, value = m.groups()
        d[symbol] = int(value)
    return d

def generate_python_dict_literal(dictname, data):

    items = data.items()
    items.sort()
    maxkeylength = max([len(repr(key))
                        for key in data.iterkeys()])
    formatstring = '   %%-%ir: %%r,' % maxkeylength
    l = ['%s = {' % dictname]
    l.extend([formatstring % (key, value)
              for (key, value) in items])
    l.append('}')
    return '\n'.join(l)

def invdict(d):

    return dict([(value, key) for (key, value) in d.iteritems()])

def generate_python_attribute_definitions(data):

    items = data.items()
    items.sort()
    maxkeylength = max([len(repr(key))
                        for key in data.iterkeys()])
    formatstring = '%%-%is = %%r' % maxkeylength
    l = [formatstring % (key, value)
         for (key, value) in items]
    return '\n'.join(l)

def generate_winerror_module(data):

    return MODULE_LAYOUT % (
        generate_python_attribute_definitions(data),
        generate_python_dict_literal('errorcode', invdict(data)))

if __name__ == '__main__':
    data = parse_defs(WINERROR_H)
    print generate_winerror_module(data)
    
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to