Esempio n. 1
0
static void allocWithCopyAttrList(ParserObjectAttrT** a, ParserObjectAttrT* b, int n)
{
    int i;
    if (!b) {*a = 0; return;}
    *a = AllocateArray(n, sizeof(ParserObjectAttrT));
    for (i = 0; i < n; i++) copyAttrToAttr((*a) + i, b + i);
}
Esempio n. 2
0
ParserObjectRecordWithDataT ParserGetSequenceElement(
    ParserObjectWithDataT info,
    int64_t index
)
{
    ParserObjectDataT* data = info.pointerToData;
    ParserObjectT* a = info.objPart;
    ParserObjectRecordWithDataT res;
    ParserObjectRecordDataT* d;
    int n = ParserGetSequenceLength(info);
    int i;
    res.pointerToData = 0; res.recPart = 0;
    if (ParserIsErrorRaised()) return res;
    if (index < 1 || index > n) {
        genParseError(E_INVALID_INDEX);
        return res;
    }
    if (!data->value) {
        data->value = AllocateArray(n, sizeof(ParserObjectRecordDataT));
        d = (ParserObjectRecordDataT*)(data->value);
        for (i = 0; i < n; i++) {
            d[i].data = 0;
            d[i].parentData = data;
        }
    }
    res.recPart = a->rec;
    //take 1-indexed value
    res.pointerToData = &(((ParserObjectRecordDataT*)(data->value))[index-1]);
    if (!res.pointerToData->data) res = *ParserAllocateObjectRecordWithData(&res, 0);
    return res;
}
Esempio n. 3
0
TetrisPiece::TetrisPiece(ePieceType pieceType):
m_currentRotation(0),
m_pieceType(pieceType)
{
	AllocateArray();
	CreatePiece(pieceType);
}
Esempio n. 4
0
static void allocWithCopyObjRecord(ParserObjectRecordT** a, ParserObjectRecordT* b)
{
    int i;
    if (!b) {*a = 0; return;}
    *a = AllocateBuffer(sizeof(ParserObjectRecordT));
    (*a)->n = b->n;
    (*a)->parent = b->parent;
    (*a)->seq = AllocateArray(b->n, sizeof(ParserObjectT));
    for (i = 0; i < b->n; i++) {
        copyObjToObj((*a)->seq + i, b->seq + i);
        (*a)->seq[i].parent = *a;
        if ((*a)->seq[i].objKind == PARSER_OBJECT_KIND_SEQUENCE) (*a)->seq[i].rec->parent = *a;
    }
}
Esempio n. 5
0
    void ConvertListToArray() {
        assert(ChildrenListHead != nullptr);

        TrieNode** array = AllocateArray();
        TrieList* listNode = ChildrenListHead;

        while(listNode) {
            array[listNode->Value] = listNode->Node;
            listNode = listNode->Next;
        }

        DeallocateList(ChildrenListHead, false);
        ChildrenArray = array;
    }
