'Allocates a temporary (which may create a new one or get a previously
allocated and released one of the same type). Type is simply registered
and handed back, but will usually be a PyrexType.
If type.is_pyobject, manage_ref comes into play. If manage_ref is set to
True, the temp will be decref-ed on return statements and in exception
handling clauses. Otherwise the caller has to deal with any reference
counting of the variable.
If not type.is_pyobject, then manage_ref will be ignored, but it
still has to be passed. It is recommended to pass False by convention
if it is known that type will never be a Python object.
static=True marks the temporary declaration with "static".
This is only used when allocating backing store for a module-level
C array literals.
A C string referring to the variable is returned.'

def allocate_temp(self, type, manage_ref, static=False):

    if (type.is_const and (not type.is_reference)):
        type = type.const_base_type
    elif (type.is_reference and (not type.is_fake_reference)):
        type = type.ref_base_type
    if ((not type.is_pyobject) and (not type.is_memoryviewslice)):
        manage_ref = False
    freelist = self.temps_free.get((type, manage_ref))
    if ((freelist is not None) and freelist[0]):
        result = freelist[0].pop()
        freelist[1].remove(result)
    else:
        while True:
            self.temp_counter += 1
            result = ('%s%d' % (Naming.codewriter_temp_prefix, self.temp_counter))
            if (result not in self.names_taken):
                break
        self.temps_allocated.append((result, type, manage_ref, static))
    self.temps_used_type[result] = (type, manage_ref)
    if DebugFlags.debug_temp_code_comments:
        self.owner.putln(('/*    %s    allocated    (%s)    */' % (result, type)))
    if self.collect_temps_stack:
        self.collect_temps_stack[(-1)].add((result, type))
    return result
