/* {{{ _mysqlnd_perealloc */ void * _mysqlnd_perealloc(void *ptr, size_t new_size, zend_bool persistent MYSQLND_MEM_D) { void *ret; zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics); size_t old_size = collect_memory_statistics && ptr? *(size_t *) (((char*)ptr) - sizeof(size_t)) : 0; #if PHP_DEBUG long * threshold = persistent? &MYSQLND_G(debug_realloc_fail_threshold):&MYSQLND_G(debug_erealloc_fail_threshold); #endif DBG_ENTER(mysqlnd_perealloc_name); DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_filename, PHP_DIR_SEPARATOR) + 1, __zend_lineno); DBG_INF_FMT("ptr=%p old_size=%lu new_size=%lu persistent=%u", ptr, old_size, new_size, persistent); #if PHP_DEBUG /* -1 is also "true" */ if (*threshold) { #endif ret = perealloc(REAL_PTR(ptr), REAL_SIZE(new_size), persistent); #if PHP_DEBUG --*threshold; } else if (*threshold == 0) { ret = NULL; } #endif DBG_INF_FMT("new_ptr=%p", (char*)ret); if (ret && collect_memory_statistics) { enum mysqlnd_collected_stats s1 = persistent? STAT_MEM_REALLOC_COUNT:STAT_MEM_EREALLOC_COUNT; enum mysqlnd_collected_stats s2 = persistent? STAT_MEM_REALLOC_AMOUNT:STAT_MEM_EREALLOC_AMOUNT; *(size_t *) ret = new_size; MYSQLND_INC_GLOBAL_STATISTIC_W_VALUE2(s1, 1, s2, new_size); } DBG_RETURN(FAKE_PTR(ret)); }
/* {{{ _mysqlnd_emalloc */ void * _mysqlnd_emalloc(size_t size MYSQLND_MEM_D) { void *ret; zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics); #if PHP_DEBUG long * threshold = &MYSQLND_G(debug_emalloc_fail_threshold); #endif DBG_ENTER(mysqlnd_emalloc_name); DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_filename, PHP_DIR_SEPARATOR) + 1, __zend_lineno); #if PHP_DEBUG /* -1 is also "true" */ if (*threshold) { #endif ret = emalloc(REAL_SIZE(size)); #if PHP_DEBUG --*threshold; } else if (*threshold == 0) { ret = NULL; } #endif DBG_INF_FMT("size=%lu ptr=%p", size, ret); if (ret && collect_memory_statistics) { *(size_t *) ret = size; MYSQLND_INC_GLOBAL_STATISTIC_W_VALUE2(STAT_MEM_EMALLOC_COUNT, 1, STAT_MEM_EMALLOC_AMOUNT, size); } DBG_RETURN(FAKE_PTR(ret)); }
/* {{{ _mysqlnd_pecalloc */ void * _mysqlnd_pecalloc(unsigned int nmemb, size_t size, zend_bool persistent MYSQLND_MEM_D) { void *ret; zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics); #if PHP_DEBUG long * threshold = persistent? &MYSQLND_G(debug_calloc_fail_threshold):&MYSQLND_G(debug_ecalloc_fail_threshold); #endif DBG_ENTER(mysqlnd_pecalloc_name); DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_filename, PHP_DIR_SEPARATOR) + 1, __zend_lineno); #if PHP_DEBUG /* -1 is also "true" */ if (*threshold) { #endif ret = pecalloc(nmemb, REAL_SIZE(size), persistent); #if PHP_DEBUG --*threshold; } else if (*threshold == 0) { ret = NULL; } #endif DBG_INF_FMT("size=%lu ptr=%p", size, ret); if (ret && collect_memory_statistics) { enum mysqlnd_collected_stats s1 = persistent? STAT_MEM_CALLOC_COUNT:STAT_MEM_ECALLOC_COUNT; enum mysqlnd_collected_stats s2 = persistent? STAT_MEM_CALLOC_AMOUNT:STAT_MEM_ECALLOC_AMOUNT; *(size_t *) ret = size; MYSQLND_INC_GLOBAL_STATISTIC_W_VALUE2(s1, 1, s2, size); } DBG_RETURN(FAKE_PTR(ret)); }
/** ** malloc function **/ static void * internal_malloc(size_t size) { SM_MALLOC_CHUNK *c, *nc; #ifdef MALLOC_ZERO_RETURNS_NULL if (size == 0) { return(NULL); } #endif /* allocate at least MALLOC_MIN_CHUNK bytes and multiple of sizeof (double) */ size = ROUNDUP(size, sizeof(double)); if (size < MALLOC_MIN_CHUNK) { size = MALLOC_MIN_CHUNK; } /* look for a free chunk of size > size */ EVERY_FREE(c->length >= size); if (c != NULL) { /* found a chunk */ assert(c->signature == SIGNATURE); if (c->length > size + REAL_SIZE(MALLOC_MIN_CHUNK)) { /* split it */ nc = (SM_MALLOC_CHUNK *)((char *)c + c->length - size); nc->length = size; c->length -= REAL_SIZE(size); nc->next = MALLOC_MAGIC; nc->signature = SIGNATURE; return((void *)(nc+1)); } else { /* supress it from free list */ remove_chunk(&smMemFreeList, c); c->next = MALLOC_MAGIC; return((void *)(c+1)); } } else { errnoSet(ENOMEM); return NULL; } } /* malloc */
static void structseq_dealloc(PyStructSequence *obj) { Py_ssize_t i, size; size = REAL_SIZE(obj); for (i = 0; i < size; ++i) { Py_XDECREF(obj->ob_item[i]); } PyObject_Del(obj); }
/* {{{ _mysqlnd_pemalloc */ void * _mysqlnd_pemalloc(size_t size, zend_bool persistent MYSQLND_MEM_D) { void *ret; zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics); #if PHP_DEBUG long * threshold = persistent? &MYSQLND_G(debug_malloc_fail_threshold):&MYSQLND_G(debug_emalloc_fail_threshold); #endif TRACE_ALLOC_ENTER(mysqlnd_pemalloc_name); #if PHP_DEBUG { char * fn = strrchr(__zend_orig_filename, PHP_DIR_SEPARATOR); TRACE_ALLOC_INF_FMT("file=%-15s line=%4d", fn? fn + 1:__zend_orig_filename, __zend_orig_lineno); } #endif #if PHP_DEBUG /* -1 is also "true" */ if (*threshold) { #endif ret = (persistent) ? __zend_malloc(REAL_SIZE(size)) : _emalloc(REAL_SIZE(size) ZEND_FILE_LINE_CC ZEND_FILE_LINE_ORIG_RELAY_CC); #if PHP_DEBUG --*threshold; } else if (*threshold == 0) { ret = NULL; } #endif TRACE_ALLOC_INF_FMT("size=%lu ptr=%p persistent=%u", size, ret, persistent); if (ret && collect_memory_statistics) { enum mysqlnd_collected_stats s1 = persistent? STAT_MEM_MALLOC_COUNT:STAT_MEM_EMALLOC_COUNT; enum mysqlnd_collected_stats s2 = persistent? STAT_MEM_MALLOC_AMOUNT:STAT_MEM_EMALLOC_AMOUNT; *(size_t *) ret = size; MYSQLND_INC_GLOBAL_STATISTIC_W_VALUE2(s1, 1, s2, size); } TRACE_ALLOC_RETURN(FAKE_PTR(ret)); }
/** ** Liberation d'une zone **/ STATUS smMemFree(void *ptr) { SM_MALLOC_CHUNK *oc, *c; LOGDBG(("comLib:smMemLib: free 0x%x\n", (unsigned)ptr)); if (ptr == NULL) { LOGDBG(("comLib:smMemLib: free(NULL)\n")); return ERROR; } /* get a pointer to the header */ oc = (SM_MALLOC_CHUNK *)ptr - 1; /* test for allocated bloc */ if (oc->next != MALLOC_MAGIC) { /* what to do ? */ LOGDBG(("comLib:smMemLib: free(something not returned by malloc)\n")); return ERROR; } /* insert free chunk in the free list */ insert_after(&smMemFreeList, oc); /* test if can merge with preceding chunk */ c = smObjGlobalToLocal(oc->prev); if (c != NULL && oc == (SM_MALLOC_CHUNK *)((char *)c + REAL_SIZE(c->length))) { /* merge */ c->length += REAL_SIZE(oc->length); remove_chunk(&smMemFreeList, oc); oc = c; } /* test if can merge with following chunk */ c = smObjGlobalToLocal(oc->next); if (c == (SM_MALLOC_CHUNK *)((char *)oc + REAL_SIZE(oc->length))) { /* merge (=> oc->next != NULL) */ oc->length += REAL_SIZE(c->length); remove_chunk(&smMemFreeList, c); } return OK; }
/* * Create a string copy (mempool version). */ LPTSTR CopyStringPool( POOL pMemPool, LPCTSTR pszString ) { LPTSTR pszCopy; /* * Allocate copy. */ size_t len = REAL_SIZE( _tcslen( pszString ) + 1 ); if (( pszCopy = AllocPooled( pMemPool, len )) != NULL ) /* * Copy the string. */ _tcscpy_s( pszCopy, len, pszString ); return pszCopy; }
static PyObject * structseq_reduce(PyStructSequence* self) { PyObject* tup; PyObject* dict; PyObject* result; Py_ssize_t n_fields, n_visible_fields, n_unnamed_fields; int i; n_fields = REAL_SIZE(self); n_visible_fields = VISIBLE_SIZE(self); n_unnamed_fields = UNNAMED_FIELDS(self); tup = PyTuple_New(n_visible_fields); if (!tup) { return NULL; } dict = PyDict_New(); if (!dict) { Py_DECREF(tup); return NULL; } for (i = 0; i < n_visible_fields; i++) { Py_INCREF(self->ob_item[i]); PyTuple_SET_ITEM(tup, i, self->ob_item[i]); } for (; i < n_fields; i++) { char *n = Py_TYPE(self)->tp_members[i-n_unnamed_fields].name; PyDict_SetItemString(dict, n, self->ob_item[i]); } result = Py_BuildValue("(O(OO))", Py_TYPE(self), tup, dict); Py_DECREF(tup); Py_DECREF(dict); return result; }
/* {{{ _mysqlnd_erealloc */ static void * _mysqlnd_erealloc(void *ptr, size_t new_size MYSQLND_MEM_D) { void *ret; zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics); size_t old_size = collect_memory_statistics && ptr? *(size_t *) (((char*)ptr) - sizeof(size_t)) : 0; #if PHP_DEBUG zend_long * threshold = &MYSQLND_G(debug_erealloc_fail_threshold); #endif TRACE_ALLOC_ENTER(mysqlnd_erealloc_name); #if PHP_DEBUG { char * fn = strrchr(__zend_filename, PHP_DIR_SEPARATOR); TRACE_ALLOC_INF_FMT("file=%-15s line=%4d", fn? fn + 1:__zend_filename, __zend_lineno); } #endif TRACE_ALLOC_INF_FMT("ptr=%p old_size=%lu, new_size=%lu", ptr, old_size, new_size); #if PHP_DEBUG /* -1 is also "true" */ if (*threshold) { #endif ret = erealloc_rel(REAL_PTR(ptr), REAL_SIZE(new_size)); #if PHP_DEBUG --*threshold; } else if (*threshold == 0) { ret = NULL; } #endif TRACE_ALLOC_INF_FMT("new_ptr=%p", (char*)ret); if (ret && collect_memory_statistics) { *(size_t *) ret = new_size; MYSQLND_INC_GLOBAL_STATISTIC_W_VALUE2(STAT_MEM_EREALLOC_COUNT, 1, STAT_MEM_EREALLOC_AMOUNT, new_size); } TRACE_ALLOC_RETURN(FAKE_PTR(ret)); }
/* {{{ _mysqlnd_ecalloc */ static void * _mysqlnd_ecalloc(unsigned int nmemb, size_t size MYSQLND_MEM_D) { void *ret; zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics); #if PHP_DEBUG zend_long * threshold = &MYSQLND_G(debug_ecalloc_fail_threshold); #endif TRACE_ALLOC_ENTER(mysqlnd_ecalloc_name); #if PHP_DEBUG { char * fn = strrchr(__zend_filename, PHP_DIR_SEPARATOR); TRACE_ALLOC_INF_FMT("file=%-15s line=%4d", fn? fn + 1:__zend_filename, __zend_lineno); } #endif TRACE_ALLOC_INF_FMT("before: %lu", zend_memory_usage(FALSE)); #if PHP_DEBUG /* -1 is also "true" */ if (*threshold) { #endif ret = ecalloc_rel(nmemb, REAL_SIZE(size)); #if PHP_DEBUG --*threshold; } else if (*threshold == 0) { ret = NULL; } #endif TRACE_ALLOC_INF_FMT("after : %lu", zend_memory_usage(FALSE)); TRACE_ALLOC_INF_FMT("size=%lu ptr=%p", size, ret); if (ret && collect_memory_statistics) { *(size_t *) ret = size; MYSQLND_INC_GLOBAL_STATISTIC_W_VALUE2(STAT_MEM_ECALLOC_COUNT, 1, STAT_MEM_ECALLOC_AMOUNT, size); } TRACE_ALLOC_RETURN(FAKE_PTR(ret)); }
BOOL CopyAppend( LPCLASSDATA lpcd ) { HGLOBAL hCombination, hClip; LPTSTR pszSelection, pszClip, pszCombination; /* * Any text? */ if ( HasMark( lpcd )) { /* * Open the clipboard. */ if ( OpenClipboard( lpcd->hWnd )) { /* * Get the clip. */ if (( hClip = GetClipboardData( CF_TEXT )) != NULL ) { /* * Lock it... */ if (( pszClip = GlobalLock( hClip )) != NULL ) { /* * Get the selection. */ if (( pszSelection = GetText( lpcd, &lpcd->ptSelStart, &lpcd->ptSelEnd )) != NULL ) { /* * Allocate combination... */ size_t len = REAL_SIZE( _tcslen( pszClip ) + _tcslen( pszSelection ) + 1 ); if (( hCombination = GlobalAlloc( GMEM_MOVEABLE | GMEM_DDESHARE, len )) != NULL ) { /* * Lock the memory.. */ if (( pszCombination = GlobalLock( hCombination )) != NULL ) { /* * Copy the texts. */ _tcscpy_s( pszCombination, len, pszClip ); _tcscat_s( pszCombination, len, pszSelection ); /* * Unlock the memory. */ GlobalUnlock( hCombination ); GlobalUnlock( hClip ); /* * Free the selection. */ ArrayFreeMem(lpcd->lpUndoRedo, pszSelection ); /* * Empty the clipboard and * set the combination. */ EmptyClipboard(); /* * Unlock the data. */ GlobalUnlock( hCombination ); /* * Put the data on the clipboard. */ if ( SetClipboardData( CF_TEXT, hCombination ) == hCombination ) return TRUE; } GlobalFree( hCombination ); } ArrayFreeMem( lpcd->lpUndoRedo, pszSelection ); } GlobalUnlock( hClip ); } } else { CloseClipboard(); Copy( lpcd ); return TRUE; } CloseClipboard(); } } return FALSE; }
/* * Obtain the hyperlink located at the * mouse position. If there is no hyperlink * at the mouse position return NULL. */ TCHAR *GetHyperlink( LPCLASSDATA lpcd ) { POINT ptStart, ptEnd, ptMousePos; /* * Are we parsing hyperlinks? */ if ( Parser->bParseHyperLinks ) { /* * Get mouse position and convert * to client coordinates. */ GetCursorPos( &ptMousePos ); ScreenToClient( lpcd->hWnd, &ptMousePos ); /* * Skip selection margin. */ ptMousePos.x -= ( GetMarginWidth( lpcd ) + GetLineMarginWidth( lpcd )); /* * Convert the coordinates to the character * position. */ if ( MouseToCaret( lpcd, ptMousePos.x, ptMousePos.y, &ptMousePos )) { /* * Check if the character is located inside * a hyperlink. */ if ( CheckForHyperlink( lpcd, &ptMousePos, &ptStart, &ptEnd, FALSE )) { /* * Allocate memory to store the * hyperlink text. */ TCHAR *pszUrl = AllocPooled( lpcd->pMemPool, REAL_SIZE( ptEnd.x - ptStart.x + 2 )); if ( pszUrl ) { /* * Copy the hyperlink text into the * allocated buffer. */ LPLINE lpLine = ( LPLINE )ArrayGetAt( lpcd->lpLines, ptStart.y ); memcpy( pszUrl, &lpLine->pcText[ ptStart.x ], ptEnd.x - ptStart.x + 1 ); /* * 0-terminate to be on the safe side. */ pszUrl[ ptEnd.x - ptStart.x + 1 ] = 0; return pszUrl; } } } } /* * No hyperlink or memory failure... */ return NULL; }