static int addcleanup_convert(void *ptr, PyObject **freelist, int (*destr)(PyObject*,void*)) { PyObject *cobj; if (!*freelist) { *freelist = PyList_New(0); if (!*freelist) { destr(NULL, ptr); return -1; } } cobj = PyCapsule_New(ptr, GETARGS_CAPSULE_NAME_CLEANUP_CONVERT, cleanup_convert); if (!cobj) { destr(NULL, ptr); return -1; } if (PyCapsule_SetContext(cobj, destr) == -1) { /* This really should not happen. */ Py_FatalError("capsule refused setting of context."); } if (PyList_Append(*freelist, cobj)) { Py_DECREF(cobj); /* This will also call destr. */ return -1; } Py_DECREF(cobj); return 0; }
// --- int sign_check_file_res( const char* file_name, unsigned long not_inst, int not_res_id ) { char* buffer = 0; HANDLE file = INVALID_HANDLE_VALUE; BOOL done; int read; int file_len; file = CreateFile( file_name, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0 ); if ( INVALID_HANDLE_VALUE == file ) return destr( SIGN_CANT_READ, file, buffer ); file_len = GetFileSize( file, 0 ); buffer = ptrAMemAlloc( file_len ); if ( !buffer ) return destr( SIGN_NOT_ENOUGH_MEMORY, file, buffer ); done = ReadFile( file, buffer, file_len, &read, 0 ) && read == file_len; if ( !done ) return destr( SIGN_CANT_READ, file, buffer ); return destr( sign_check_buffer_res(buffer,file_len,0,not_inst,not_res_id), file, buffer ); }
void __pthread_destroy_specifics() { pthread_descr self = thread_self(); int i, j, round, found_nonzero; destr_function destr; void * data; for (round = 0, found_nonzero = 1; found_nonzero && round < PTHREAD_DESTRUCTOR_ITERATIONS; round++) { found_nonzero = 0; for (i = 0; i < PTHREAD_KEY_1STLEVEL_SIZE; i++) if (THREAD_GETMEM_NC(self, p_specific[i]) != NULL) for (j = 0; j < PTHREAD_KEY_2NDLEVEL_SIZE; j++) { destr = pthread_keys[i * PTHREAD_KEY_2NDLEVEL_SIZE + j].destr; data = THREAD_GETMEM_NC(self, p_specific[i])[j]; if (destr != NULL && data != NULL) { THREAD_GETMEM_NC(self, p_specific[i])[j] = NULL; destr(data); found_nonzero = 1; } } } __pthread_lock(THREAD_GETMEM(self, p_lock), self); for (i = 0; i < PTHREAD_KEY_1STLEVEL_SIZE; i++) { if (THREAD_GETMEM_NC(self, p_specific[i]) != NULL) { free(THREAD_GETMEM_NC(self, p_specific[i])); THREAD_SETMEM_NC(self, p_specific[i], NULL); } } __pthread_unlock(THREAD_GETMEM(self, p_lock)); }
static void cleanup_convert(PyObject *self) { typedef int (*destr_t)(PyObject *, void *); destr_t destr = (destr_t)PyCapsule_GetContext(self); void *ptr = PyCapsule_GetPointer(self, GETARGS_CAPSULE_NAME_CLEANUP_CONVERT); if (ptr && destr) destr(NULL, ptr); }
~BackParaCandidates() { CALL("destructor ~BackParaCandidates()"); if (BK::DestructionMode::isThorough()) { SkList::Destruction destr(_skList); LitRedexPair* lrlist; while (destr.next(lrlist)) LitRedexPair::destroy(lrlist); }; };
// --- int sign_load_pub_key_file( const char* pub_key_file, void* pub_key ) { HANDLE file = INVALID_HANDLE_VALUE; MY_TRY { file = CreateFile( pub_key_file, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0 ); if ( INVALID_HANDLE_VALUE != file ) { DWORD done; DWORD size = GetFileSize( file, 0 ); if ( size <= (PUBKEY_LEN_MIN-CT_N_LEN_SIGN) || PUBKEY_LEN_MAX < size ) return destr( SIGN_BAD_OPEN_KEY, file ); if ( ReadFile(file,pub_key,size,&done,0) && size == done ) return destr( SIGN_OK, file ); else return destr( SIGN_CANT_READ, file ); } else return destr( SIGN_CANT_READ, file ); } MY_EXCEPT }
static void clear_rec(struct kdnode *node, void (*destr)(void*)) { if(!node) return; clear_rec(node->left, destr); clear_rec(node->right, destr); if(destr) { destr(node->data); } free(node->pos); free(node); }
static void clear_rec(struct kdnode *node, void (*destr)(void*)) { if(!node) return; clear_rec(node->left, destr); clear_rec(node->right, destr); if(destr) { destr(node->data); } delete[] node->pos; delete node; }
static int addcleanup(void *ptr, PyObject **freelist, void (*destr)(void *)) { PyObject *cobj; if (!*freelist) { *freelist = PyList_New(0); if (!*freelist) { destr(ptr); return -1; } } cobj = PyCObject_FromVoidPtr(ptr, destr); if (!cobj) { destr(ptr); return -1; } if (PyList_Append(*freelist, cobj)) { Py_DECREF(cobj); return -1; } Py_DECREF(cobj); return 0; }
const UnitCollection& UnitCollection::operator=( const UnitCollection &uc ) { #ifdef _DEBUG printf( "warning could cause problems with concurrent lists. Make sure no one is traversing gotten list" ); #endif destr(); init(); un_iter ui = createIterator(); const UnitListNode *n = uc.u; while (n) { if (n->unit) { ui.postinsert( n->unit ); ++ui; } n = n->next; } return uc; }