void free_(void *p) { t_chunk *c; t_mem *m; if (!p) return ; g_malloc_memory = g_malloc_memory ? GMEM : array_new(sizeof(t_chunk), 0); while ((c = (t_chunk *)array_next(g_malloc_memory))) { if ((char *)p < c->start || (char *)p > c->start + c->size) continue ; while ((m = (t_mem *)array_next(c->mem))) { if ((char *)p < m->start || (char *)p > m->start + m->size) continue ; array_remove(c->mem, c->mem->it - 1); c->mem->it = 0; g_malloc_memory->it = 0; if (c->mem->size == 0) array_remove(g_malloc_memory, g_malloc_memory->it); return ; } c->mem->it = 0; } g_malloc_memory->it = 0; free__(p); }
// ------------------------------------------------------------------------- // Part of the simple stack, returns the topmost item from the stack or // NULL if the stack is empty. It also returns NULL if the stack itself // is NULL. // // Precondition: The stack's top element is either NULL or a properly // initialised stackObject. // ------------------------------------------------------------------------- void* Pop(Stack* stack) { stackObject* popee; void* value; // Throw away invalid parameter. if (NULL == stack) { fprintf(stderr, "nedit: Internal error: pop() called with NULL stack.\n"); return NULL; } // Return NULL if Stack is empty. if (NULL == stack->top) { return NULL; } // Remove top entry in the stack. popee = stack->top; stack->top = popee->next; (stack->size)--; value = popee->value; free__((char*) popee); return value; }
void* realloc__(void* p, size_t size, const char* file, int line) { if (NULL != p && 0 == size) { free__(p); return NULL; } if (NULL == p) return malloc__(size, file, line); #ifdef _PALM_OS if (errNone == MemPtrResize(p, size)) return p; void* np = malloc__(size, file, line); if (NULL == np) return NULL; MemMove(np, p, MemPtrSize(p)); free__(p); #elif defined(_WIN32_WCE) void* np = realloc(p, size); #ifndef NDEBUG if (np != p) { logAllocation(p, 0, true, __FILE__, __LINE__); if (NULL != np) logAllocation(np, size, false, __FILE__, __LINE__); } #endif #endif return np; }
/* ** Copy the primary selection to the clipboard */ void CopyToClipboard(Ne_Text_Editor* textD, double time) { long itemID = 0; /* Get the selected text, if there's no selection, do nothing */ char* text = BufGetSelectionText(textD->buffer); if (*text == '\0') { free__(text); return; } /* If the string contained ascii-nul characters, something else was substituted in the buffer. Put the nulls back */ int length = strlen(text); BufUnsubstituteNullChars(text, textD->buffer); // Copy to the clipboard Fl::copy(text, length, 1); }