char *test_push_pop() { List_push(list, test1); mu_assert(List_last(list) == test1, "Wrong last value"); List_push(list, test2); mu_assert(List_last(list) == test2, "Wrong last value"); List_push(list, test3); mu_assert(List_last(list) == test3, "Wrong last value"); mu_assert(List_count(list) == 3, "Wrong count on push"); char *val = List_pop(list); mu_assert(val == test3, "Wrong value on pop"); val = List_pop(list); mu_assert(val == test2, "Wrong value on pop"); val = List_pop(list); mu_assert(val == test1, "Wrong value on pop"); mu_assert(List_count(list) == 0, "Wrong count after pop."); return NULL; }
void str_push_pop(List *list) { SET_TYPE(list, string); List_push(list, "hello world"); List_push(list, "bad boy"); assert(strcmp(List_index(list, 0)->data, "hello world") == 0); assert(strcmp(List_index(list, 1)->data, "bad boy") == 0); assert(strcmp(List_first(list)->data, "hello world") == 0); assert(strcmp(List_last(list)->data, "bad boy") == 0); List_pop(list); List_pop(list); }
void push_pop(List *list) { List_push(list, 12); List_push(list, 7); List_push(list, 2); assert(List_index(list, 0)->data == 12); assert(List_index(list, 1)->data == 7); assert(List_first(list)->data == 12); assert(List_last(list)->data == 2); List_pop(list); assert(List_first(list)->data == 12); List_pop(list); assert(List_first(list)->data == 12); List_pop(list); assert(List_first(list) == NULL); }
__declspec(dllexport) void* curl_shim_multi_info_read(void* pvHandle, int* nMsgs) { // cast return from GetProcAddress as a CPROC List_T lst = NULL; CPVPROC pcp = (CPVPROC)GetProcAddress(g_hModCurl, "curl_multi_info_read"); void* pvItem; int i, nLocalMsgs, j = 0; unsigned int *pnReturn = NULL; unsigned int *pnItem; *nMsgs = 0; while ((pvItem = pcp(pvHandle, &nLocalMsgs)) != NULL) lst = List_push(lst, pvItem); *nMsgs = List_length(lst); if (*nMsgs == 0) return NULL; pnReturn = (unsigned int*)malloc(3 * (*nMsgs) * sizeof(unsigned int)); for (i = 0; i < (*nMsgs); i++) { lst = List_pop(lst, (void**)&pnItem); pnReturn[j++] = pnItem[0]; pnReturn[j++] = pnItem[1]; pnReturn[j++] = pnItem[2]; } List_free(&lst); return pnReturn; }
__declspec(dllexport) void curl_shim_free_slist(void* lst) { void* pvStr = NULL; List_T list = (List_T)lst; while ((list = List_pop(list, &pvStr)) != NULL) free(pvStr); }
IoMessage *IoMessage_opShuffle(IoMessage *self, IoObject *locals, IoMessage *m) { Levels *levels = Levels_new(self); List *expressions = List_new(); List_push_(expressions, self); while (List_size(expressions) >= 1) { IoMessage *n = List_pop(expressions); do { Levels_attach(levels, n, expressions); List_appendSeq_(expressions, DATA(n)->args); } while ((n = DATA(n)->next)); Levels_nextMessage(levels); } List_free(expressions); Levels_free(levels); return self; }
/*----------------------------------------------------------------------------- * Fill scan buffer if needed, return FALSE on end of file *----------------------------------------------------------------------------*/ static Bool fill_buffer( void ) { char *line; while ( *p == '\0' ) { /* get last buffer from stack, if any */ line = List_pop( input_stack ); if ( line != NULL ) { set_scan_buf( line, FALSE ); /* read from stack - assume not at BOL */ m_free( line ); } else { /* get next line from input source file */ line = src_getline(); if ( line == NULL ) return FALSE; /* got new line */ set_scan_buf( line, TRUE ); /* read from file - at BOL */ } } return TRUE; }
static void _gcppl(Port_T *p) { ASSERT(p&&*p); if((*p)->next) _gcppl(&(*p)->next); if((*p)->action) _gc_eventaction(&(*p)->action); if((*p)->generic) _gcgrc(&(*p)->generic); if((*p)->url_request) _gc_request(&(*p)->url_request); FREE((*p)->request); FREE((*p)->hostname); FREE((*p)->pathname); FREE((*p)->SSL.certmd5); FREE((*p)->SSL.clientpemfile); FREE((*p)->request_checksum); FREE((*p)->request_hostheader); if ((*p)->http_headers) { List_T l = (*p)->http_headers; while (List_length(l) > 0) { char *s = List_pop(l); FREE(s); } } FREE(*p); }
void Levels_popDownTo(Levels *self, int targetLevel) { Level *level; while (level = List_top(self->stack), level->precedence <= targetLevel && level->type != ARG) { Level_finish(List_pop(self->stack)); self->currentLevel--; } }
void Levels_nextMessage(Levels *self) { Level *level; while ((level = List_pop(self->stack))) { Level_finish(level); } Levels_reset(self); }
IoObject *IoObject_alloc(IoObject *self) { IoObject *child = List_pop(IOSTATE->recycledObjects); if (!child) { child = IoObject_justAlloc(IOSTATE); } IoObject_markerCount_(child, 0); return child; }
char *test_push_pop() { List_push(list, tv1); mu_assert(List_last(list) == tv1, "Bad last value."); List_push(list, tv2); mu_assert(List_last(list) == tv2, "Bad last value."); List_push(list, tv3); mu_assert(List_last(list) == tv3, "Bad last value."); mu_assert(List_size(list) == 3, "Wrong size"); char *out = List_pop(list); mu_assert(out == tv3, "Bad popped value."); out = List_pop(list); mu_assert(out == tv2, "Bad popped value."); out = List_pop(list); mu_assert(out == tv1, "Bad popped value."); mu_assert(List_size(list) == 0, "Wrong size"); return NULL; }
char *test_push_pop() { List_push(list, test1); mu_assert(List_last(list) == test1, "Wrong last value"); List_push(list, test2); mu_assert(List_last(list) == test2, "Wrong last value"); List_push(list, test3); mu_assert(List_last(list) == test3, "Wrong last value"); mu_assert(List_count(list) == 3, "Wrong count"); char *val = List_pop(list); mu_assert(val == test3, "Wrong popped value"); val = List_pop(list); mu_assert(val == test2, "Wrong popped value"); val = List_pop(list); mu_assert(val == test1, "Wrong popped value"); mu_assert(List_count(list) == 0, "Wrong count"); return NULL; }
IoObject *IoObject_alloc(IoObject *self) { IoObject *child; #ifdef IOSTATE_RECYCLING_ON child = List_pop(IOSTATE->recycledObjects); if (!child) #endif { child = IoObject_justAlloc(IOSTATE); } IoObject_markerCount_(child, 0); return child; }
Bool SrcFile_pop( SrcFile *self ) { FileStackElem *elem; if ( List_empty( self->file_stack ) ) return FALSE; if ( self->file != NULL ) myfclose( self->file ); elem = List_pop( self->file_stack ); self->file = elem->file; self->filename = elem->filename; self->line_nr = elem->line_nr; m_free( elem ); return TRUE; }
int List_pop_test(List *list) { int i; int *val; int count; count = list->count; for (i = 0; i < count; i++) { val = List_pop(list); free(val); } assert(List_count(list) == 0); assert(list->first == NULL); assert(list->last == NULL); return 0; }
bool SrcFile_pop( SrcFile *self ) { FileStackElem *elem; if ( List_empty( self->file_stack ) ) return false; if ( self->file != NULL ) xfclose( self->file ); elem = List_pop( self->file_stack ); self->file = elem->file; self->filename = elem->filename; self->line_filename = elem->line_filename; self->line_nr = elem->line_nr; self->line_inc = elem->line_inc; self->is_c_source = elem->is_c_source; m_free( elem ); return true; }
void IoAudioMixer_processActiveEvents(IoAudioMixer *self) { AudioEvent *e; while ( (e = List_pop(DATA(self)->activeEvents)) ) { #ifdef DEBUG printf("processing: "); AudioEvent_show(e); #endif switch (e->etype) { case AUDIOEVENT_ADD: IoAudioMixer_justAddSound_(self, e->ioPlaySound); break; case AUDIOEVENT_REMOVE: IoAudioMixer_justRemoveSound_(self, e->ioPlaySound); break; } } IoAudioMixer_updateScale(self); }
PID_TYPE UDBIndex_allocPid(UDBIndex *self) { PID_TYPE hole = (PID_TYPE)List_pop(self->holes); if (hole) { return hole; } else { PID_TYPE max = JFile_setPositionToEnd(self->file) / sizeof(UDBIndexEntry); if (max > self->maxPid) { self->maxPid = max; } else { self->maxPid ++; } return self->maxPid; } }
void IoAudioMixer_processSoundRemovals(IoAudioMixer *self) { IoSound *s; List *soundsToRemove = DATA(self)->soundsToRemove; List *sounds = DATA(self)->sounds; int removeCount = List_size(soundsToRemove); if (removeCount) { printf("removeCount = %i\n", removeCount); printf("soundsCount = %i\n", List_size(sounds)); } while ( (s = List_pop(soundsToRemove)) ) { IoAudioMixer_justRemoveSound_(self, s); } if (removeCount) { printf("remaining sounds = %i\n", List_size(sounds)); printf("remaining removeCount = %i\n\n", List_size(soundsToRemove)); } IoAudioMixer_updateScale(self); }
/* get the next line of input, normalize end of line termination (i.e. convert "\r", "\r\n" and "\n\r" to "\n" Calls the new_line_cb call back and returns the pointer to the null-terminated text data in Str *line, including the final "\n". Returns NULL on end of file. */ char *SrcFile_getline( SrcFile *self ) { int c, c1; Bool found_newline; char *line; /* clear result string */ str_clear( self->line ); /* check for line stack */ if ( ! List_empty( self->line_stack ) ) { line = List_pop( self->line_stack ); /* we own the string now and need to release memory */ str_set( self->line, line ); m_free( line ); /* dont increment line number as we are still on same file input line */ return str_data(self->line); } /* check for EOF condition */ if ( self->file == NULL ) return NULL; /* read characters */ found_newline = FALSE; while ( ! found_newline && ( c = getc( self->file ) ) != EOF ) { switch ( c ) { case '\r': case '\n': c1 = getc( self->file ); if ( ( c1 == '\r' || c1 == '\n' ) && /* next char also newline */ c1 != c ) /* "\r\n" or "\n\r" */ { /* c1 will be discarded */ } else /* not composite newline - push back */ { if ( c1 != EOF ) { ungetc( c1, self->file ); /* push back except EOF */ } } /* normalize newline and fall through to default */ found_newline = TRUE; c = '\n'; default: str_append_char( self->line, c ); } } /* terminate string if needed */ if ( str_len(self->line) > 0 && ! found_newline ) str_append_char( self->line, '\n' ); /* signal new line, even empty one, to show end line in list */ self->line_nr++; call_new_line_cb( self->filename, self->line_nr, str_data(self->line) ); /* check for end of file even if EOF found, we need to return any chars in line first */ if ( str_len(self->line) > 0 ) { return str_data(self->line); } else { /* EOF - close file */ myfclose( self->file ); /* close input */ self->file = NULL; // call_new_line_cb( NULL, 0, NULL ); return NULL; /* EOF */ } }
Window* newWindow(unsigned int width, unsigned int height, unsigned char flags, unsigned int pid) { static int next_handle = 1; Window *new_window, *temp_window; unsigned int i, bufsz; if (!(new_window = (Window*)malloc(sizeof(window)))) { printf("Coudln't allocate a new window structure"); return 0; } new_window->active = 1; new_window->pid = pid; new_window->flags = flags; new_window->x = 0; new_window->y = 0; new_window->w = width; new_window->h = height; new_window->title = (unsigned char*)0; new_window->frame_needs_redraw = 1; //Create a drawing context for the new window if (!(new_window->context = newBitmap(new_window->w, new_window->h))) { free((void*)new_window); printf("Couldn't allocate bitmap area for new window"); return (window*)0; } bufsz = new_window->w * new_window->h; //Clear new window to white for (i = 0; i < bufsz; i++) new_window->context->data[i] = RGB(255, 255, 255); new_window->handle = next_handle++; if (mouse_window) List_pop(window_list, (void*)mouse_window); //De-activate the old active window if (temp_window = (window*)List_get_at(window_list, window_list->count - (mouse_window ? 2 : 1))) { temp_window->active = 0; } if (!List_add(window_list, (void*)new_window)){ freeBitmap(new_window->context); free((void*)new_window); //re-activate the old active window if (temp_window) temp_window->active = 1; return (window*)0; } //Give the new window its initial decoration if (!(new_window->flags & WIN_UNDECORATED)) drawFrame(new_window); drawWindow(new_window, 0); //Update the titlebar on the old active window if (temp_window) drawTitlebar(temp_window, 1); if (mouse_window) { List_add(window_list, mouse_window); drawWindow(mouse_window, 0); } return new_window; }
int main(void) { List_T L = NULL; Bootstrap(); // Need to initialize library printf("============> Start List Tests\n\n"); printf("=> Test0: create\n"); { L = List_new(); assert(L); List_free(&L); } printf("=> Test0: OK\n\n"); printf("=> Test1: List_push() & List_length()\n"); { L = List_new(); List_push(L, "1"); List_push(L, "2"); List_push(L, "3"); List_push(L, "4"); List_push(L, "5"); List_push(L, "6"); List_push(L, "7"); List_push(L, "8"); List_push(L, "9"); List_push(L, "10"); List_push(L, "11"); List_push(L, "12"); List_push(L, "13"); List_push(L, "14"); List_push(L, "15"); assert(Str_isEqual(L->tail->e, "1")); assert(Str_isEqual(L->head->e, "15")); assert(List_length(L) == 15); } printf("=> Test1: OK\n\n"); printf("=> Test2: List_pop()\n"); { int i= 0; list_t p; while (List_pop(L)) ; assert(List_length(L) == 0); // Ensure that nodes are retained in the freelist for (p= L->freelist; p; p= p->next) i++; assert(i == 15); List_free(&L); } printf("=> Test2: OK\n\n"); printf("=> Test3: List_append()\n"); { L = List_new(); List_append(L, "1"); List_append(L, "2"); List_append(L, "3"); List_append(L, "4"); List_append(L, "5"); List_append(L, "6"); List_append(L, "7"); List_append(L, "8"); List_append(L, "9"); List_append(L, "10"); List_append(L, "11"); List_append(L, "12"); List_append(L, "13"); List_append(L, "14"); List_append(L, "15"); assert(Str_isEqual(L->tail->e, "15")); assert(Str_isEqual(L->head->e, "1")); assert(List_length(L) == 15); } printf("=> Test3: OK\n\n"); printf("=> Test4: List_cat()\n"); { List_T t= List_new(); List_append(t, "a"); List_append(t, "b"); List_append(t, "c"); List_append(t, "d"); List_cat(L, t); assert(Str_isEqual(L->tail->e, "d")); assert(Str_isEqual(L->head->e, "1")); assert(List_length(L) == 19); } printf("=> Test4: OK\n\n"); printf("=> Test5: List_reverse()\n"); { list_t p; List_T l= List_new(); List_append(l, "a"); List_append(l, "b"); List_append(l, "c"); List_append(l, "d"); printf("\tList before reverse: "); for (p= l->head; p; p= p->next) printf("%s%s", (char*)p->e, p->next?"->":"\n"); assert(Str_isEqual(l->head->e, "a")); assert(Str_isEqual(l->tail->e, "d")); List_reverse(l); printf("\tList after reverse: "); for (p= l->head; p; p= p->next) printf("%s%s", (char*)p->e, p->next?"->":"\n"); assert(Str_isEqual(l->head->e, "d")); assert(Str_isEqual(l->tail->e, "a")); List_free(&l); } printf("=> Test5: OK\n\n"); printf("=> Test6: List_map()\n"); { int i = 0; List_map(L, apply, &i); assert(i == 19); } printf("=> Test6: OK\n\n"); printf("=> Test7: List_clear()\n"); { List_clear(L); assert(List_length(L) == 0); assert(L->freelist); } printf("=> Test7: OK\n\n"); List_free(&L); printf("=> Test8: List malloc\n"); { L = List_new(); List_push(L, "1"); List_push(L, "2"); List_push(L, "3"); List_push(L, "4"); List_push(L, "5"); List_push(L, "6"); List_push(L, "7"); List_push(L, "8"); List_push(L, "9"); List_push(L, "10"); List_push(L, "11"); List_push(L, "12"); List_push(L, "13"); List_push(L, "14"); List_push(L, "15"); assert(Str_isEqual(L->tail->e, "1")); assert(Str_isEqual(L->head->e, "15")); assert(List_length(L) == 15); List_clear(L); List_append(L, "1"); List_append(L, "2"); List_append(L, "3"); List_append(L, "4"); List_append(L, "5"); List_append(L, "6"); List_append(L, "7"); List_append(L, "8"); List_append(L, "9"); List_append(L, "10"); List_append(L, "11"); List_append(L, "12"); List_append(L, "13"); List_append(L, "14"); List_append(L, "15"); assert(Str_isEqual(L->tail->e, "15")); assert(Str_isEqual(L->head->e, "1")); assert(List_length(L) == 15); List_free(&L); } printf("=> Test8: OK\n\n"); printf("=> Test9: List remove\n"); { char *one = "1"; char *two = "2"; L = List_new(); printf("\tRemove from empty list.. "); assert(List_remove(L, "1") == NULL); printf("OK\n"); List_push(L, one); printf("\tRemove from 1 element list.. "); assert(List_remove(L, one) == one); assert(List_length(L) == 0); printf("OK\n"); List_push(L, one); List_push(L, two); printf("\tRemove last from list.. "); assert(List_remove(L, two) == two); assert(List_length(L) == 1); printf("OK\n"); List_append(L, two); List_append(L, two); List_append(L, two); List_append(L, "5"); printf("\tRemove first occurrence.. "); assert(List_remove(L, two) == two); assert(List_length(L) == 4); printf("OK\n"); List_free(&L); } printf("=> Test9: OK\n\n"); printf("=> Test10: check pointers\n"); { L = List_new(); printf("\tCheck pop.. "); List_push(L, "1"); List_push(L, "2"); List_pop(L); List_pop(L); List_push(L, "1"); assert(L->head == L->tail); List_pop(L); List_append(L, "1"); assert(L->head == L->tail); printf("OK\n"); printf("\tCheck remove.. "); List_push(L, "1"); List_append(L, "2"); List_remove(L, "2"); List_remove(L, "1"); assert(L->head == L->tail); printf("OK\n"); List_free(&L); } printf("=> Test10: OK\n\n"); printf("=> Test11: List_toArray()\n"); { List_T l = List_new(); List_append(l, "a"); List_append(l, "b"); List_append(l, "c"); List_append(l, "d"); char **array = (char**)List_toArray(l); assert(Str_isEqual(array[0], "a")); assert(Str_isEqual(array[1], "b")); assert(Str_isEqual(array[2], "c")); assert(Str_isEqual(array[3], "d")); assert(array[4] == NULL); FREE(array); List_free(&l); } printf("=> Test11: OK\n\n"); printf("============> List Tests: OK\n\n"); return 0; }
int IoAudioMixer_mixOneChunk(IoAudioMixer *self, IoObject *locals, IoMessage *m) { UArray *mixBuffer = DATA(self)->mixBuffer; List *sounds = DATA(self)->sounds; List *soundsToRemove = DATA(self)->soundsToRemove; AudioEvent *e = List_top(DATA(self)->events); List *activeEvents = DATA(self)->activeEvents; int frame; /*int samplesPerBuffer = DATA(self)->samplesPerBuffer;*/ int samplesPerBuffer = UArray_size(DATA(self)->mixBuffer) / (sizeof(float) * 2); UArray_setAllBytesTo_(mixBuffer, 0); while ( e && (!e->ioTriggerSound)) { List_append_(DATA(self)->activeEvents, List_pop(DATA(self)->events)); e = List_top(DATA(self)->events); } if (List_size(activeEvents)) IoAudioMixer_processActiveEvents(self); if (List_size(soundsToRemove)) IoAudioMixer_processSoundRemovals(self); for (frame = 0; frame < samplesPerBuffer; frame ++) { int index = frame * 2; int i; float *ol = UArray_floatPointerAt_(mixBuffer, index); float *or = UArray_floatPointerAt_(mixBuffer, index+1); for (i = 0; i < List_size(sounds); i++) { IoSound *ioSound = List_at_(sounds, i); Sound *sound = IoSound_rawSound(ioSound); float left, right; char done = Sound_nextFloat(sound, &left, &right); if (done && !Sound_isLooping(sound)) { List_append_(soundsToRemove, ioSound); continue; } (*ol) += left; (*or) += right; while (e && ((!e->ioTriggerSound) || ((e->ioTriggerSound == ioSound) && (e->sample == Sound_position(sound)))) ) { List_append_(DATA(self)->activeEvents, List_pop(DATA(self)->events)); e = List_top(DATA(self)->events); } } (*ol) *= DATA(self)->scale; (*or) *= DATA(self)->scale; if (List_size(activeEvents)) IoAudioMixer_processActiveEvents(self); if (List_size(soundsToRemove)) IoAudioMixer_processSoundRemovals(self); } /* adjust pitch and tempo */ { //double t1 = ((double)clock())/((double)CLOCKS_PER_SEC); //double t2; int receivedSamples = 1; SoundTouch_putSamples(DATA(self)->soundTouch, (float *)UArray_bytes(mixBuffer), samplesPerBuffer); //printf("put %i\n", samplesPerBuffer); //while (receivedSamples) { UArray_setSize_(DATA(self)->buffer, 10000*8); receivedSamples = SoundTouch_receiveSamples(DATA(self)->soundTouch, (float *)UArray_bytes(DATA(self)->buffer), UArray_size(DATA(self)->buffer) / (sizeof(float) * 2)); UArray_setSize_(DATA(self)->buffer, receivedSamples * (sizeof(float) * 2)); //printf("received %i\n", receivedSamples); if (receivedSamples) { if (receivedSamples < 5000) { #ifdef DEBUG printf("non-blocking write\n"); #endif IoMessage_locals_performOn_(DATA(self)->nonBlockingWriteMessage, self, DATA(self)->ioAudioDevice); } else { IoMessage_locals_performOn_(DATA(self)->writeMessage, self, DATA(self)->ioAudioDevice); } } #ifdef DEBUG t2 = ((double)clock())/((double)CLOCKS_PER_SEC); printf("tempo: %1.1f %i -> %i in %0.2f sec\n", DATA(self)->tempo, samplesPerBuffer, receivedSamples, (float)(t2 - t1)); #endif } //printf("\n"); return receivedSamples; } /* need to change this to be dynamic, so we can easily record the output */ /*IoAudioDevice_justWrite(DATA(self)->ioAudioDevice, locals, m, buffer);*/ return UArray_size(DATA(self)->buffer) / 8; }
/* Free each string in a list of strings */ static void freeStrings(List_T l) { while (List_length(l) > 0) { char *s = List_pop(l); FREE(s); } }