@@ -291,7 +291,7 @@ void MCB_trace(MCExecContext &ctxt, uint2 line, uint2 pos)
291291 t_parentscript = ctxt . GetParentScript ();
292292 if ((t_parentscript == NULL && MCbreakpoints[i].object == ctxt.GetObject ()) ||
293293 (t_parentscript != NULL && MCbreakpoints[i].object == t_parentscript -> GetParent () -> GetObject ()))
294- MCB_prepmessage (ctxt, MCM_trace_break, line, pos, 0 , MCbreakpoints[i].info );
294+ MCB_prepmessage (ctxt, MCM_trace_break, line, pos, 0 , * MCbreakpoints[i].info );
295295 }
296296 }
297297}
@@ -378,17 +378,18 @@ void MCB_setvalue(MCExecContext &ctxt, MCExecValue p_value, MCNameRef name)
378378
379379void MCB_clearbreaks (MCObject *p_for_object)
380380{
381- for (unsigned int n = 0 ; n < MCnbreakpoints; ++n)
382- if (p_for_object == NULL || MCbreakpoints[n] . object == p_for_object)
381+ for (size_t n = 0 ; n < MCnbreakpoints; ++n)
382+ {
383+ if (p_for_object == nil || MCbreakpoints[n].object == p_for_object)
383384 {
384- MCbreakpoints[n] . object = NULL ;
385- MCValueAssign (MCbreakpoints[n] . info, kMCEmptyString );
385+ MCbreakpoints[n].Clear ();
386386 }
387+ }
387388
388- if (p_for_object == NULL )
389+ if (p_for_object == nil && MCbreakpoints != nil )
389390 {
390391 MCnbreakpoints = 0 ;
391- free (MCbreakpoints);
392+ MCMemoryDestroy (MCbreakpoints);
392393 MCbreakpoints = nil;
393394 }
394395}
@@ -407,7 +408,7 @@ bool MCB_unparsebreaks(MCStringRef& r_value)
407408 // MW-2005-06-26: Fix breakpoint crash issue - ignore any breakpoints with NULL object
408409 for (uint32_t i = 0 ; i < MCnbreakpoints ; i++)
409410 {
410- if (MCbreakpoints[i] . object != NULL )
411+ if (MCbreakpoints[i]. object )
411412 {
412413 MCAutoListRef t_breakpoint;
413414 t_success = MCListCreateMutable (' ,' , &t_breakpoint);
@@ -426,9 +427,9 @@ bool MCB_unparsebreaks(MCStringRef& r_value)
426427 MCListAppend (*t_breakpoint, *t_line);
427428 }
428429
429- if (t_success && !MCStringIsEmpty (MCbreakpoints[i] . info))
430+ if (t_success && !MCStringIsEmpty (* MCbreakpoints[i]. info ))
430431 {
431- t_success = MCListAppend (*t_breakpoint, MCbreakpoints[i] . info);
432+ t_success = MCListAppend (*t_breakpoint, * MCbreakpoints[i]. info );
432433 }
433434
434435 if (t_success)
@@ -518,15 +519,12 @@ void MCB_parsebreaks(MCExecContext& ctxt, MCStringRef p_input)
518519 if (t_valid_break)
519520 {
520521 Breakpoint *t_new_breakpoints;
521- t_new_breakpoints = (Breakpoint *)realloc (MCbreakpoints, sizeof (Breakpoint) * (MCnbreakpoints + 1 ));
522- if (t_new_breakpoints != nil)
523- {
524- MCbreakpoints = t_new_breakpoints;
525- MCbreakpoints[MCnbreakpoints] . object = t_object . object;
526- MCbreakpoints[MCnbreakpoints] . line = (uint32_t )t_line;
527- MCbreakpoints[MCnbreakpoints] . info = MCValueRetain (*t_info);
528- MCnbreakpoints++;
529- }
522+ if (!MCMemoryReallocate (MCbreakpoints, sizeof (Breakpoint) * (MCnbreakpoints + 1 ), t_new_breakpoints))
523+ break ;
524+
525+ MCbreakpoints = t_new_breakpoints;
526+ new (&MCbreakpoints[MCnbreakpoints]) Breakpoint (t_object.object ->GetHandle (), t_line, *t_info);
527+ MCnbreakpoints++;
530528 }
531529 }
532530 t_last_offset = t_return_offset + 1 ;
@@ -537,16 +535,17 @@ void MCB_parsebreaks(MCExecContext& ctxt, MCStringRef p_input)
537535
538536void MCB_clearwatches (void )
539537{
540- while ( MCnwatchedvars-- )
538+ for ( size_t i = 0 ; i < MCnwatchedvars; i++ )
541539 {
542- MCNameDelete (MCwatchedvars[MCnwatchedvars].handlername );
543- MCNameDelete (MCwatchedvars[MCnwatchedvars].varname );
544- MCValueRelease (MCwatchedvars[MCnwatchedvars].expression );
540+ MCwatchedvars[i].Clear ();
545541 }
546- MCnwatchedvars = 0 ;
547542
548- free (MCwatchedvars);
549- MCwatchedvars = nil;
543+ if (MCwatchedvars != nil)
544+ {
545+ MCnwatchedvars = 0 ;
546+ MCMemoryDestroy (MCwatchedvars);
547+ MCwatchedvars = nil;
548+ }
550549}
551550
552551void MCB_parsewatches (MCExecContext& ctxt, MCStringRef p_input)
@@ -615,23 +614,25 @@ void MCB_parsewatches(MCExecContext& ctxt, MCStringRef p_input)
615614 t_object . object != nil)
616615 {
617616 Watchvar *t_new_watches;
618- t_new_watches = (Watchvar *)realloc (MCwatchedvars, sizeof (Watchvar) * (MCnwatchedvars + 1 ));
619- if (t_new_watches != nil)
620- {
621- MCwatchedvars = t_new_watches;
622- if (t_resolved_object)
623- MCwatchedvars[MCnwatchedvars] . object = t_object . object;
624- else
625- MCwatchedvars[MCnwatchedvars] . object = nil;
626-
627- if (MCStringGetLength (*t_hname) != 0 )
628- /* UNCHECKED */ MCNameCreate (*t_hname, MCwatchedvars[MCnwatchedvars] . handlername);
629- else
630- MCwatchedvars[MCnwatchedvars] . handlername = nil;
631- /* UNCHECKED */ MCNameCreate (*t_vname, MCwatchedvars[MCnwatchedvars] . varname);
632- MCwatchedvars[MCnwatchedvars] . expression = MCValueRetain (*t_express);
633- MCnwatchedvars++;
634- }
617+ if (!MCMemoryReallocate (MCwatchedvars, sizeof (Watchvar) * (MCnwatchedvars + 1 ), t_new_watches))
618+ {
619+ t_success = false ;
620+ break ;
621+ }
622+
623+ MCObjectHandle t_objecthandle;
624+ MCNewAutoNameRef t_handlername;
625+ MCNewAutoNameRef t_varname;
626+
627+ if (t_resolved_object)
628+ t_objecthandle = t_object.object ;
629+
630+ /* UNCHECKED */ MCNameCreate (*t_hname, &t_handlername);
631+ /* UNCHECKED */ MCNameCreate (*t_vname, &t_varname);
632+
633+ MCwatchedvars = t_new_watches;
634+ new (&MCwatchedvars[MCnwatchedvars]) Watchvar (t_objecthandle, *t_handlername, *t_varname, *t_express);
635+ MCnwatchedvars++;
635636 }
636637 }
637638 t_last_offset = t_return_offset + 1 ;
@@ -656,7 +657,7 @@ bool MCB_unparsewatches(MCStringRef &r_watches)
656657
657658 if (t_success)
658659 {
659- if (MCwatchedvars[i] . object != NULL )
660+ if (MCwatchedvars[i]. object )
660661 {
661662 MCAutoValueRef t_var_id;
662663 t_success = MCwatchedvars[i] . object -> names (P_LONG_ID, &t_var_id) &&
@@ -668,18 +669,18 @@ bool MCB_unparsewatches(MCStringRef &r_watches)
668669
669670 if (t_success)
670671 {
671- if (MCwatchedvars[i] . handlername == NULL )
672+ if (! MCwatchedvars[i]. handlername . IsSet () )
672673 t_success = MCListAppend (*t_watched_var, kMCEmptyString );
673674 else
674- t_success = MCListAppend (*t_watched_var, MCwatchedvars[i].handlername );
675+ t_success = MCListAppend (*t_watched_var, * MCwatchedvars[i].handlername );
675676 }
676677
677678 if (t_success)
678- t_success = MCListAppend (*t_watched_var, MCwatchedvars[i].varname );
679+ t_success = MCListAppend (*t_watched_var, * MCwatchedvars[i].varname );
679680
680681 // SN-2014-09-18: [[ Bug 13453 ]] A watched variable's expression is never nil
681682 if (t_success)
682- t_success = MCListAppend (*t_watched_var, MCwatchedvars[i].expression );
683+ t_success = MCListAppend (*t_watched_var, * MCwatchedvars[i].expression );
683684
684685 if (t_success)
685686 t_success = MCListAppend (*t_watches_list, *t_watched_var);
0 commit comments