librelist archives

« back to archive

Custom wrappers

Custom wrappers

From:
Edder
Date:
2011-07-21 @ 09:22
Hi all,

I noticed after an update my custom wrapper for Array to std::vector
stopped working. The source files are copied to the generated dir and
everything compiles fine, but I get the following error:
Unable to convert Array to std::vector<double, std::allocator<double>
> (ArgumentError)
My implementation is based on the tips in:
https://github.com/jameskilton/rbplusplus/issues/5 and

https://github.com/jameskilton/ogrerb/blob/master/wrappers/noise/code/custom_to_from_ruby.hpp
and like I said used to work fine.

I have the feeling it might be namespace related, but I tried adding
them to the namespace Rice and that only led to compilation problems.

custom_from_to_ruby.h:
#ifndef __CUSTOM_TO_RUBY_H__
#define __CUSTOM_TO_RUBY_H__

#include <rice/Object.hpp>
#include <rice/Array.hpp>
#include <rice/Hash.hpp>
#include <rice/String.hpp>
#include <rice/to_from_ruby.hpp>
#include <vector>
#include <map>
#include <iostream>

template<>
std::vector<double> from_ruby< std::vector<double> >(Rice::Object obj);
#endif



custom_from_to_ruby.cc:
#include "custom_from_to_ruby.h"

template<>
std::vector<double> from_ruby< std::vector<double> >(Rice::Object obj) {
  Rice::Array arr(obj);
  std::vector<double> vec;

  for (size_t i=0;i<arr.size();++i) {
      vec.push_back( from_ruby<double>( arr[i] ) );
  }

  return vec;
}

Any help would be appreciated,

Cheers, Edwin

Re: Custom wrappers

From:
Edder
Date:
2011-08-10 @ 10:54
Hi all,

Has anyone else the same issue or does is it likely to have something
to do with my setup? Like I said I did test it with some code that
used to work on older rbplusplus versions, but haven't investigated
further, so I might have missed something.

Cheers, Edwin

On 21 July 2011 10:22, Edder <edder@tkwsping.nl> wrote:
> Hi all,
>
> I noticed after an update my custom wrapper for Array to std::vector
> stopped working. The source files are copied to the generated dir and
> everything compiles fine, but I get the following error:
> Unable to convert Array to std::vector<double, std::allocator<double>
>> (ArgumentError)
> My implementation is based on the tips in:
> https://github.com/jameskilton/rbplusplus/issues/5 and
> 
https://github.com/jameskilton/ogrerb/blob/master/wrappers/noise/code/custom_to_from_ruby.hpp
> and like I said used to work fine.
>
> I have the feeling it might be namespace related, but I tried adding
> them to the namespace Rice and that only led to compilation problems.
>
> custom_from_to_ruby.h:
> #ifndef __CUSTOM_TO_RUBY_H__
> #define __CUSTOM_TO_RUBY_H__
>
> #include <rice/Object.hpp>
> #include <rice/Array.hpp>
> #include <rice/Hash.hpp>
> #include <rice/String.hpp>
> #include <rice/to_from_ruby.hpp>
> #include <vector>
> #include <map>
> #include <iostream>
>
> template<>
> std::vector<double> from_ruby< std::vector<double> >(Rice::Object obj);
> #endif
>
>
>
> custom_from_to_ruby.cc:
> #include "custom_from_to_ruby.h"
>
> template<>
> std::vector<double> from_ruby< std::vector<double> >(Rice::Object obj) {
>  Rice::Array arr(obj);
>  std::vector<double> vec;
>
>  for (size_t i=0;i<arr.size();++i) {
>      vec.push_back( from_ruby<double>( arr[i] ) );
>  }
>
>  return vec;
> }
>
> Any help would be appreciated,
>
> Cheers, Edwin
>

Re: [rice] Re: Custom wrappers

From:
Paul Brannan
Date:
2011-08-10 @ 12:26
to_ruby and from_ruby are intentionally not in the Rice namespace, so that
the user can specialize them.

My guess on this one is that the from_ruby template is getting instantiated
before the compiler sees your specialization.

