//! Test for memory leak in concurrent_hash_map (TR #153). void TestConcurrency( int nthread ) { REMARK("testing multiple insertions/deletions of same key with %d threads\n", nthread); { ASSERT( MyDataCount==0, NULL ); MyTable table; const int m = 1000; Counter = 0; tbb::tick_count t0 = tbb::tick_count::now(); NativeParallelFor( nthread, AddToTable(table,nthread,m) ); tbb::tick_count t1 = tbb::tick_count::now(); REMARK("time for %u insertions = %g with %d threads\n",unsigned(MyDataCount),(t1-t0).seconds(),nthread); ASSERT( MyDataCount==m, "memory leak detected" ); EraseCount = 0; t0 = tbb::tick_count::now(); NativeParallelFor( nthread, RemoveFromTable(table,nthread,m) ); t1 = tbb::tick_count::now(); REMARK("time for %u deletions = %g with %d threads\n",unsigned(EraseCount),(t1-t0).seconds(),nthread); ASSERT( MyDataCount==0, "memory leak detected" ); ASSERT( EraseCount==m, "return value of erase() is broken" ); CheckAllocator(table, m, m, /*exact*/nthread <= 1); } ASSERT( MyDataCount==0, "memory leak detected" ); }
WORD W_EXPORT AddObject(LPSTR lpObject, LPSTR lpArg) { KppGetAtomName(NAME(lpObject), return_buffer, RET_BUFFER_LEN); if (!strncmp(SearchedName, return_buffer, cCount)) { if (strcmp(return_buffer, SearchedMin) <= 0) strcpy(SearchedMin, return_buffer); AddToTable(return_buffer, NAME(lpObject)); } return TRUE; }
void gfx_light::ResetProperties (const enum LIGHT_TARGET light_targ, const GFXColor &color) { bool changed=false; if (LocalLight()) { GFXLight t; memcpy (&t,this,sizeof (GFXLight)); t.SetProperties (light_targ,color); changed=RemoveFromTable(false,t); memcpy (this,&t,sizeof (GFXLight)); if (changed) AddToTable (); if (target>=0) TrashFromGLLights(); return; } switch (light_targ) { case DIFFUSE: diffuse[0]= color.r;diffuse[1]=color.g;diffuse[2]=color.b;diffuse[3]=color.a; if (target<0) break; glLightfv (GL_LIGHT0+target,GL_DIFFUSE,diffuse); break; case SPECULAR: specular[0]= color.r;specular[1]=color.g;specular[2]=color.b;specular[3]=color.a; if (target<0) break; glLightfv (GL_LIGHT0+target,GL_SPECULAR,specular); break; case AMBIENT: ambient[0]= color.r;ambient[1]=color.g;ambient[2]=color.b;ambient[3]=color.a; if (target<0) break; glLightfv (GL_LIGHT0+target,GL_AMBIENT,ambient); break; case POSITION: vect[0]=color.r;vect[1]=color.g;vect[2]=color.b; if (target<0) break; SendGLPosition (GL_LIGHT0+target); break; default: case ATTENUATE: attenuate[0]=color.r; attenuate[1]=color.g; attenuate[2]=color.b; apply_attenuate(attenuated()); if (target<0) break; SendGLPosition (GL_LIGHT0+target); glLightf (GL_LIGHT0+target,GL_CONSTANT_ATTENUATION, attenuate[0]*atten0scale); glLightf (GL_LIGHT0+target,GL_LINEAR_ATTENUATION, attenuate[1]*atten1scale); glLightf (GL_LIGHT0+target,GL_QUADRATIC_ATTENUATION, attenuate[2]*atten2scale); break; } }
//unimplemented void gfx_light::Enable() { if (!enabled()) { if (LocalLight()) AddToTable(); else { if (target==-1) { int newtarg = findGlobalClobberable(); if (newtarg==-1) return; _GLLightsEnabled++; ClobberGLLight (newtarg); } glEnable (GL_LIGHT0+this->target); GLLights[this->target].options|=OpenGLL::GL_ENABLED|OpenGLL::GLL_ON; } enable(); } }
// Allocate a new object. May create a new space and add the old one to the permanent // memory table if this is exhausted. PolyObject *SpaceAlloc::NewObj(POLYUNSIGNED objWords) { if (currentSize - used <= objWords) { // Need some more space. if (! AddToTable()) return 0; POLYUNSIGNED size = defaultSize; if (size <= objWords) size = objWords+1; size_t iSpace = size*sizeof(PolyWord); base = (PolyWord*)osMemoryManager->Allocate(iSpace, PERMISSION_READ|PERMISSION_WRITE|PERMISSION_EXEC); currentSize = iSpace/sizeof(PolyWord); used = 0; } ASSERT(currentSize - used > objWords); PolyObject *newObj = (PolyObject*)(base+used+1); used += objWords+1; return newObj; }
/************************************************************************ * * Initialize * ************************************************************************/ static void Initialize( Widget req_widget, Widget new_widget, ArgList args, Cardinal *num_args ) { int event_base_return, error_base_return ; XmPrintShellWidget print_shell = (XmPrintShellWidget) new_widget ; XPContext pcontext ; Screen * pscreen ; _XmProcessLock(); /* mark the screen of this print shell in this context */ XSaveContext(XtDisplay(new_widget), (XID)XtScreen(new_widget), _XmPrintScreenToShellContext, (XPointer) new_widget); /* also maintain a counter of all shell */ _XmPrintShellCounter ++ ; _XmProcessUnlock(); print_shell->print.xp_connected = False ; print_shell->print.print_resolution = 100 ; /*** first check if the Print extension is present at all */ if (!XpQueryExtension (XtDisplay(new_widget), &event_base_return, &error_base_return)) { return ; } /* need to check that the print context is set for the screen of this print shell (i.e. it's a print screen, not just a screen on a display that support printing and for which a context was establish on a different screen - which can be common in preview case */ pcontext = XpGetContext(XtDisplay(new_widget)); if (!pcontext || XpGetScreenOfContext(XtDisplay(new_widget),pcontext) != XtScreen(new_widget)) { return ; } print_shell->print.xp_connected = True ; /*** add an element to a widget/XPContext table, used in the event dispatch mechanism */ AddToTable(pcontext, new_widget); /*** add extension event Handler for Start/End Job/Page Notify */ XtInsertEventTypeHandler(new_widget, event_base_return + XPPrintNotify, (XtPointer)XPPrintMask, PrintNotifyHandler, NULL, XtListTail); /*** also add extension event Handler for tracking attributes change */ XtInsertEventTypeHandler(new_widget, event_base_return + XPAttributeNotify, (XtPointer)XPAttributeMask, AttributesNotifyHandler, NULL, XtListTail); /* always register the extension selector, and the event dispatcher, it will override itself accordingly and works ok for different display connection */ XtRegisterExtensionSelector(XtDisplay(new_widget), event_base_return + XPPrintNotify, event_base_return + XPAttributeNotify, SelectXpEvents, NULL); (void) XtSetEventDispatcher(XtDisplay(new_widget), event_base_return + XPPrintNotify, PrintDispatchEvent); (void) XtSetEventDispatcher(XtDisplay(new_widget), event_base_return + XPAttributeNotify, PrintDispatchEvent); /* go and get resolution and initial sizes */ ResourcesUpdate(new_widget, pcontext, &(new_widget->core.width), &(new_widget->core.height)); }
int yyparse (void) { int yystate; /* Number of tokens to shift before error messages enabled. */ int yyerrstatus; /* The stacks and their tools: 'yyss': related to states. 'yyvs': related to semantic values. Refer to the stacks through separate pointers, to allow yyoverflow to reallocate them elsewhere. */ /* The state stack. */ yytype_int16 yyssa[YYINITDEPTH]; yytype_int16 *yyss; yytype_int16 *yyssp; /* The semantic value stack. */ YYSTYPE yyvsa[YYINITDEPTH]; YYSTYPE *yyvs; YYSTYPE *yyvsp; YYSIZE_T yystacksize; int yyn; int yyresult; /* Lookahead token as an internal (translated) token number. */ int yytoken = 0; /* The variables used to return semantic value and location from the action routines. */ YYSTYPE yyval; #if YYERROR_VERBOSE /* Buffer for error messages, and its allocated size. */ char yymsgbuf[128]; char *yymsg = yymsgbuf; YYSIZE_T yymsg_alloc = sizeof yymsgbuf; #endif #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) /* The number of symbols on the RHS of the reduced rule. Keep to zero when no symbol should be popped. */ int yylen = 0; yyssp = yyss = yyssa; yyvsp = yyvs = yyvsa; yystacksize = YYINITDEPTH; YYDPRINTF ((stderr, "Starting parse\n")); yystate = 0; yyerrstatus = 0; yynerrs = 0; yychar = YYEMPTY; /* Cause a token to be read. */ goto yysetstate; /*------------------------------------------------------------. | yynewstate -- Push a new state, which is found in yystate. | `------------------------------------------------------------*/ yynewstate: /* In all cases, when you get here, the value and location stacks have just been pushed. So pushing a state here evens the stacks. */ yyssp++; yysetstate: *yyssp = yystate; if (yyss + yystacksize - 1 <= yyssp) { /* Get the current used size of the three stacks, in elements. */ YYSIZE_T yysize = yyssp - yyss + 1; #ifdef yyoverflow { /* Give user a chance to reallocate the stack. Use copies of these so that the &'s don't force the real ones into memory. */ YYSTYPE *yyvs1 = yyvs; yytype_int16 *yyss1 = yyss; /* Each stack pointer address is followed by the size of the data in use in that stack, in bytes. This used to be a conditional around just the two extra args, but that might be undefined if yyoverflow is a macro. */ yyoverflow (YY_("memory exhausted"), &yyss1, yysize * sizeof (*yyssp), &yyvs1, yysize * sizeof (*yyvsp), &yystacksize); yyss = yyss1; yyvs = yyvs1; } #else /* no yyoverflow */ # ifndef YYSTACK_RELOCATE goto yyexhaustedlab; # else /* Extend the stack our own way. */ if (YYMAXDEPTH <= yystacksize) goto yyexhaustedlab; yystacksize *= 2; if (YYMAXDEPTH < yystacksize) yystacksize = YYMAXDEPTH; { yytype_int16 *yyss1 = yyss; union yyalloc *yyptr = (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); if (! yyptr) goto yyexhaustedlab; YYSTACK_RELOCATE (yyss_alloc, yyss); YYSTACK_RELOCATE (yyvs_alloc, yyvs); # undef YYSTACK_RELOCATE if (yyss1 != yyssa) YYSTACK_FREE (yyss1); } # endif #endif /* no yyoverflow */ yyssp = yyss + yysize - 1; yyvsp = yyvs + yysize - 1; YYDPRINTF ((stderr, "Stack size increased to %lu\n", (unsigned long int) yystacksize)); if (yyss + yystacksize - 1 <= yyssp) YYABORT; } YYDPRINTF ((stderr, "Entering state %d\n", yystate)); if (yystate == YYFINAL) YYACCEPT; goto yybackup; /*-----------. | yybackup. | `-----------*/ yybackup: /* Do appropriate processing given the current state. Read a lookahead token if we need one and don't already have one. */ /* First try to decide what to do without reference to lookahead token. */ yyn = yypact[yystate]; if (yypact_value_is_default (yyn)) goto yydefault; /* Not known => get a lookahead token if don't already have one. */ /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ if (yychar == YYEMPTY) { YYDPRINTF ((stderr, "Reading a token: ")); yychar = yylex (); } if (yychar <= YYEOF) { yychar = yytoken = YYEOF; YYDPRINTF ((stderr, "Now at end of input.\n")); } else { yytoken = YYTRANSLATE (yychar); YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); } /* If the proper action on seeing token YYTOKEN is to reduce or to detect an error, take that action. */ yyn += yytoken; if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) goto yydefault; yyn = yytable[yyn]; if (yyn <= 0) { if (yytable_value_is_error (yyn)) goto yyerrlab; yyn = -yyn; goto yyreduce; } /* Count tokens shifted since error; after three, turn off error status. */ if (yyerrstatus) yyerrstatus--; /* Shift the lookahead token. */ YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); /* Discard the shifted token. */ yychar = YYEMPTY; yystate = yyn; YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN *++yyvsp = yylval; YY_IGNORE_MAYBE_UNINITIALIZED_END goto yynewstate; /*-----------------------------------------------------------. | yydefault -- do the default action for the current state. | `-----------------------------------------------------------*/ yydefault: yyn = yydefact[yystate]; if (yyn == 0) goto yyerrlab; goto yyreduce; /*-----------------------------. | yyreduce -- Do a reduction. | `-----------------------------*/ yyreduce: /* yyn is the number of a rule to reduce with. */ yylen = yyr2[yyn]; /* If YYLEN is nonzero, implement the default value of the action: '$$ = $1'. Otherwise, the following line sets YYVAL to garbage. This behavior is undocumented and Bison users should not rely upon it. Assigning to YYVAL unconditionally makes the parser a bit smaller, and it avoids a GCC warning that YYVAL may be used uninitialized. */ yyval = yyvsp[1-yylen]; YY_REDUCE_PRINT (yyn); switch (yyn) { case 2: #line 31 "three.y" /* yacc.c:1646 */ {AddToTable((char)(yyvsp[-3].sym),(char)(yyvsp[-1].sym),'=');} #line 1232 "y.tab.c" /* yacc.c:1646 */ break; case 4: #line 35 "three.y" /* yacc.c:1646 */ {(yyval.sym) = AddToTable((char)(yyvsp[-2].sym),(char)(yyvsp[0].sym),'+');} #line 1238 "y.tab.c" /* yacc.c:1646 */ break; case 5: #line 36 "three.y" /* yacc.c:1646 */ {(yyval.sym) = AddToTable((char)(yyvsp[-2].sym),(char)(yyvsp[0].sym),'-');} #line 1244 "y.tab.c" /* yacc.c:1646 */ break; case 6: #line 37 "three.y" /* yacc.c:1646 */ {(yyval.sym) = AddToTable((char)(yyvsp[-2].sym),(char)(yyvsp[0].sym),'*');} #line 1250 "y.tab.c" /* yacc.c:1646 */ break; case 7: #line 38 "three.y" /* yacc.c:1646 */ {(yyval.sym) = AddToTable((char)(yyvsp[-2].sym),(char)(yyvsp[0].sym),'/');} #line 1256 "y.tab.c" /* yacc.c:1646 */ break; case 8: #line 39 "three.y" /* yacc.c:1646 */ {(yyval.sym) = (char)(yyvsp[-1].sym);} #line 1262 "y.tab.c" /* yacc.c:1646 */ break; case 9: #line 40 "three.y" /* yacc.c:1646 */ {(yyval.sym) = (char)(yyvsp[0].sym);} #line 1268 "y.tab.c" /* yacc.c:1646 */ break; case 10: #line 41 "three.y" /* yacc.c:1646 */ {(yyval.sym) = (char)(yyvsp[0].sym);} #line 1274 "y.tab.c" /* yacc.c:1646 */ break; #line 1278 "y.tab.c" /* yacc.c:1646 */ default: break; } /* User semantic actions sometimes alter yychar, and that requires that yytoken be updated with the new translation. We take the approach of translating immediately before every use of yytoken. One alternative is translating here after every semantic action, but that translation would be missed if the semantic action invokes YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an incorrect destructor might then be invoked immediately. In the case of YYERROR or YYBACKUP, subsequent parser actions might lead to an incorrect destructor call or verbose syntax error message before the lookahead is translated. */ YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); YYPOPSTACK (yylen); yylen = 0; YY_STACK_PRINT (yyss, yyssp); *++yyvsp = yyval; /* Now 'shift' the result of the reduction. Determine what state that goes to, based on the state we popped back to and the rule number reduced by. */ yyn = yyr1[yyn]; yystate = yypgoto[yyn - YYNTOKENS] + *yyssp; if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp) yystate = yytable[yystate]; else yystate = yydefgoto[yyn - YYNTOKENS]; goto yynewstate; /*--------------------------------------. | yyerrlab -- here on detecting error. | `--------------------------------------*/ yyerrlab: /* Make sure we have latest lookahead translation. See comments at user semantic actions for why this is necessary. */ yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar); /* If not already recovering from an error, report this error. */ if (!yyerrstatus) { ++yynerrs; #if ! YYERROR_VERBOSE yyerror (YY_("syntax error")); #else # define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \ yyssp, yytoken) { char const *yymsgp = YY_("syntax error"); int yysyntax_error_status; yysyntax_error_status = YYSYNTAX_ERROR; if (yysyntax_error_status == 0) yymsgp = yymsg; else if (yysyntax_error_status == 1) { if (yymsg != yymsgbuf) YYSTACK_FREE (yymsg); yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc); if (!yymsg) { yymsg = yymsgbuf; yymsg_alloc = sizeof yymsgbuf; yysyntax_error_status = 2; } else { yysyntax_error_status = YYSYNTAX_ERROR; yymsgp = yymsg; } } yyerror (yymsgp); if (yysyntax_error_status == 2) goto yyexhaustedlab; } # undef YYSYNTAX_ERROR #endif } if (yyerrstatus == 3) { /* If just tried and failed to reuse lookahead token after an error, discard it. */ if (yychar <= YYEOF) { /* Return failure if at end of input. */ if (yychar == YYEOF) YYABORT; } else { yydestruct ("Error: discarding", yytoken, &yylval); yychar = YYEMPTY; } } /* Else will try to reuse lookahead token after shifting the error token. */ goto yyerrlab1; /*---------------------------------------------------. | yyerrorlab -- error raised explicitly by YYERROR. | `---------------------------------------------------*/ yyerrorlab: /* Pacify compilers like GCC when the user code never invokes YYERROR and the label yyerrorlab therefore never appears in user code. */ if (/*CONSTCOND*/ 0) goto yyerrorlab; /* Do not reclaim the symbols of the rule whose action triggered this YYERROR. */ YYPOPSTACK (yylen); yylen = 0; YY_STACK_PRINT (yyss, yyssp); yystate = *yyssp; goto yyerrlab1; /*-------------------------------------------------------------. | yyerrlab1 -- common code for both syntax error and YYERROR. | `-------------------------------------------------------------*/ yyerrlab1: yyerrstatus = 3; /* Each real token shifted decrements this. */ for (;;) { yyn = yypact[yystate]; if (!yypact_value_is_default (yyn)) { yyn += YYTERROR; if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) { yyn = yytable[yyn]; if (0 < yyn) break; } } /* Pop the current state because it cannot handle the error token. */ if (yyssp == yyss) YYABORT; yydestruct ("Error: popping", yystos[yystate], yyvsp); YYPOPSTACK (1); yystate = *yyssp; YY_STACK_PRINT (yyss, yyssp); } YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN *++yyvsp = yylval; YY_IGNORE_MAYBE_UNINITIALIZED_END /* Shift the error token. */ YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp); yystate = yyn; goto yynewstate; /*-------------------------------------. | yyacceptlab -- YYACCEPT comes here. | `-------------------------------------*/ yyacceptlab: yyresult = 0; goto yyreturn; /*-----------------------------------. | yyabortlab -- YYABORT comes here. | `-----------------------------------*/ yyabortlab: yyresult = 1; goto yyreturn; #if !defined yyoverflow || YYERROR_VERBOSE /*-------------------------------------------------. | yyexhaustedlab -- memory exhaustion comes here. | `-------------------------------------------------*/ yyexhaustedlab: yyerror (YY_("memory exhausted")); yyresult = 2; /* Fall through. */ #endif yyreturn: if (yychar != YYEMPTY) { /* Make sure we have latest lookahead translation. See comments at user semantic actions for why this is necessary. */ yytoken = YYTRANSLATE (yychar); yydestruct ("Cleanup: discarding lookahead", yytoken, &yylval); } /* Do not reclaim the symbols of the rule whose action triggered this YYABORT or YYACCEPT. */ YYPOPSTACK (yylen); YY_STACK_PRINT (yyss, yyssp); while (yyssp != yyss) { yydestruct ("Cleanup: popping", yystos[*yyssp], yyvsp); YYPOPSTACK (1); } #ifndef yyoverflow if (yyss != yyssa) YYSTACK_FREE (yyss); #endif #if YYERROR_VERBOSE if (yymsg != yymsgbuf) YYSTACK_FREE (yymsg); #endif return yyresult; }