void CHANNEL_return(int channel, CSOUND *sound) { CCHANNEL *ch = NULL; if (channel < 0 || channel >= _count) { if (sound) GB.Unref(POINTER(&sound)); GB.ReturnNull(); return; } CHECK_AUDIO(); ch = _cache[channel]; if (!ch) { ch = GB.New(CLASS_Channel, NULL, NULL); _cache[channel] = ch; ch->channel = channel; GB.Ref(ch); } //free_channel(ch); if (sound) { GB.Unref(POINTER(&ch->sound)); ch->sound = sound; } GB.ReturnObject(ch); }
void MatchGraph::UNPAIR (long oldbase, long oldmate) { long e, newbase, u; #ifdef DEBUG printf("Unpair oldbase, oldmate=%d %d\n",oldbase, oldmate); #endif UNLINK (oldbase); newbase = BMATE (oldmate); if (newbase != oldbase) { LINK [(int)oldbase] = -DUMMYEDGE; REMATCH (newbase, MATE[(int)oldbase]); if (f == LASTEDGE[1]) LINK[(int)secondmate] = -LASTEDGE[2]; else LINK[(int)secondmate] = -LASTEDGE[1]; } e = LINK[(int)oldmate]; u = BEND (OPPEDGE (e)); if (u == newbase) { POINTER (newbase, oldmate, e); return; } LINK[BMATE (u)] = -e; do { e = -LINK[(int)u]; v = BMATE (u); POINTER (u, v, -LINK[(int)v]); u = BEND (e); } while (u != newbase); e = OPPEDGE (e); POINTER (newbase, oldmate, e); }
static CMATRIX *_powi(CMATRIX *m, int n) { if (n == 1) return m; CMATRIX *m2 = _mul(m, m, FALSE); CMATRIX *r; if ((n & 1) == 0) { n /= 2; if (n > 1) r = _powi(m2, n); else r = m2; } else { n /= 2; if (n > 1) r = _powi(m2, n); else r = m2; m2 = _mul(r, m, FALSE); GB.Unref(POINTER(&r)); r = m2; } GB.Unref(POINTER(&m)); return r; }
/* common code to set up encrypt/decrypt */ static int desEncDecSetup( ITEM *iv, B_BLK_CIPHER_W_FEEDBACK_PARAMS *spec, B_ALGORITHM_OBJ *alg) { int brtn; spec->encryptionMethodName = POINTER("des"); spec->feedbackMethodName = POINTER("cbc"); spec->feedbackParams = POINTER(iv); spec->paddingParams = NULL_PTR; spec->encryptionParams = NULL_PTR; spec->paddingMethodName = POINTER("pad"); brtn = B_CreateAlgorithmObject(alg); if(brtn) { printf("***B_CreateAlgorithmObject error (%d)\n", brtn); return 1; } brtn = B_SetAlgorithmInfo(*alg, AI_FeedbackCipher, (POINTER)spec); if(brtn) { printf("***B_SetAlgorithmInfo error (%d)\n", brtn); return 1; } return 0; }
// update for input/output block/stream algorithms void BSafe::BSafeContext::update(void *inp, size_t &inSize, void *outp, size_t &outSize) { unsigned int length; opStarted = true; check(inOutUpdate(bsAlgorithm, POINTER(outp), &length, outSize, POINTER(inp), inSize, bsRandom, bsSurrender)); // always eat all input (inSize unchanged) outSize = length; // let the algorithm manager track I/O sizes, if needed trackUpdate(inSize, outSize); }
void TabCodeGen::COND_TRANSLATE() { out << " _widec = " << GET_KEY() << ";\n" " _klen = " << CL() << "[" << vCS() << "];\n" " _keys = " << ARR_OFF( CK(), "(" + CO() + "[" + vCS() + "]*2)" ) << ";\n" " if ( _klen > 0 ) {\n" " " << PTR_CONST() << WIDE_ALPH_TYPE() << PTR_CONST_END() << POINTER() << "_lower = _keys;\n" " " << PTR_CONST() << WIDE_ALPH_TYPE() << PTR_CONST_END() << POINTER() << "_mid;\n" " " << PTR_CONST() << WIDE_ALPH_TYPE() << PTR_CONST_END() << POINTER() << "_upper = _keys + (_klen<<1) - 2;\n" " while (1) {\n" " if ( _upper < _lower )\n" " break;\n" "\n" " _mid = _lower + (((_upper-_lower) >> 1) & ~1);\n" " if ( " << GET_WIDE_KEY() << " < _mid[0] )\n" " _upper = _mid - 2;\n" " else if ( " << GET_WIDE_KEY() << " > _mid[1] )\n" " _lower = _mid + 2;\n" " else {\n" " switch ( " << C() << "[" << CO() << "[" << vCS() << "]" " + ((_mid - _keys)>>1)] ) {\n"; for ( CondSpaceList::Iter csi = condSpaceList; csi.lte(); csi++ ) { GenCondSpace *condSpace = csi; out << " case " << condSpace->condSpaceId << ": {\n"; out << TABS(2) << "_widec = " << CAST(WIDE_ALPH_TYPE()) << "(" << KEY(condSpace->baseKey) << " + (" << GET_KEY() << " - " << KEY(keyOps->minKey) << "));\n"; for ( GenCondSet::Iter csi = condSpace->condSet; csi.lte(); csi++ ) { out << TABS(2) << "if ( "; CONDITION( out, *csi ); Size condValOffset = ((1 << csi.pos()) * keyOps->alphSize()); out << " ) _widec += " << condValOffset << ";\n"; } out << " break;\n" " }\n"; } SWITCH_DEFAULT(); out << " }\n" " break;\n" " }\n" " }\n" " }\n" "\n"; }
void CHANNEL_exit() { int i; CCHANNEL *ch; Mix_HaltChannel(-1); for (i = 0; i < MAX_CHANNEL; i++) { ch = _cache[i]; if (!ch) continue; free_channel(ch); GB.Unref(POINTER(&ch)); } if (_pipe_usage) { GB.Watch(_pipe[0], GB_WATCH_NONE, NULL, 0); _pipe_usage = 0; } close(_pipe[0]); close(_pipe[1]); }
int sem_post (sem_t *__sem) { psem_t *sem = sem2psem(__sem); ENTER(); POINTER(sem); if(_PSEM_INVALID(sem)) { DBG("Invalid sem_t provided, magic=%lx\n",((psem_t *)__sem)->magic); errno = EINVAL; return -1; } Forbid(); if((_SSEM(sem)->ss_QueueCount != -1) && ((_SSEM(sem)->ss_Owner == NULL) || (_SSEM(sem)->ss_Owner == FindTask(NULL)))) { ReleaseSemaphore(_SSEM(sem)); } if((sem->flags & SEMF_EXPUNGE) && (_SSEM(sem)->ss_QueueCount == -1)) { DBG("Delayed expunge will take action now...\n"); psem_destroy(sem); memset(__sem,_PSEM_ERASEDBIT,sizeof(*__sem)); } Permit(); LEAVE(); return 0; }
static void return_channel(int channel, CSOUND *sound) { CCHANNEL *ch = NULL; if (channel < 0 || channel >= channel_count) { if (sound) GB.Unref(POINTER(&sound)); GB.ReturnNull(); return; } ch = channel_cache[channel]; if (!ch) { ch = GB.New(GB.FindClass("Channel"), NULL, NULL); channel_cache[channel] = ch; ch->channel = channel; GB.Ref(ch); } free_channel(ch); if (sound) ch->sound = sound; GB.ReturnObject(ch); }
gpointer gMalloc (gsize n_bytes) { gpointer *ptr; GB.Alloc((void**)POINTER(&ptr), n_bytes); return ptr; }
void BSafe::BSafeContext::setAlgorithm( B_INFO_TYPE bAlgType, const void *info) { B_DestroyAlgorithmObject(&bsAlgorithm); // clear any old BSafe algorithm check(B_CreateAlgorithmObject(&bsAlgorithm)); check(B_SetAlgorithmInfo(bsAlgorithm, bAlgType, POINTER(info))); }
void ternary_sift_down(void *base, size_t start, size_t size, size_t max_index, compare_fun3 compare, void *arg) { size_t root = start; while (TRUE) { size_t left_child = LEFT(root); if (left_child > max_index) { break; } void *root_ptr = POINTER(base, root, size); size_t swap = root; void *swap_ptr = root_ptr; void *left_child_ptr = POINTER(base, left_child, size); if (compare(swap_ptr, left_child_ptr, arg) < 0) { swap = left_child; swap_ptr = left_child_ptr; } size_t middle_child = MIDDLE(root); size_t right_child = RIGHT(root); if (middle_child <= max_index) { void *middle_child_ptr = POINTER(base, middle_child, size); if (compare(swap_ptr, middle_child_ptr, arg) < 0) { swap = middle_child; swap_ptr = middle_child_ptr; } if (right_child <= max_index) { void *right_child_ptr = POINTER(base, right_child, size); if (compare(swap_ptr, right_child_ptr, arg) < 0) { swap = right_child; swap_ptr = right_child_ptr; } } } if (swap != root) { swap_elements(root_ptr, swap_ptr, size); root = swap; root_ptr = swap_ptr; } else { return; } } }
static VALUE ptr_equals(VALUE self, VALUE other) { Pointer* ptr; Data_Get_Struct(self, Pointer, ptr); return ptr->memory.address == POINTER(other)->address ? Qtrue : Qfalse; }
void gb_raise_button_Click(gControl *sender) { CWIDGET *ob = GetObject(sender); if (!ob) return; GB.Ref(ob); GB.Raise((void*)ob,EVENT_Click,0); CACTION_raise(ob); GB.Unref(POINTER(&ob)); }
//============================================================================= // // gv4l2_uninit_device(THIS) // // Uninitialise the device and free all the associated memory // void gv4l2_uninit_device(CWEBCAM * _object) { unsigned int i; GB.Free( POINTER(&THIS->frame) ); v4lconvert_destroy(THIS->convert); if( !THIS->use_mmap) { GB.Free ( POINTER(&THIS->buffers[0].start)); GB.Free ( POINTER(&THIS->buffers)); return; } for (i = 0; i < THIS->buffer_count; ++i ) if(munmap(THIS->buffers[i].start,THIS->buffers[i].length)==-1) gv4l2_debug("MUNMAP Error"); GB.Free ( POINTER(&THIS->buffers)); }
void Free_Reader(CXMLREADER *test) { if (test->buffer)GB.Free(POINTER(&test->buffer)); if (test->reader) { xmlTextReaderClose(test->reader); xmlFreeTextReader(test->reader); test->reader=NULL; } test->eof=0; }
static void gb_raise_window_Hide(gMainWindow *sender) { CWIDGET *ob=GetObject(sender); if (!ob) return; GB.Ref(ob); GB.Raise((void*)ob,EVENT_Hide,0); if (!sender->spontaneous()) CACTION_raise(ob); GB.Unref(POINTER(&ob)); }
static void free_channel(CCHANNEL *ch) { if (!ch->sound) return; GB.Unref(POINTER(&ch->sound)); ch->sound = NULL; ch->free = FALSE; _ch_playing--; if (_ch_playing == 0) GB.Watch(_ch_pipe[0], GB_WATCH_NONE, (void *)0, 0); }
/* form of *info varies per bKeyInfo */ void BSafe::BSafeContext::setKeyAtom( B_INFO_TYPE bKeyInfo, const void *info) { /* debug only */ if((bKeyInfo == KI_RSAPublicBER) || (bKeyInfo == KI_RSAPublic)) { printf("Aargh! Unhandled KI_RSAPublic!\n"); CssmError::throwMe(CSSMERR_CSP_INVALID_KEY); } assert(bKeyInfo != KI_RSAPublicBER); // handled elsewhere for now assert(bKeyInfo != KI_RSAPublic); // handled elsewhere for now createBsKey(); check(B_SetKeyInfo(bsKey, bKeyInfo, POINTER(info)), true); }
/* cook up a Binary key */ void BSafe::BSafeKeyInfoProvider::CssmKeyToBinary( CssmKey *paramKey, // optional, ignored CSSM_KEYATTR_FLAGS &attrFlags, // IN/OUT BinaryKey **binKey) { *binKey = NULL; const CSSM_KEYHEADER *hdr = &mKey.KeyHeader; assert(hdr->BlobType == CSSM_KEYBLOB_RAW); B_INFO_TYPE bsType; CSSM_KEYBLOB_FORMAT format; bool isPub; switch(hdr->KeyClass) { case CSSM_KEYCLASS_PUBLIC_KEY: isPub = true; break; case CSSM_KEYCLASS_PRIVATE_KEY: isPub = false; break; default: // someone else's key CssmError::throwMe(CSSMERR_CSP_INVALID_KEY_CLASS); } if(!bsafeAlgToInfoType(hdr->AlgorithmId, isPub, bsType, format)) { // someone else's key CssmError::throwMe(CSSMERR_CSP_INVALID_ALGORITHM); } if(hdr->Format != format) { dprintf0("BSafe::cssmKeyToBinary: format mismatch\n"); CssmError::throwMe(CSSMERR_CSP_INVALID_KEY_FORMAT); } BSafeBinaryKey *bsBinKey = new BSafeBinaryKey(isPub, hdr->AlgorithmId); // set up key material as appropriate if(format == CSSM_KEYBLOB_RAW_FORMAT_PKCS1) { /* special case, decode the PKCS1 format blob */ BS_setKeyPkcs1(mKey, bsBinKey->bsKey()); } else { /* normal case, use key blob as is */ BSafeItem item(mKey.KeyData); BSafe::check( B_SetKeyInfo(bsBinKey->bsKey(), bsType, POINTER(&item)), true); } *binKey = bsBinKey; }
void WEB_remove_download(CWEBDOWNLOAD *_object) { int index; abort_download(THIS, NULL); index = find_download(THIS); if (index >= 0) { GB.Unref(POINTER(&_downloads[index])); GB.Remove(&_downloads, index, 1); } }
static void insert_cache(const char *key, CPICTURE *pict) { CPICTURE *old = dict[key]; if (old) dict.remove(key); if (pict) { dict.insert(key, pict); GB.Ref(pict); } if (old) GB.Unref(POINTER(&old)); }
static void free_channel(CCHANNEL *ch) { if (!ch->sound) return; GB.Unref(POINTER(&ch->sound)); ch->sound = NULL; ch->free = FALSE; _pipe_usage--; if (_pipe_usage == 0) { //fprintf(stderr, "stop watch\n"); GB.Watch(_pipe[0], GB_WATCH_NONE, NULL, 0); } }
// // DSA Parameter Generation // void BSafe::BSafeKeyPairGenContext::generate( const Context &context, uint32 bitSize, CssmData ¶ms, uint32 &attrCount, Context::Attr * &attrs) { assert(context.algorithm() == CSSM_ALGID_DSA); B_ALGORITHM_OBJ genAlg = NULL; B_ALGORITHM_OBJ result = NULL; try { check(B_CreateAlgorithmObject(&genAlg)); B_DSA_PARAM_GEN_PARAMS genParams; genParams.primeBits = bitSize; check(B_SetAlgorithmInfo(genAlg, AI_DSAParamGen, POINTER(&genParams))); setRandom(); check(B_GenerateInit(genAlg, chooser(), bsSurrender), true); check(B_CreateAlgorithmObject(&result)); check(B_GenerateParameters(genAlg, result, bsRandom, bsSurrender)); // get parameters out of algorithm object A_DSA_PARAMS *kParams = NULL; check(B_GetAlgorithmInfo((POINTER *)&kParams, result, AI_DSAKeyGen), true); // shred them into context attribute form attrs = normAllocator->alloc<Context::Attr>(3); attrs[0] = Context::Attr(CSSM_ATTRIBUTE_PRIME, *BSafeItem(kParams->prime).copyp<CssmData>(*normAllocator)); attrs[1] = Context::Attr(CSSM_ATTRIBUTE_SUBPRIME, *BSafeItem(kParams->subPrime).copyp<CssmData>(*normAllocator)); attrs[2] = Context::Attr(CSSM_ATTRIBUTE_BASE, *BSafeItem(kParams->base).copyp<CssmData>(*normAllocator)); attrCount = 3; // clean up B_DestroyAlgorithmObject(&result); B_DestroyAlgorithmObject(&genAlg); } catch (...) { // clean up B_DestroyAlgorithmObject(&result); B_DestroyAlgorithmObject(&genAlg); throw; } }
void ternary_hsort_r(void *base, size_t nmemb, size_t size, compare_fun3 compare, void *arg) { if (nmemb <= 1) { /* nothing to sort!! */ return; } ternary_heapify(base, nmemb, size, compare, arg); size_t end = nmemb - 1; for (end = nmemb - 1; end > 0; end--) { void *end_ptr = POINTER(base, end, size); swap_elements(base, end_ptr, size); ternary_sift_down(base, 0, size, end-1, compare, arg); } }
static void flush_picture() { QHash<QByteArray, CPICTURE *>::iterator it; CPICTURE *pict; //qDebug("flush_picture"); for (it = dict.begin(); it != dict.end(); it++) { //delete it.current()->pixmap; pict = it.value(); //qDebug("flushing: %s %p", it.currentKey().latin1(), pict); GB.Unref(POINTER(&pict)); } dict.clear(); }
void TabCodeGen::LOCATE_TRANS() { out << " _keys = " << ARR_OFF( K(), KO() + "[" + vCS() + "]" ) << ";\n" " _trans = " << IO() << "[" << vCS() << "];\n" "\n" " _klen = " << SL() << "[" << vCS() << "];\n" " if ( _klen > 0 ) {\n" " " << PTR_CONST() << WIDE_ALPH_TYPE() << PTR_CONST_END() << POINTER() << "_lower = _keys;\n" " " << PTR_CONST() << WIDE_ALPH_TYPE() << PTR_CONST_END() << POINTER() << "_mid;\n" " " << PTR_CONST() << WIDE_ALPH_TYPE() << PTR_CONST_END() << POINTER() << "_upper = _keys + _klen - 1;\n" " while (1) {\n" " if ( _upper < _lower )\n" " break;\n" "\n" " _mid = _lower + ((_upper-_lower) >> 1);\n" " if ( " << GET_WIDE_KEY() << " < *_mid )\n" " _upper = _mid - 1;\n" " else if ( " << GET_WIDE_KEY() << " > *_mid )\n" " _lower = _mid + 1;\n" " else {\n" " _trans += " << CAST(UINT()) << "(_mid - _keys);\n" " goto _match;\n" " }\n" " }\n" " _keys += _klen;\n" " _trans += _klen;\n" " }\n" "\n" " _klen = " << RL() << "[" << vCS() << "];\n" " if ( _klen > 0 ) {\n" " " << PTR_CONST() << WIDE_ALPH_TYPE() << PTR_CONST_END() << POINTER() << "_lower = _keys;\n" " " << PTR_CONST() << WIDE_ALPH_TYPE() << PTR_CONST_END() << POINTER() << "_mid;\n" " " << PTR_CONST() << WIDE_ALPH_TYPE() << PTR_CONST_END() << POINTER() << "_upper = _keys + (_klen<<1) - 2;\n" " while (1) {\n" " if ( _upper < _lower )\n" " break;\n" "\n" " _mid = _lower + (((_upper-_lower) >> 1) & ~1);\n" " if ( " << GET_WIDE_KEY() << " < _mid[0] )\n" " _upper = _mid - 2;\n" " else if ( " << GET_WIDE_KEY() << " > _mid[1] )\n" " _lower = _mid + 2;\n" " else {\n" " _trans += " << CAST(UINT()) << "((_mid - _keys)>>1);\n" " goto _match;\n" " }\n" " }\n" " _trans += _klen;\n" " }\n" "\n"; }
int *MATRIX_map_array(MATRIX *matrix, int *coord, int npoint) { int *map_coord, *map; int i; GB.Alloc(POINTER(&map_coord), sizeof(int) * npoint * 2); map = map_coord; for (i = 0; i < npoint; i++) { map[0] = coord[0]; map[1] = coord[1]; MATRIX_map_point(matrix, &map[0], &map[1]); coord += 2; map += 2; } return map_coord; }
/* * call-seq: ptr.initialize_copy(other) * @param [Pointer] other source for cloning or dupping * @return [self] * @raise {RuntimeError} if +other+ is an unbounded memory area, or is unreable/unwritable * @raise {NoMemError} if failed to allocate memory for new object * DO NOT CALL THIS METHOD. * * This method is internally used by #dup and #clone. Memory contents is copied from +other+. */ static VALUE ptr_initialize_copy(VALUE self, VALUE other) { AbstractMemory* src; Pointer* dst; Data_Get_Struct(self, Pointer, dst); src = POINTER(other); if (src->size == LONG_MAX) { rb_raise(rb_eRuntimeError, "cannot duplicate unbounded memory area"); return Qnil; } if ((dst->memory.flags & (MEM_RD | MEM_WR)) != (MEM_RD | MEM_WR)) { rb_raise(rb_eRuntimeError, "cannot duplicate unreadable/unwritable memory area"); return Qnil; } if (dst->storage != NULL) { xfree(dst->storage); dst->storage = NULL; } dst->storage = xmalloc(src->size + 7); if (dst->storage == NULL) { rb_raise(rb_eNoMemError, "failed to allocate memory size=%lu bytes", src->size); return Qnil; } dst->allocated = true; dst->autorelease = true; dst->memory.address = (void *) (((uintptr_t) dst->storage + 0x7) & (uintptr_t) ~0x7UL); dst->memory.size = src->size; dst->memory.typeSize = src->typeSize; // finally, copy the actual memory contents memcpy(dst->memory.address, src->address, src->size); return self; }
CONSTANT(GLUT_ENTERED) CONSTANT(GLUT_MENU_NOT_IN_USE) CONSTANT(GLUT_MENU_IN_USE) CONSTANT(GLUT_NOT_VISIBLE) CONSTANT(GLUT_VISIBLE) CONSTANT(GLUT_HIDDEN) CONSTANT(GLUT_FULLY_RETAINED) CONSTANT(GLUT_PARTIALLY_RETAINED) CONSTANT(GLUT_FULLY_COVERED) CONSTANT(GLUT_RED) CONSTANT(GLUT_GREEN) CONSTANT(GLUT_BLUE) CONSTANT(GLUT_NORMAL) CONSTANT(GLUT_OVERLAY) POINTER(GLUT_STROKE_ROMAN) POINTER(GLUT_STROKE_MONO_ROMAN) POINTER(GLUT_BITMAP_9_BY_15) POINTER(GLUT_BITMAP_8_BY_13) POINTER(GLUT_BITMAP_TIMES_ROMAN_10) POINTER(GLUT_BITMAP_TIMES_ROMAN_24) POINTER(GLUT_BITMAP_HELVETICA_10) POINTER(GLUT_BITMAP_HELVETICA_12) POINTER(GLUT_BITMAP_HELVETICA_18) CONSTANT(GLUT_WINDOW_X) CONSTANT(GLUT_WINDOW_Y) CONSTANT(GLUT_WINDOW_WIDTH) CONSTANT(GLUT_WINDOW_HEIGHT) CONSTANT(GLUT_WINDOW_BUFFER_SIZE) CONSTANT(GLUT_WINDOW_STENCIL_SIZE)