If this is the case, then we need to find where from_ruby is getting
instantiated.  The first thing I notice is that you include a lot of
unnecessary headers.  Try removing them one at a time until you have a
minimal set of includes.

Also make sure you are including your custom header as early as possible in
your project.

Paul

On Wed, Aug 10, 2011 at 6:54 AM, Edder <edder@tkwsping.nl> wrote:

> Hi all,
>
> Has anyone else the same issue or does is it likely to have something
> to do with my setup? Like I said I did test it with some code that
> used to work on older rbplusplus versions, but haven't investigated
> further, so I might have missed something.
>
> Cheers, Edwin
>
> On 21 July 2011 10:22, Edder <edder@tkwsping.nl> wrote:
> > Hi all,
> >
> > I noticed after an update my custom wrapper for Array to std::vector
> > stopped working. The source files are copied to the generated dir and
> > everything compiles fine, but I get the following error:
> > Unable to convert Array to std::vector<double, std::allocator<double>
> >> (ArgumentError)
> > My implementation is based on the tips in:
> > https://github.com/jameskilton/rbplusplus/issues/5 and
> >
> 
https://github.com/jameskilton/ogrerb/blob/master/wrappers/noise/code/custom_to_from_ruby.hpp
> > and like I said used to work fine.
> >
> > I have the feeling it might be namespace related, but I tried adding
> > them to the namespace Rice and that only led to compilation problems.
> >
> > custom_from_to_ruby.h:
> > #ifndef __CUSTOM_TO_RUBY_H__
> > #define __CUSTOM_TO_RUBY_H__
> >
> > #include <rice/Object.hpp>
> > #include <rice/Array.hpp>
> > #include <rice/Hash.hpp>
> > #include <rice/String.hpp>
> > #include <rice/to_from_ruby.hpp>
> > #include <vector>
> > #include <map>
> > #include <iostream>
> >
> > template<>
> > std::vector<double> from_ruby< std::vector<double> >(Rice::Object obj);
> > #endif
> >
> >
> >
> > custom_from_to_ruby.cc:
> > #include "custom_from_to_ruby.h"
> >
> > template<>
> > std::vector<double> from_ruby< std::vector<double> >(Rice::Object obj) {
> >  Rice::Array arr(obj);
> >  std::vector<double> vec;
> >
> >  for (size_t i=0;i<arr.size();++i) {
> >      vec.push_back( from_ruby<double>( arr[i] ) );
> >  }
> >
> >  return vec;
> > }
> >
> > Any help would be appreciated,
> >
> > Cheers, Edwin
> >
>

Re: [rice] Re: Custom wrappers

From:
Edder
Date:
2011-08-10 @ 13:17
On 10 August 2011 13:26, Paul Brannan <curlypaul924@gmail.com> wrote:
> to_ruby and from_ruby are intentionally not in the Rice namespace, so that
> the user can specialize them.

That makes sense.

> My guess on this one is that the from_ruby template is getting instantiated
> before the compiler sees your specialization.
> If this is the case, then we need to find where from_ruby is getting
> instantiated.  The first thing I notice is that you include a lot of
> unnecessary headers.  Try removing them one at a time until you have a
> minimal set of includes.

I did that, but it made no difference (Rice/String.hpp, map and
iostream were not needed)

> Also make sure you are including your custom header as early as possible in
> your project.

The Makefile etc is automatically generated by rbplusplus and
automatically includes all header/source files specified in the
":include_source_dir =>" variable. The header is not explicitly
included from anywhere else in the project and as far as I know this
is not needed, since they will get linked into the final library file.
I did check that they are actually included in the compiled library
file by looking at the generated Makefile.

Cheers, Edwin

