Skip to content

Commit

Permalink
properly use passed begin/end function ptrs to get respective iterators
Browse files Browse the repository at this point in the history
previously we'd ignore the passed ptrs and always call `begin()`/`end()`
making the ptrs entirely useless.
the new calls properly go to the passed functions on the object we want to
iter on.

adjusted iter test to make sure this continues working

Fixes #103
  • Loading branch information
hsitter committed Nov 7, 2017
1 parent a015ecd commit 05b668b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
3 changes: 2 additions & 1 deletion COPYING
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Copyright (C) 2017 Paul Brannan <pbrannan@atdesk.com>,
Jason Roelofs <jasongroelofs@gmail.com>
Jason Roelofs <jasongroelofs@gmail.com>,
Harald Sitter <sitter@kde.org>

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
Expand Down
4 changes: 2 additions & 2 deletions rice/detail/Iterator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ class Iterator_Impl
virtual VALUE call_impl(VALUE self)
{
Data_Object<T> obj(self, data_type_);
Iterator_T it = obj->begin();
Iterator_T end = obj->end();
Iterator_T it = (*obj.*begin_)();
Iterator_T end = (*obj.*end_)();
for(; it != end; ++it)
{
Rice::protect(rb_yield, to_ruby(*it));
Expand Down
8 changes: 5 additions & 3 deletions test/test_Class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,10 @@ class Container
{
}

int * begin() { return array_; }
int * end() { return array_ + length_; }
// Custom names to make sure we call the function pointers rather than
// expectable default names.
int * beginFoo() { return array_; }
int * endBar() { return array_ + length_; }

private:
int * array_;
Expand All @@ -325,7 +327,7 @@ TESTCASE(define_iterator)
{
int array[] = { 1, 2, 3 };
Class c(anonymous_class());
c.define_iterator(&Container::begin, &Container::end);
c.define_iterator(&Container::beginFoo, &Container::endBar);
Container * container = new Container(array, 3);
Object wrapped_container = Data_Wrap_Struct(
c, 0, Default_Free_Function<Container>::free, container);
Expand Down

0 comments on commit 05b668b

Please sign in to comment.