Esempio n. 6
0
static ParserObjectAttrT* parseAttrList(
    ParserObjectKindT objKind,
    ParserObjectRecordT* curSeq
)
{
    //it should eat semicolons too
    ParserObjectAttrT *res = 0;
    ParserObjectAttrT *curAttr;
    int bad = 0, i, n = 0;
    int vis[PARSER_OBJECT_ATTRIBUTE_KINDS_COUNT];

    res = AllocateArray(PARSER_OBJECT_ATTRIBUTE_KINDS_COUNT,
        sizeof(ParserObjectAttrT));
    memset(vis, 0, sizeof(vis));

    while ((curAttr = parseAttr(curSeq))) {
        i = attrFind(curAttr->attrName);
        if (vis[i]) {
            genParseError(E_ATTRIBUTE_ALREADY_DEFINED);
            attrDestructor(curAttr); curAttr = 0;
            bad = 1; break;
        }
        if (!g_ParserObjectAttrKindIsValidForObjectKind[objKind][i]) {
            genParseError(E_INVALID_ATTRIBUTE);
            attrDestructor(curAttr); curAttr = 0;
            bad = 1; break;
        }
        vis[i] = 1; n++;
        copyAttrToAttr(&(res[i]), curAttr);
        attrDestructor(curAttr);

        if (chkCurToken(',')) {
            bad = 1; moveToNextToken();
        } else bad = 0;
    }

    if (ParserIsErrorRaised()) {attrListDestructor(res); return NULL;}
    if (n < getAttrCount(objKind)) bad = 1;
    if (bad) {
        attrListDestructor(res);
        genParseError(E_INVALID_ATTRIBUTE_LIST);
        return NULL;
    }
    if (!curToken || chkCurToken(';')) {
        if (curToken) moveToNextToken();
        return res;
    } else {attrListDestructor(res); return NULL;}
}
Esempio n. 7
0
int main(int argc, char *argv[]) {
  if (argc < 2) return 1;
  unsigned int n = std::stoi(argv[1]);

  // Returned memory address stored in stack variable
  double *a = AllocateArray(n);

  // Memory is now used by main()
  for (unsigned int i = 0; i < n; i++)
    a[i] = i+3; 
  for (unsigned int i = 0; i < n; i++)
    std::cout << "a[" << i << "] = " << a[i] << std::endl;

  delete[] a; // Memory is freed
  a = NULL;

  return 0;
}
Esempio n. 8
0
static ParserObjectRecordT* parseObjRecord1(ParserObjectRecordT* parent)
{
    ParserObjectT* curObj;
    ParserObjectRecordT *res, *tmp;
    int wasEnd = 0;
    int i;
    res = AllocateBuffer(sizeof(ParserObjectRecordT));
    res->n = 0; res->seq = 0; res->parent = parent;

    while ((curObj = parseNextObject(res))) {
        if (curObj->objKind == PARSER_OBJECT_KIND_END) {
            if (!parent) {
                genParseError(E_UNEXPECTED_END);
            } else {
                objDestructor(curObj);
                wasEnd = 1;
            }
            break;
        }
        res->n++;
        tmp = AllocateBuffer(sizeof(ParserObjectRecordT));
        tmp->seq = AllocateArray(res->n, sizeof(ParserObjectT));
        for (i = 0; i < res->n - 1; i++) {
            copyObjToObj(tmp->seq + i, res->seq + i);
            tmp->seq[i].parent = tmp;
            if (tmp->seq[i].objKind == PARSER_OBJECT_KIND_SEQUENCE) tmp->seq[i].rec->parent = tmp;
        }
        tmp->parent = res->parent; tmp->n = res->n;
        res->n--; ParserDestroyObjectRecord(res);
        copyObjToObj(tmp->seq + tmp->n - 1, curObj);
        tmp->seq[tmp->n - 1].parent = tmp;
        if (tmp->seq[tmp->n - 1].objKind == PARSER_OBJECT_KIND_SEQUENCE)
            tmp->seq[tmp->n - 1].rec->parent = tmp;
        res = tmp;
        objDestructor(curObj);
    }

    if (!wasEnd && parent) {
        genParseError(E_END_EXPECTED);
    }

    if (ParserIsErrorRaised()) {ParserDestroyObjectRecord(res); return 0;}
    return res;
}
Esempio n. 9
0
/* Allocate memory for all dynamic variables of the decoder. */
static void AllocateDecMemory (ebunch * D)
{
  D->FrameHdr.ICoefA = AllocateArray(2,sizeof(**D->FrameHdr.ICoefA),D->FrameHdr.MaxNrOfFilters, (1<<SIZE_CODEDPREDORDER));

  D->StrFilter.Coded = MemoryAllocate(D->FrameHdr.MaxNrOfFilters, sizeof(*D->StrFilter.Coded));
  D->StrFilter.BestMethod = MemoryAllocate(D->FrameHdr.MaxNrOfFilters, sizeof(*D->StrFilter.BestMethod));
  D->StrFilter.m = AllocateArray(2, sizeof(**D->StrFilter.m), D->FrameHdr.MaxNrOfFilters, NROFFRICEMETHODS);
  D->StrFilter.Data = AllocateArray(2, sizeof(**D->StrFilter.Data), D->FrameHdr.MaxNrOfFilters, (1<<SIZE_CODEDPREDORDER) * SIZE_PREDCOEF);
  D->StrFilter.DataLen = MemoryAllocate(D->FrameHdr.MaxNrOfFilters, sizeof(*D->StrFilter.DataLen));
  D->StrFilter.CPredOrder = MemoryAllocate(NROFFRICEMETHODS, sizeof(*D->StrFilter.CPredOrder));
  D->StrFilter.CPredCoef = AllocateArray(2, sizeof(**D->StrFilter.CPredCoef), NROFFRICEMETHODS, MAXCPREDORDER);
  D->StrPtable.Coded = MemoryAllocate(D->FrameHdr.MaxNrOfPtables, sizeof(*D->StrPtable.Coded));
  D->StrPtable.BestMethod = MemoryAllocate(D->FrameHdr.MaxNrOfPtables, sizeof(*D->StrPtable.BestMethod));
  D->StrPtable.m  = AllocateArray(2, sizeof(**D->StrPtable.m), D->FrameHdr.MaxNrOfPtables, NROFPRICEMETHODS);
  D->StrPtable.Data = AllocateArray(2, sizeof(**D->StrPtable.Data), D->FrameHdr.MaxNrOfPtables, AC_BITS * AC_HISMAX);
  D->StrPtable.DataLen = MemoryAllocate(D->FrameHdr.MaxNrOfPtables, sizeof(*D->StrPtable.DataLen));
  D->StrPtable.CPredOrder = MemoryAllocate(NROFPRICEMETHODS, sizeof(*D->StrPtable.CPredOrder));
  D->StrPtable.CPredCoef = AllocateArray(2, sizeof(**D->StrPtable.CPredCoef), NROFPRICEMETHODS, MAXCPREDORDER);
  D->P_one = AllocateArray(2, sizeof(**D->P_one), D->FrameHdr.MaxNrOfPtables, AC_HISMAX);
  D->AData = MemoryAllocate(D->FrameHdr.BitStreamLen,  sizeof(*D->AData));
}
Esempio n. 10
0
//-----------------------------data processing procedures----------------------
ParserObjectRecordWithDataT* ParserAllocateObjectRecordWithData(
    ParserObjectRecordWithDataT *info,
    int isRoot
)
{
    int i;
    if (!info) return NULL;
    if (!info->recPart->n) {info->pointerToData = 0; return info;}
    if (isRoot) {
        info->pointerToData = AllocateBuffer(sizeof(ParserObjectRecordDataT));
        info->pointerToData->parentData = 0;
    }
    info->pointerToData->data =
        AllocateArray(info->recPart->n, sizeof(ParserObjectDataT));
    for (i = 0; i < info->recPart->n; i++) {
        info->pointerToData->data[i].value = 0;
        info->pointerToData->data[i].parentData = info->pointerToData;
    }
    return info;
}