Staging
v0.5.1
https://github.com/python/cpython
Raw File
Tip revision: 6053744c3a3175992ac5f27cdf628e5ca01cbb57 authored by Barry Warsaw on 03 August 2010, 22:39:42 UTC
Bumping to 2.6.6 rc 1
Tip revision: 6053744
bgenStackBuffer.py
"""Buffers allocated on the stack."""


from bgenBuffer import FixedInputBufferType, FixedOutputBufferType


class StackOutputBufferType(FixedOutputBufferType):

    """Fixed output buffer allocated on the stack -- passed as (buffer, size).

    Instantiate with the buffer size as parameter.
    """

    def passOutput(self, name):
        return "%s__out__, %s" % (name, self.size)


class VarStackOutputBufferType(StackOutputBufferType):

    """Output buffer allocated on the stack -- passed as (buffer, &size).

    Instantiate with the buffer size as parameter.
    """

    def getSizeDeclarations(self, name):
        return []

    def getAuxDeclarations(self, name):
        return ["int %s__len__ = %s" % (name, self.size)]

    def passOutput(self, name):
        return "%s__out__, &%s__len__" % (name, name)

    def mkvalueArgs(self, name):
        return "%s__out__, (int)%s__len__" % (name, name)


class VarVarStackOutputBufferType(VarStackOutputBufferType):

    """Output buffer allocated on the stack -- passed as (buffer, size, &size).

    Instantiate with the buffer size as parameter.
    """

    def passOutput(self, name):
        return "%s__out__, %s__len__, &%s__len__" % (name, name, name)


class ReturnVarStackOutputBufferType(VarStackOutputBufferType):

    """Output buffer allocated on the stack -- passed as (buffer, size) -> size.

    Instantiate with the buffer size as parameter.
    The function's return value is the size.
    (XXX Should have a way to suppress returning it separately, too.)
    """

    def passOutput(self, name):
        return "%s__out__, %s__len__" % (name, name)

    def mkvalueArgs(self, name):
        return "%s__out__, (int)_rv" % name
back to top