From 05b668b4ec1637cb3343020fcbaee5843f3a1bff Mon Sep 17 00:00:00 2001 From: Harald Sitter Date: Tue, 7 Nov 2017 10:59:15 +0100 Subject: [PATCH] properly use passed begin/end function ptrs to get respective iterators 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 --- COPYING | 3 ++- rice/detail/Iterator.hpp | 4 ++-- test/test_Class.cpp | 8 +++++--- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/COPYING b/COPYING index 9dd7defa4..c314e79c8 100644 --- a/COPYING +++ b/COPYING @@ -1,5 +1,6 @@ Copyright (C) 2017 Paul Brannan , - Jason Roelofs + Jason Roelofs , + Harald Sitter Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions diff --git a/rice/detail/Iterator.hpp b/rice/detail/Iterator.hpp index a6181cd6c..613c7ba31 100644 --- a/rice/detail/Iterator.hpp +++ b/rice/detail/Iterator.hpp @@ -48,8 +48,8 @@ class Iterator_Impl virtual VALUE call_impl(VALUE self) { Data_Object 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)); diff --git a/test/test_Class.cpp b/test/test_Class.cpp index 760fbaec2..8c57106e8 100644 --- a/test/test_Class.cpp +++ b/test/test_Class.cpp @@ -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_; @@ -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::free, container);