> Paul
>
> On Wed, Aug 10, 2011 at 6:54 AM, Edder <edder@tkwsping.nl> wrote:
>>
>> Hi all,
>>
>> Has anyone else the same issue or does is it likely to have something
>> to do with my setup? Like I said I did test it with some code that
>> used to work on older rbplusplus versions, but haven't investigated
>> further, so I might have missed something.
>>
>> Cheers, Edwin
>>
>> On 21 July 2011 10:22, Edder <edder@tkwsping.nl> wrote:
>> > Hi all,
>> >
>> > I noticed after an update my custom wrapper for Array to std::vector
>> > stopped working. The source files are copied to the generated dir and
>> > everything compiles fine, but I get the following error:
>> > Unable to convert Array to std::vector<double, std::allocator<double>
>> >> (ArgumentError)
>> > My implementation is based on the tips in:
>> > https://github.com/jameskilton/rbplusplus/issues/5 and
>> >
>> > 
https://github.com/jameskilton/ogrerb/blob/master/wrappers/noise/code/custom_to_from_ruby.hpp
>> > and like I said used to work fine.
>> >
>> > I have the feeling it might be namespace related, but I tried adding
>> > them to the namespace Rice and that only led to compilation problems.
>> >
>> > custom_from_to_ruby.h:
>> > #ifndef __CUSTOM_TO_RUBY_H__
>> > #define __CUSTOM_TO_RUBY_H__
>> >
>> > #include <rice/Object.hpp>
>> > #include <rice/Array.hpp>
>> > #include <rice/Hash.hpp>
>> > #include <rice/String.hpp>
>> > #include <rice/to_from_ruby.hpp>
>> > #include <vector>
>> > #include <map>
>> > #include <iostream>
>> >
>> > template<>
>> > std::vector<double> from_ruby< std::vector<double> >(Rice::Object obj);
>> > #endif
>> >
>> >
>> >
>> > custom_from_to_ruby.cc:
>> > #include "custom_from_to_ruby.h"
>> >
>> > template<>
>> > std::vector<double> from_ruby< std::vector<double> >(Rice::Object obj) {
>> >  Rice::Array arr(obj);
>> >  std::vector<double> vec;
>> >
>> >  for (size_t i=0;i<arr.size();++i) {
>> >      vec.push_back( from_ruby<double>( arr[i] ) );
>> >  }
>> >
>> >  return vec;
>> > }
>> >
>> > Any help would be appreciated,
>> >
>> > Cheers, Edwin
>> >
>
>

Re: [rice] Re: Custom wrappers

From:
Edder
Date:
2011-08-11 @ 09:22
On 10 August 2011 13:26, Paul Brannan <curlypaul924@gmail.com> wrote:
> My guess on this one is that the from_ruby template is getting instantiated
> before the compiler sees your specialization.
> If this is the case, then we need to find where from_ruby is getting
> instantiated.  The first thing I notice is that you include a lot of
> unnecessary headers.  Try removing them one at a time until you have a
> minimal set of includes.
> Also make sure you are including your custom header as early as possible in
> your project.

I did some more debugging on this and the problem seems to be that
rbplusplus only includes the custom wrappers in the "main file", i.e.
<project>.rb.cpp. If I also include the file in the file that actually
defines the method that accepts a std::vector<double> the wrappers do
work. So I guess it is a problem with rbplusplus/my knowledge of
rbplusplus. I will probably open a bug in rbplusplus describing the
issue.

> Paul

Re: [rice] Re: Custom wrappers

From:
Jason Roelofs
Date:
2011-08-11 @ 11:48
On Thu, Aug 11, 2011 at 5:22 AM, Edder <edder@tkwsping.nl> wrote:
> On 10 August 2011 13:26, Paul Brannan <curlypaul924@gmail.com> wrote:
>> My guess on this one is that the from_ruby template is getting instantiated
>> before the compiler sees your specialization.
>> If this is the case, then we need to find where from_ruby is getting
>> instantiated.  The first thing I notice is that you include a lot of
>> unnecessary headers.  Try removing them one at a time until you have a
>> minimal set of includes.
>> Also make sure you are including your custom header as early as possible in
>> your project.
>
> I did some more debugging on this and the problem seems to be that
> rbplusplus only includes the custom wrappers in the "main file", i.e.
> <project>.rb.cpp. If I also include the file in the file that actually
> defines the method that accepts a std::vector<double> the wrappers do
> work. So I guess it is a problem with rbplusplus/my knowledge of
> rbplusplus. I will probably open a bug in rbplusplus describing the
> issue.
>
>> Paul
>

Thanks for opening an issue, I'll take a look at what you've found and
continue the discussion there[1].

Jason

[1]https://github.com/jameskilton/rbplusplus/issues/13