def generateListCreationCode(to_name, expression, emit, context):
    elements = expression.getElements()
    emit(('%s = PyList_New( %d );' % (to_name, len(elements))))
    context.addCleanupTempName(to_name)
    element_name = context.allocateTempName('list_element')
    for (count, element) in enumerate(elements):
        generateExpressionCode(to_name=element_name, expression=element, emit=emit, context=context)
        if (not context.needsCleanup(element_name)):
            emit(('Py_INCREF( %s );' % element_name))
        else:
            context.removeCleanupTempName(element_name)
        emit(('PyList_SET_ITEM( %s, %d, %s );' % (to_name, count, element_name)))
def generateListCreationCode(to_name, expression, emit, context):
    elements = expression.getElements()
    emit(('%s = PyList_New( %d );' % (to_name, len(elements))))
    context.addCleanupTempName(to_name)
    element_name = context.allocateTempName('list_element')
    for (count, element) in enumerate(elements):
        generateExpressionCode(to_name=element_name, expression=element, emit=emit, context=context)
        if (not context.needsCleanup(element_name)):
            emit(('Py_INCREF( %s );' % element_name))
        else:
            context.removeCleanupTempName(element_name)
        emit(('PyList_SET_ITEM( %s, %d, %s );' % (to_name, count, element_name)))