diff options
| author | Kris De Gussem <kris.degussem@gmail.com> | 2012-05-12 11:16:29 +0000 |
|---|---|---|
| committer | Kris <Kris.De.Gussem@hotmail.com> | 2012-05-12 11:16:29 +0000 |
| commit | adc17549c5f0485a30a87e7674c7779ef3155d6c (patch) | |
| tree | 5d7600ee04a17673e9af977637c4cd89fe5e4938 /src | |
| parent | Fix for externally reported patch by Juergen Weigert, Bug #993500 (inkscape s... (diff) | |
| download | inkscape-adc17549c5f0485a30a87e7674c7779ef3155d6c.tar.gz inkscape-adc17549c5f0485a30a87e7674c7779ef3155d6c.zip | |
syntx of null pointer dereference checks
(bzr r11358)
Diffstat (limited to 'src')
| -rw-r--r-- | src/desktop-events.cpp | 26 | ||||
| -rw-r--r-- | src/display/nr-filter-image.cpp | 2 | ||||
| -rw-r--r-- | src/ege-color-prof-tracker.cpp | 33 | ||||
| -rw-r--r-- | src/widgets/gradient-vector.cpp | 20 | ||||
| -rw-r--r-- | src/widgets/sp-color-icc-selector.cpp | 88 | ||||
| -rw-r--r-- | src/xml/composite-node-observer.cpp | 8 | ||||
| -rw-r--r-- | src/xml/event.cpp | 591 | ||||
| -rw-r--r-- | src/xml/helper-observer.cpp | 14 | ||||
| -rw-r--r-- | src/xml/repr-io.cpp | 26 | ||||
| -rw-r--r-- | src/xml/repr-sorting.cpp | 11 | ||||
| -rw-r--r-- | src/xml/repr-util.cpp | 9 |
11 files changed, 438 insertions, 390 deletions
diff --git a/src/desktop-events.cpp b/src/desktop-events.cpp index 513e8347b..a9ad5da44 100644 --- a/src/desktop-events.cpp +++ b/src/desktop-events.cpp @@ -113,15 +113,17 @@ static gint sp_dt_ruler_event(GtkWidget *widget, GdkEvent *event, SPDesktopWidge normal_bl_to_tr.normalize(); normal_tr_to_bl.normalize(); Inkscape::CanvasGrid * grid = sp_namedview_get_first_enabled_grid(desktop->namedview); - if ( grid && grid->getGridType() == Inkscape::GRID_AXONOMETRIC ) { - Inkscape::CanvasAxonomGrid *axonomgrid = dynamic_cast<Inkscape::CanvasAxonomGrid *>(grid); - if (event->button.state & GDK_CONTROL_MASK) { - // guidelines normal to gridlines - normal_bl_to_tr = Geom::Point::polar(-axonomgrid->angle_rad[0], 1.0); - normal_tr_to_bl = Geom::Point::polar(axonomgrid->angle_rad[2], 1.0); - } else { - normal_bl_to_tr = rot90(Geom::Point::polar(axonomgrid->angle_rad[2], 1.0)); - normal_tr_to_bl = rot90(Geom::Point::polar(-axonomgrid->angle_rad[0], 1.0)); + if (grid){ + if (grid->getGridType() == Inkscape::GRID_AXONOMETRIC ) { + Inkscape::CanvasAxonomGrid *axonomgrid = dynamic_cast<Inkscape::CanvasAxonomGrid *>(grid); + if (event->button.state & GDK_CONTROL_MASK) { + // guidelines normal to gridlines + normal_bl_to_tr = Geom::Point::polar(-axonomgrid->angle_rad[0], 1.0); + normal_tr_to_bl = Geom::Point::polar(axonomgrid->angle_rad[2], 1.0); + } else { + normal_bl_to_tr = rot90(Geom::Point::polar(axonomgrid->angle_rad[2], 1.0)); + normal_tr_to_bl = rot90(Geom::Point::polar(-axonomgrid->angle_rad[0], 1.0)); + } } } if (horiz) { @@ -456,7 +458,7 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data) guide_cursor = gdk_cursor_new (GDK_EXCHANGE); gdk_window_set_cursor(gtk_widget_get_window (GTK_WIDGET(sp_desktop_canvas(desktop))), guide_cursor); #if GTK_CHECK_VERSION(3,0,0) - g_object_unref(guide_cursor); + g_object_unref(guide_cursor); #else gdk_cursor_unref(guide_cursor); #endif @@ -495,7 +497,7 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data) guide_cursor = gdk_cursor_new (GDK_EXCHANGE); gdk_window_set_cursor(gtk_widget_get_window (GTK_WIDGET(sp_desktop_canvas(desktop))), guide_cursor); #if GTK_CHECK_VERSION(3,0,0) - g_object_unref(guide_cursor); + g_object_unref(guide_cursor); #else gdk_cursor_unref(guide_cursor); #endif @@ -516,7 +518,7 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data) guide_cursor = gdk_cursor_new (GDK_EXCHANGE); gdk_window_set_cursor(gtk_widget_get_window (GTK_WIDGET(sp_desktop_canvas(desktop))), guide_cursor); #if GTK_CHECK_VERSION(3,0,0) - g_object_unref(guide_cursor); + g_object_unref(guide_cursor); #else gdk_cursor_unref(guide_cursor); #endif diff --git a/src/display/nr-filter-image.cpp b/src/display/nr-filter-image.cpp index 5294a5ee0..16f126b9f 100644 --- a/src/display/nr-filter-image.cpp +++ b/src/display/nr-filter-image.cpp @@ -118,7 +118,7 @@ void FilterImage::render_cairo(FilterSlot &slot) /* TODO: If feImageHref is absolute, then use that (preferably handling the * case that it's not a file URI). Otherwise, go up the tree looking * for an xml:base attribute, and use that as the base URI for resolving - * the relative feImageHref URI. Otherwise, if document && document->base, + * the relative feImageHref URI. Otherwise, if document->base is valid, * then use that as the base URI. Otherwise, use feImageHref directly * (i.e. interpreting it as relative to our current working directory). * (See http://www.w3.org/TR/xmlbase/#resolution .) */ diff --git a/src/ege-color-prof-tracker.cpp b/src/ege-color-prof-tracker.cpp index 81aee087e..c0e095a98 100644 --- a/src/ege-color-prof-tracker.cpp +++ b/src/ege-color-prof-tracker.cpp @@ -263,26 +263,27 @@ void ege_color_prof_tracker_get_profile( EgeColorProfTracker const * tracker, gp { gpointer dataPos = 0; guint dataLen = 0; - if ( tracker && tracker->private_data->_target ) { - GdkScreen* screen = gtk_widget_get_screen(tracker->private_data->_target); - GSList* curr = tracked_screens; - while ( curr ) { - ScreenTrack* screenTrack = (ScreenTrack*)curr->data; - if ( screenTrack->screen == screen ) { - if ( tracker->private_data->_monitor >= 0 && tracker->private_data->_monitor < (gint)screenTrack->profiles->len ) { - GByteArray* gba = (GByteArray*)g_ptr_array_index( screenTrack->profiles, tracker->private_data->_monitor ); - if ( gba ) { - dataPos = gba->data; - dataLen = gba->len; + if (tracker) { + if (tracker->private_data->_target ) { + GdkScreen* screen = gtk_widget_get_screen(tracker->private_data->_target); + GSList* curr = tracked_screens; + while ( curr ) { + ScreenTrack* screenTrack = static_cast<ScreenTrack*>(curr->data); + if ( screenTrack->screen == screen ) { + if ( tracker->private_data->_monitor >= 0 && tracker->private_data->_monitor < (static_cast<gint>(screenTrack->profiles->len))) { + GByteArray* gba = static_cast<GByteArray*>(g_ptr_array_index(screenTrack->profiles, tracker->private_data->_monitor)); + if ( gba ) { + dataPos = gba->data; + dataLen = gba->len; + } + } else { + g_warning("No profile data tracked for the specified item."); } - } else { - g_warning("No profile data tracked for the specified item."); + break; } - break; + curr = g_slist_next(curr); } - curr = g_slist_next(curr); } - } if ( ptr ) { *ptr = dataPos; diff --git a/src/widgets/gradient-vector.cpp b/src/widgets/gradient-vector.cpp index 8348f7045..60436c404 100644 --- a/src/widgets/gradient-vector.cpp +++ b/src/widgets/gradient-vector.cpp @@ -109,13 +109,13 @@ static void sp_gradient_vector_selector_class_init(SPGradientVectorSelectorClass parent_class = static_cast<GtkVBoxClass*>(g_type_class_peek_parent(klass)); signals[VECTOR_SET] = g_signal_new( "vector_set", - G_TYPE_FROM_CLASS(object_class), - G_SIGNAL_RUN_LAST, + G_TYPE_FROM_CLASS(object_class), + G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET(SPGradientVectorSelectorClass, vector_set), - NULL, NULL, - g_cclosure_marshal_VOID__POINTER, - G_TYPE_NONE, 1, - G_TYPE_POINTER); + NULL, NULL, + g_cclosure_marshal_VOID__POINTER, + G_TYPE_NONE, 1, + G_TYPE_POINTER); object_class->destroy = sp_gradient_vector_selector_destroy; } @@ -605,7 +605,7 @@ static void sp_grad_edit_combo_box_changed (GtkComboBox * /*widget*/, GtkWidget blocked = TRUE; - SPColorSelector *csel = (SPColorSelector*)g_object_get_data(G_OBJECT(tbl), "cselector"); + SPColorSelector *csel = static_cast<SPColorSelector*>(g_object_get_data(G_OBJECT(tbl), "cselector")); // set its color, from the stored array csel->base->setColorAlpha( stop->getEffectiveColor(), stop->opacity ); GtkWidget *offspin = GTK_WIDGET(g_object_get_data(G_OBJECT(tbl), "offspn")); @@ -1137,10 +1137,10 @@ static void sp_gradient_vector_widget_destroy(GtkObject *object, gpointer /*data release_connection->disconnect(); modified_connection->disconnect(); sp_signal_disconnect_by_data(gradient, object); - } - if (gradient && gradient->getRepr()) { - sp_repr_remove_listener_by_data(gradient->getRepr(), object); + if (gradient->getRepr()) { + sp_repr_remove_listener_by_data(gradient->getRepr(), object); + } } } diff --git a/src/widgets/sp-color-icc-selector.cpp b/src/widgets/sp-color-icc-selector.cpp index 844ba0020..0c40eff66 100644 --- a/src/widgets/sp-color-icc-selector.cpp +++ b/src/widgets/sp-color-icc-selector.cpp @@ -447,7 +447,7 @@ sp_color_icc_selector_new (void) { SPColorICCSelector *csel; - csel = (SPColorICCSelector*)g_object_new (SP_TYPE_COLOR_ICC_SELECTOR, NULL); + csel = static_cast<SPColorICCSelector*>(g_object_new (SP_TYPE_COLOR_ICC_SELECTOR, NULL)); return GTK_WIDGET (csel); } @@ -653,30 +653,32 @@ void ColorICCSelector::_colorChanged() _fixupNeeded = 0; gtk_widget_set_sensitive( _fixupBtn, FALSE ); - if ( _prof && _prof->getTransfToSRGB8() ) { - cmsUInt16Number tmp[4]; - for ( guint i = 0; i < _profChannelCount; i++ ) { - gdouble val = 0.0; - if ( _color.icc->colors.size() > i ) { - if ( _fooScales[i] == 256 ) { - val = (_color.icc->colors[i] + 128.0) / static_cast<gdouble>(_fooScales[i]); - } else { - val = _color.icc->colors[i] / static_cast<gdouble>(_fooScales[i]); + if (_prof) { + if (_prof->getTransfToSRGB8() ) { + cmsUInt16Number tmp[4]; + for ( guint i = 0; i < _profChannelCount; i++ ) { + gdouble val = 0.0; + if ( _color.icc->colors.size() > i ) { + if ( _fooScales[i] == 256 ) { + val = (_color.icc->colors[i] + 128.0) / static_cast<gdouble>(_fooScales[i]); + } else { + val = _color.icc->colors[i] / static_cast<gdouble>(_fooScales[i]); + } } + tmp[i] = val * 0x0ffff; } - tmp[i] = val * 0x0ffff; - } - guchar post[4] = {0,0,0,0}; - cmsHTRANSFORM trans = _prof->getTransfToSRGB8(); - if ( trans ) { - cmsDoTransform( trans, tmp, post, 1 ); - guint32 other = SP_RGBA32_U_COMPOSE(post[0], post[1], post[2], 255 ); - if ( other != _color.toRGBA32(255) ) { - _fixupNeeded = other; - gtk_widget_set_sensitive( _fixupBtn, TRUE ); + guchar post[4] = {0,0,0,0}; + cmsHTRANSFORM trans = _prof->getTransfToSRGB8(); + if ( trans ) { + cmsDoTransform( trans, tmp, post, 1 ); + guint32 other = SP_RGBA32_U_COMPOSE(post[0], post[1], post[2], 255 ); + if ( other != _color.toRGBA32(255) ) { + _fixupNeeded = other; + gtk_widget_set_sensitive( _fixupBtn, TRUE ); #ifdef DEBUG_LCMS - g_message("Color needs to change 0x%06x to 0x%06x", _color.toRGBA32(255) >> 8, other >> 8 ); + g_message("Color needs to change 0x%06x to 0x%06x", _color.toRGBA32(255) >> 8, other >> 8 ); #endif // DEBUG_LCMS + } } } } @@ -790,30 +792,32 @@ void ColorICCSelector::_updateSliders( gint ignore ) gtk_adjustment_set_value( _fooAdj[i], val ); } - if ( _prof && _prof->getTransfToSRGB8() ) { - for ( guint i = 0; i < _profChannelCount; i++ ) { - if ( static_cast<gint>(i) != ignore ) { - cmsUInt16Number* scratch = getScratch(); - cmsUInt16Number filler[4] = {0, 0, 0, 0}; - for ( guint j = 0; j < _profChannelCount; j++ ) { - filler[j] = 0x0ffff * ColorScales::getScaled( _fooAdj[j] ); - } - - cmsUInt16Number* p = scratch; - for ( guint x = 0; x < 1024; x++ ) { + if ( _prof) { + if (_prof->getTransfToSRGB8() ) { + for ( guint i = 0; i < _profChannelCount; i++ ) { + if ( static_cast<gint>(i) != ignore ) { + cmsUInt16Number* scratch = getScratch(); + cmsUInt16Number filler[4] = {0, 0, 0, 0}; for ( guint j = 0; j < _profChannelCount; j++ ) { - if ( j == i ) { - *p++ = x * 0x0ffff / 1024; - } else { - *p++ = filler[j]; + filler[j] = 0x0ffff * ColorScales::getScaled( _fooAdj[j] ); + } + + cmsUInt16Number* p = scratch; + for ( guint x = 0; x < 1024; x++ ) { + for ( guint j = 0; j < _profChannelCount; j++ ) { + if ( j == i ) { + *p++ = x * 0x0ffff / 1024; + } else { + *p++ = filler[j]; + } } } - } - - cmsHTRANSFORM trans = _prof->getTransfToSRGB8(); - if ( trans ) { - cmsDoTransform( trans, scratch, _fooMap[i], 1024 ); - sp_color_slider_set_map( SP_COLOR_SLIDER(_fooSlider[i]), _fooMap[i] ); + + cmsHTRANSFORM trans = _prof->getTransfToSRGB8(); + if ( trans ) { + cmsDoTransform( trans, scratch, _fooMap[i], 1024 ); + sp_color_slider_set_map( SP_COLOR_SLIDER(_fooSlider[i]), _fooMap[i] ); + } } } } diff --git a/src/xml/composite-node-observer.cpp b/src/xml/composite-node-observer.cpp index 36fe469de..7343ab1a8 100644 --- a/src/xml/composite-node-observer.cpp +++ b/src/xml/composite-node-observer.cpp @@ -277,7 +277,13 @@ struct vector_data_matches { bool operator()(NodeObserver const &observer) { VectorNodeObserver const *vo=dynamic_cast<VectorNodeObserver const *>(&observer); - return vo && vo->data == data; + bool OK = false; + if (vo) { + if (vo && vo->data == data) { + OK = true; + } + } + return OK; } }; diff --git a/src/xml/event.cpp b/src/xml/event.cpp index 23251eac6..9a760ccc5 100644 --- a/src/xml/event.cpp +++ b/src/xml/event.cpp @@ -32,246 +32,247 @@ int Inkscape::XML::Event::_next_serial=0; void sp_repr_begin_transaction (Inkscape::XML::Document *doc) { - using Inkscape::Debug::SimpleEvent; - using Inkscape::Debug::EventTracker; - using Inkscape::Debug::Event; + using Inkscape::Debug::SimpleEvent; + using Inkscape::Debug::EventTracker; + using Inkscape::Debug::Event; - EventTracker<SimpleEvent<Event::XML> > tracker("begin-transaction"); + EventTracker<SimpleEvent<Event::XML> > tracker("begin-transaction"); - g_assert(doc != NULL); - doc->beginTransaction(); + g_assert(doc != NULL); + doc->beginTransaction(); } void sp_repr_rollback (Inkscape::XML::Document *doc) { - using Inkscape::Debug::SimpleEvent; - using Inkscape::Debug::EventTracker; - using Inkscape::Debug::Event; + using Inkscape::Debug::SimpleEvent; + using Inkscape::Debug::EventTracker; + using Inkscape::Debug::Event; - EventTracker<SimpleEvent<Event::XML> > tracker("rollback"); + EventTracker<SimpleEvent<Event::XML> > tracker("rollback"); - g_assert(doc != NULL); - doc->rollback(); + g_assert(doc != NULL); + doc->rollback(); } void sp_repr_commit (Inkscape::XML::Document *doc) { - using Inkscape::Debug::SimpleEvent; - using Inkscape::Debug::EventTracker; - using Inkscape::Debug::Event; + using Inkscape::Debug::SimpleEvent; + using Inkscape::Debug::EventTracker; + using Inkscape::Debug::Event; - EventTracker<SimpleEvent<Event::XML> > tracker("commit"); + EventTracker<SimpleEvent<Event::XML> > tracker("commit"); - g_assert(doc != NULL); - doc->commit(); + g_assert(doc != NULL); + doc->commit(); } Inkscape::XML::Event * sp_repr_commit_undoable (Inkscape::XML::Document *doc) { - using Inkscape::Debug::SimpleEvent; - using Inkscape::Debug::EventTracker; - using Inkscape::Debug::Event; + using Inkscape::Debug::SimpleEvent; + using Inkscape::Debug::EventTracker; + using Inkscape::Debug::Event; - EventTracker<SimpleEvent<Event::XML> > tracker("commit"); + EventTracker<SimpleEvent<Event::XML> > tracker("commit"); - g_assert(doc != NULL); - return doc->commitUndoable(); + g_assert(doc != NULL); + return doc->commitUndoable(); } namespace { class LogPerformer : public Inkscape::XML::NodeObserver { public: - typedef Inkscape::XML::Node Node; - - static LogPerformer &instance() { - static LogPerformer singleton; - return singleton; - } - - void notifyChildAdded(Node &parent, Node &child, Node *ref) { - parent.addChild(&child, ref); - } - - void notifyChildRemoved(Node &parent, Node &child, Node */*old_ref*/) { - parent.removeChild(&child); - } - - void notifyChildOrderChanged(Node &parent, Node &child, - Node */*old_ref*/, Node *new_ref) - { - parent.changeOrder(&child, new_ref); - } - - void notifyAttributeChanged(Node &node, GQuark name, - Inkscape::Util::ptr_shared<char> /*old_value*/, - Inkscape::Util::ptr_shared<char> new_value) - { - node.setAttribute(g_quark_to_string(name), new_value); - } - - void notifyContentChanged(Node &node, - Inkscape::Util::ptr_shared<char> /*old_value*/, - Inkscape::Util::ptr_shared<char> new_value) - { - node.setContent(new_value); - } + typedef Inkscape::XML::Node Node; + + static LogPerformer &instance() { + static LogPerformer singleton; + return singleton; + } + + void notifyChildAdded(Node &parent, Node &child, Node *ref) { + parent.addChild(&child, ref); + } + + void notifyChildRemoved(Node &parent, Node &child, Node */*old_ref*/) { + parent.removeChild(&child); + } + + void notifyChildOrderChanged(Node &parent, Node &child, + Node */*old_ref*/, Node *new_ref) + { + parent.changeOrder(&child, new_ref); + } + + void notifyAttributeChanged(Node &node, GQuark name, + Inkscape::Util::ptr_shared<char> /*old_value*/, + Inkscape::Util::ptr_shared<char> new_value) + { + node.setAttribute(g_quark_to_string(name), new_value); + } + + void notifyContentChanged(Node &node, + Inkscape::Util::ptr_shared<char> /*old_value*/, + Inkscape::Util::ptr_shared<char> new_value) + { + node.setContent(new_value); + } }; } void Inkscape::XML::undo_log_to_observer( - Inkscape::XML::Event const *log, - Inkscape::XML::NodeObserver &observer + Inkscape::XML::Event const *log, + Inkscape::XML::NodeObserver &observer ) { - for ( Event const *action = log ; action ; action = action->next ) { - action->undoOne(observer); - } + for ( Event const *action = log ; action ; action = action->next ) { + action->undoOne(observer); + } } -void -sp_repr_undo_log (Inkscape::XML::Event *log) +void sp_repr_undo_log (Inkscape::XML::Event *log) { - using Inkscape::Debug::SimpleEvent; - using Inkscape::Debug::EventTracker; - using Inkscape::Debug::Event; + using Inkscape::Debug::SimpleEvent; + using Inkscape::Debug::EventTracker; + using Inkscape::Debug::Event; - EventTracker<SimpleEvent<Event::XML> > tracker("undo-log"); + EventTracker<SimpleEvent<Event::XML> > tracker("undo-log"); - if (log && log->repr) { - g_assert(!log->repr->document()->inTransaction()); - } + if (log) { + if (log->repr) { + g_assert(!log->repr->document()->inTransaction()); + } + } - Inkscape::XML::undo_log_to_observer(log, LogPerformer::instance()); + Inkscape::XML::undo_log_to_observer(log, LogPerformer::instance()); } void Inkscape::XML::EventAdd::_undoOne( - Inkscape::XML::NodeObserver &observer + Inkscape::XML::NodeObserver &observer ) const { - observer.notifyChildRemoved(*this->repr, *this->child, this->ref); + observer.notifyChildRemoved(*this->repr, *this->child, this->ref); } void Inkscape::XML::EventDel::_undoOne( - Inkscape::XML::NodeObserver &observer + Inkscape::XML::NodeObserver &observer ) const { - observer.notifyChildAdded(*this->repr, *this->child, this->ref); + observer.notifyChildAdded(*this->repr, *this->child, this->ref); } void Inkscape::XML::EventChgAttr::_undoOne( - Inkscape::XML::NodeObserver &observer + Inkscape::XML::NodeObserver &observer ) const { - observer.notifyAttributeChanged(*this->repr, this->key, this->newval, this->oldval); + observer.notifyAttributeChanged(*this->repr, this->key, this->newval, this->oldval); } void Inkscape::XML::EventChgContent::_undoOne( - Inkscape::XML::NodeObserver &observer + Inkscape::XML::NodeObserver &observer ) const { - observer.notifyContentChanged(*this->repr, this->newval, this->oldval); + observer.notifyContentChanged(*this->repr, this->newval, this->oldval); } void Inkscape::XML::EventChgOrder::_undoOne( - Inkscape::XML::NodeObserver &observer + Inkscape::XML::NodeObserver &observer ) const { - observer.notifyChildOrderChanged(*this->repr, *this->child, this->newref, this->oldref); + observer.notifyChildOrderChanged(*this->repr, *this->child, this->newref, this->oldref); } void Inkscape::XML::replay_log_to_observer( - Inkscape::XML::Event const *log, - Inkscape::XML::NodeObserver &observer + Inkscape::XML::Event const *log, + Inkscape::XML::NodeObserver &observer ) { - List<Inkscape::XML::Event const &> reversed = - reverse_list<Inkscape::XML::Event::ConstIterator>(log, NULL); - for ( ; reversed ; ++reversed ) { - reversed->replayOne(observer); - } + List<Inkscape::XML::Event const &> reversed = + reverse_list<Inkscape::XML::Event::ConstIterator>(log, NULL); + for ( ; reversed ; ++reversed ) { + reversed->replayOne(observer); + } } void sp_repr_replay_log (Inkscape::XML::Event *log) { - using Inkscape::Debug::SimpleEvent; - using Inkscape::Debug::EventTracker; - using Inkscape::Debug::Event; + using Inkscape::Debug::SimpleEvent; + using Inkscape::Debug::EventTracker; + using Inkscape::Debug::Event; - EventTracker<SimpleEvent<Event::XML> > tracker("replay-log"); + EventTracker<SimpleEvent<Event::XML> > tracker("replay-log"); - if (log) { - if (log->repr->document()) { - g_assert(!log->repr->document()->inTransaction()); - } - } + if (log) { + if (log->repr->document()) { + g_assert(!log->repr->document()->inTransaction()); + } + } - Inkscape::XML::replay_log_to_observer(log, LogPerformer::instance()); + Inkscape::XML::replay_log_to_observer(log, LogPerformer::instance()); } void Inkscape::XML::EventAdd::_replayOne( - Inkscape::XML::NodeObserver &observer + Inkscape::XML::NodeObserver &observer ) const { - observer.notifyChildAdded(*this->repr, *this->child, this->ref); + observer.notifyChildAdded(*this->repr, *this->child, this->ref); } void Inkscape::XML::EventDel::_replayOne( - Inkscape::XML::NodeObserver &observer + Inkscape::XML::NodeObserver &observer ) const { - observer.notifyChildRemoved(*this->repr, *this->child, this->ref); + observer.notifyChildRemoved(*this->repr, *this->child, this->ref); } void Inkscape::XML::EventChgAttr::_replayOne( - Inkscape::XML::NodeObserver &observer + Inkscape::XML::NodeObserver &observer ) const { - observer.notifyAttributeChanged(*this->repr, this->key, this->oldval, this->newval); + observer.notifyAttributeChanged(*this->repr, this->key, this->oldval, this->newval); } void Inkscape::XML::EventChgContent::_replayOne( - Inkscape::XML::NodeObserver &observer + Inkscape::XML::NodeObserver &observer ) const { - observer.notifyContentChanged(*this->repr, this->oldval, this->newval); + observer.notifyContentChanged(*this->repr, this->oldval, this->newval); } void Inkscape::XML::EventChgOrder::_replayOne( - Inkscape::XML::NodeObserver &observer + Inkscape::XML::NodeObserver &observer ) const { - observer.notifyChildOrderChanged(*this->repr, *this->child, this->oldref, this->newref); + observer.notifyChildOrderChanged(*this->repr, *this->child, this->oldref, this->newref); } Inkscape::XML::Event * sp_repr_coalesce_log (Inkscape::XML::Event *a, Inkscape::XML::Event *b) { - Inkscape::XML::Event *action; - Inkscape::XML::Event **prev_ptr; + Inkscape::XML::Event *action; + Inkscape::XML::Event **prev_ptr; - if (!b) return a; - if (!a) return b; + if (!b) return a; + if (!a) return b; - /* find the earliest action in the second log */ - /* (also noting the pointer that references it, so we can - * replace it later) */ - prev_ptr = &b; - for ( action = b ; action->next ; action = action->next ) { - prev_ptr = &action->next; - } + /* find the earliest action in the second log */ + /* (also noting the pointer that references it, so we can + * replace it later) */ + prev_ptr = &b; + for ( action = b ; action->next ; action = action->next ) { + prev_ptr = &action->next; + } - /* add the first log after it */ - action->next = a; + /* add the first log after it */ + action->next = a; - /* optimize the result */ - *prev_ptr = action->optimizeOne(); + /* optimize the result */ + *prev_ptr = action->optimizeOne(); - return b; + return b; } void sp_repr_free_log (Inkscape::XML::Event *log) { - while (log) { - Inkscape::XML::Event *action; - action = log; - log = action->next; - delete action; - } + while (log) { + Inkscape::XML::Event *action; + action = log; + log = action->next; + delete action; + } } namespace { @@ -280,199 +281,211 @@ template <typename T> struct ActionRelations; template <> struct ActionRelations<Inkscape::XML::EventAdd> { - typedef Inkscape::XML::EventDel Opposite; + typedef Inkscape::XML::EventDel Opposite; }; template <> struct ActionRelations<Inkscape::XML::EventDel> { - typedef Inkscape::XML::EventAdd Opposite; + typedef Inkscape::XML::EventAdd Opposite; }; template <typename A> Inkscape::XML::Event *cancel_add_or_remove(A *action) { - typedef typename ActionRelations<A>::Opposite Opposite; - Opposite *opposite=dynamic_cast<Opposite *>(action->next); - - if ( opposite && opposite->repr == action->repr && - opposite->child == action->child && - opposite->ref == action->ref ) - { - Inkscape::XML::Event *remaining=opposite->next; - - delete opposite; - delete action; - - return remaining; - } else { - return action; - } + typedef typename ActionRelations<A>::Opposite Opposite; + Opposite *opposite=dynamic_cast<Opposite *>(action->next); + + bool OK = false; + if (opposite){ + if (opposite->repr == action->repr && + opposite->child == action->child && + opposite->ref == action->ref ) { + OK = true; + } + } + if (OK){ + Inkscape::XML::Event *remaining=opposite->next; + + delete opposite; + delete action; + + return remaining; + } else { + return action; + } } - } Inkscape::XML::Event *Inkscape::XML::EventAdd::_optimizeOne() { - return cancel_add_or_remove(this); + return cancel_add_or_remove(this); } Inkscape::XML::Event *Inkscape::XML::EventDel::_optimizeOne() { - return cancel_add_or_remove(this); + return cancel_add_or_remove(this); } Inkscape::XML::Event *Inkscape::XML::EventChgAttr::_optimizeOne() { - Inkscape::XML::EventChgAttr *chg_attr=dynamic_cast<Inkscape::XML::EventChgAttr *>(this->next); - - /* consecutive chgattrs on the same key can be combined */ - if ( chg_attr && chg_attr->repr == this->repr && - chg_attr->key == this->key ) - { - /* replace our oldval with the prior action's */ - this->oldval = chg_attr->oldval; - - /* discard the prior action */ - this->next = chg_attr->next; - delete chg_attr; - } - - return this; + Inkscape::XML::EventChgAttr *chg_attr=dynamic_cast<Inkscape::XML::EventChgAttr *>(this->next); + + /* consecutive chgattrs on the same key can be combined */ + if ( chg_attr) { + if ( chg_attr->repr == this->repr && + chg_attr->key == this->key ) + { + /* replace our oldval with the prior action's */ + this->oldval = chg_attr->oldval; + + /* discard the prior action */ + this->next = chg_attr->next; + delete chg_attr; + } + } + + return this; } Inkscape::XML::Event *Inkscape::XML::EventChgContent::_optimizeOne() { - Inkscape::XML::EventChgContent *chg_content=dynamic_cast<Inkscape::XML::EventChgContent *>(this->next); + Inkscape::XML::EventChgContent *chg_content=dynamic_cast<Inkscape::XML::EventChgContent *>(this->next); - /* consecutive content changes can be combined */ - if ( chg_content && chg_content->repr == this->repr ) { - /* replace our oldval with the prior action's */ - this->oldval = chg_content->oldval; + /* consecutive content changes can be combined */ + if (chg_content) { + if (chg_content->repr == this->repr ) { + /* replace our oldval with the prior action's */ + this->oldval = chg_content->oldval; - /* get rid of the prior action*/ - this->next = chg_content->next; - delete chg_content; - } + /* get rid of the prior action*/ + this->next = chg_content->next; + delete chg_content; + } + } - return this; + return this; } Inkscape::XML::Event *Inkscape::XML::EventChgOrder::_optimizeOne() { - Inkscape::XML::EventChgOrder *chg_order=dynamic_cast<Inkscape::XML::EventChgOrder *>(this->next); - - /* consecutive chgorders for the same child may be combined or - * canceled out */ - if ( chg_order && chg_order->repr == this->repr && - chg_order->child == this->child ) - { - if ( chg_order->oldref == this->newref ) { - /* cancel them out */ - Inkscape::XML::Event *after=chg_order->next; - - delete chg_order; - delete this; - - return after; - } else { - /* combine them */ - this->oldref = chg_order->oldref; - - /* get rid of the other one */ - this->next = chg_order->next; - delete chg_order; - - return this; - } - } else { - return this; - } + Inkscape::XML::EventChgOrder *chg_order=dynamic_cast<Inkscape::XML::EventChgOrder *>(this->next); + + /* consecutive chgorders for the same child may be combined or + * canceled out */ + bool OK = false; + if (chg_order) { + if (chg_order->repr == this->repr && + chg_order->child == this->child ){ + OK = true; + } + } + if (OK) { + if ( chg_order->oldref == this->newref ) { + /* cancel them out */ + Inkscape::XML::Event *after=chg_order->next; + + delete chg_order; + delete this; + + return after; + } else { + /* combine them */ + this->oldref = chg_order->oldref; + + /* get rid of the other one */ + this->next = chg_order->next; + delete chg_order; + + return this; + } + } else { + return this; + } } namespace { class LogPrinter : public Inkscape::XML::NodeObserver { public: - typedef Inkscape::XML::Node Node; - - static LogPrinter &instance() { - static LogPrinter singleton; - return singleton; - } - - static Glib::ustring node_to_string(Node const &node) { - Glib::ustring result; - char const *type_name=NULL; - switch (node.type()) { - case Inkscape::XML::DOCUMENT_NODE: - type_name = "Document"; - break; - case Inkscape::XML::ELEMENT_NODE: - type_name = "Element"; - break; - case Inkscape::XML::TEXT_NODE: - type_name = "Text"; - break; - case Inkscape::XML::COMMENT_NODE: - type_name = "Comment"; - break; - default: - g_assert_not_reached(); - } - char buffer[40]; - result.append("#<"); - result.append(type_name); - result.append(":"); - snprintf(buffer, 40, "0x%p", &node); - result.append(buffer); - result.append(">"); - - return result; - } - - static Glib::ustring ref_to_string(Node *ref) { - if (ref) { - return node_to_string(*ref); - } else { - return "beginning"; - } - } - - void notifyChildAdded(Node &parent, Node &child, Node *ref) { - g_warning("Event: Added %s to %s after %s", node_to_string(parent).c_str(), node_to_string(child).c_str(), ref_to_string(ref).c_str()); - } - - void notifyChildRemoved(Node &parent, Node &child, Node */*ref*/) { - g_warning("Event: Removed %s from %s", node_to_string(parent).c_str(), node_to_string(child).c_str()); - } - - void notifyChildOrderChanged(Node &parent, Node &child, - Node */*old_ref*/, Node *new_ref) - { - g_warning("Event: Moved %s after %s in %s", node_to_string(child).c_str(), ref_to_string(new_ref).c_str(), node_to_string(parent).c_str()); - } - - void notifyAttributeChanged(Node &node, GQuark name, - Inkscape::Util::ptr_shared<char> /*old_value*/, - Inkscape::Util::ptr_shared<char> new_value) - { - if (new_value) { - g_warning("Event: Set attribute %s to \"%s\" on %s", g_quark_to_string(name), new_value.pointer(), node_to_string(node).c_str()); - } else { - g_warning("Event: Unset attribute %s on %s", g_quark_to_string(name), node_to_string(node).c_str()); - } - } - - void notifyContentChanged(Node &node, - Inkscape::Util::ptr_shared<char> /*old_value*/, - Inkscape::Util::ptr_shared<char> new_value) - { - if (new_value) { - g_warning("Event: Set content of %s to \"%s\"", node_to_string(node).c_str(), new_value.pointer()); - } else { - g_warning("Event: Unset content of %s", node_to_string(node).c_str()); - } - } + typedef Inkscape::XML::Node Node; + + static LogPrinter &instance() { + static LogPrinter singleton; + return singleton; + } + + static Glib::ustring node_to_string(Node const &node) { + Glib::ustring result; + char const *type_name=NULL; + switch (node.type()) { + case Inkscape::XML::DOCUMENT_NODE: + type_name = "Document"; + break; + case Inkscape::XML::ELEMENT_NODE: + type_name = "Element"; + break; + case Inkscape::XML::TEXT_NODE: + type_name = "Text"; + break; + case Inkscape::XML::COMMENT_NODE: + type_name = "Comment"; + break; + default: + g_assert_not_reached(); + } + char buffer[40]; + result.append("#<"); + result.append(type_name); + result.append(":"); + snprintf(buffer, 40, "0x%p", &node); + result.append(buffer); + result.append(">"); + + return result; + } + + static Glib::ustring ref_to_string(Node *ref) { + if (ref) { + return node_to_string(*ref); + } else { + return "beginning"; + } + } + + void notifyChildAdded(Node &parent, Node &child, Node *ref) { + g_warning("Event: Added %s to %s after %s", node_to_string(parent).c_str(), node_to_string(child).c_str(), ref_to_string(ref).c_str()); + } + + void notifyChildRemoved(Node &parent, Node &child, Node */*ref*/) { + g_warning("Event: Removed %s from %s", node_to_string(parent).c_str(), node_to_string(child).c_str()); + } + + void notifyChildOrderChanged(Node &parent, Node &child, + Node */*old_ref*/, Node *new_ref) + { + g_warning("Event: Moved %s after %s in %s", node_to_string(child).c_str(), ref_to_string(new_ref).c_str(), node_to_string(parent).c_str()); + } + + void notifyAttributeChanged(Node &node, GQuark name, + Inkscape::Util::ptr_shared<char> /*old_value*/, + Inkscape::Util::ptr_shared<char> new_value) + { + if (new_value) { + g_warning("Event: Set attribute %s to \"%s\" on %s", g_quark_to_string(name), new_value.pointer(), node_to_string(node).c_str()); + } else { + g_warning("Event: Unset attribute %s on %s", g_quark_to_string(name), node_to_string(node).c_str()); + } + } + + void notifyContentChanged(Node &node, + Inkscape::Util::ptr_shared<char> /*old_value*/, + Inkscape::Util::ptr_shared<char> new_value) + { + if (new_value) { + g_warning("Event: Set content of %s to \"%s\"", node_to_string(node).c_str(), new_value.pointer()); + } else { + g_warning("Event: Unset content of %s", node_to_string(node).c_str()); + } + } }; } -void -sp_repr_debug_print_log(Inkscape::XML::Event const *log) { - Inkscape::XML::replay_log_to_observer(log, LogPrinter::instance()); +void sp_repr_debug_print_log(Inkscape::XML::Event const *log) { + Inkscape::XML::replay_log_to_observer(log, LogPrinter::instance()); } diff --git a/src/xml/helper-observer.cpp b/src/xml/helper-observer.cpp index ce902ba75..c54dd8e74 100644 --- a/src/xml/helper-observer.cpp +++ b/src/xml/helper-observer.cpp @@ -13,10 +13,16 @@ void SignalObserver::set(SPObject* o) { // XML Tree being used direcly in this function in the following code // while it shouldn't be - if(_oldsel && _oldsel->getRepr()) - _oldsel->getRepr()->removeObserver(*this); - if(o && o->getRepr()) - o->getRepr()->addObserver(*this); + if(_oldsel) { + if (_oldsel->getRepr()) { + _oldsel->getRepr()->removeObserver(*this); + } + } + if(o) { + if (o->getRepr()) { + o->getRepr()->addObserver(*this); + } + } _oldsel = o; } diff --git a/src/xml/repr-io.cpp b/src/xml/repr-io.cpp index b85e58899..29a5b4a78 100644 --- a/src/xml/repr-io.cpp +++ b/src/xml/repr-io.cpp @@ -471,13 +471,19 @@ Document *sp_repr_do_read (xmlDocPtr doc, const gchar *default_ns) gint sp_repr_qualified_name (gchar *p, gint len, xmlNsPtr ns, const xmlChar *name, const gchar */*default_ns*/, GHashTable *prefix_map) { const xmlChar *prefix; - if ( ns && ns->href ) { - prefix = reinterpret_cast<const xmlChar*>( sp_xml_ns_uri_prefix(reinterpret_cast<const gchar*>(ns->href), - reinterpret_cast<const char*>(ns->prefix)) ); - void* p0 = reinterpret_cast<gpointer>(const_cast<xmlChar *>(prefix)); - void* p1 = reinterpret_cast<gpointer>(const_cast<xmlChar *>(ns->href)); - g_hash_table_insert( prefix_map, p0, p1 ); - } else { + if (ns){ + if (ns->href ) { + prefix = reinterpret_cast<const xmlChar*>( sp_xml_ns_uri_prefix(reinterpret_cast<const gchar*>(ns->href), + reinterpret_cast<const char*>(ns->prefix)) ); + void* p0 = reinterpret_cast<gpointer>(const_cast<xmlChar *>(prefix)); + void* p1 = reinterpret_cast<gpointer>(const_cast<xmlChar *>(ns->href)); + g_hash_table_insert( prefix_map, p0, p1 ); + } + else { + prefix = NULL; + } + } + else { prefix = NULL; } @@ -600,10 +606,10 @@ Glib::ustring sp_repr_save_buf(Document *doc) sp_repr_save_writer(doc, &outs, SP_INKSCAPE_NS_URI, 0, 0); - outs.close(); - Glib::ustring buf = souts.getString(); + outs.close(); + Glib::ustring buf = souts.getString(); - return buf; + return buf; } diff --git a/src/xml/repr-sorting.cpp b/src/xml/repr-sorting.cpp index 056236d33..fd485925b 100644 --- a/src/xml/repr-sorting.cpp +++ b/src/xml/repr-sorting.cpp @@ -13,9 +13,14 @@ Inkscape::XML::Node const *LCA(Inkscape::XML::Node const *a, Inkscape::XML::Node { using Inkscape::Algorithms::longest_common_suffix; Inkscape::XML::Node const *ancestor = longest_common_suffix<Inkscape::XML::NodeConstParentIterator>( - a, b, NULL, &same_repr - ); - if ( ancestor && ancestor->type() != Inkscape::XML::DOCUMENT_NODE ) { + a, b, NULL, &same_repr); + bool OK = false; + if (ancestor) { + if (ancestor->type() != Inkscape::XML::DOCUMENT_NODE) { + OK = true; + } + } + if ( OK ) { return ancestor; } else { return NULL; diff --git a/src/xml/repr-util.cpp b/src/xml/repr-util.cpp index 6899e77ee..5b8ab12ae 100644 --- a/src/xml/repr-util.cpp +++ b/src/xml/repr-util.cpp @@ -261,8 +261,13 @@ gchar const *sp_xml_ns_uri_prefix(gchar const *uri, gchar const *suggested) GQuark const prefix_key=g_quark_from_string(suggested); SPXMLNs *found=namespaces; - while ( found && found->prefix != prefix_key ) { - found = found->next; + while (found) { + if (found->prefix != prefix_key) { + found = found->next; + } + else { + break; + } } if (found) { // prefix already used? |
