can't really make the complete project available at present. That said, what you've done below (test.cpp) works for me as well. The difference is when I test from a c program (i.e test.c).

On 17/2/21 12:29 pm, Sutou Kouhei wrote:
Hi,

Could you provide a complete project that reproduces this
case? (For example, you create a GitHub repository,
prepare the repository to reproduces this case and share it
to us.)

I couldn't reproduce with the following:

test_stream.h:

#include <arrow-glib/arrow-glib.hpp>

class test_stream: public ::arrow::RecordBatchReader {
public:
   std::shared_ptr<::arrow::Schema> schema() const override {
     return ::arrow::schema({::arrow::field("a", arrow::int32())});
   }

   arrow::Status ReadNext(std::shared_ptr<::arrow::RecordBatch> *batch)
     override {
     return arrow::Status::OK();
   }
};

extern "C" GArrowRecordBatchReader* make_test_stream(){
   std::shared_ptr<::arrow::RecordBatchReader> ts =
     std::make_shared<test_stream>();
   return garrow_record_batch_reader_new_raw(&ts);
}

test.cpp:

#include "test_stream.h"

int
main(void)
{
   GArrowRecordBatchReader *ts = make_test_stream();
   GArrowSchema *schema = garrow_record_batch_reader_get_schema(ts);
   g_object_unref(schema);
   g_object_unref(ts);
   return 0;
}

Command lines:

$ g++ test.cpp $(pkg-config --cflags --libs arrow-glib)
$ ./a.out


Thanks,
--
kou

In <[email protected]>
   "c/c++ interop" on Wed, 17 Feb 2021 12:09:37 +1100,
   Matt Youill <[email protected]> wrote:

Hi,

I'm not super familiar with glib and currently have an issue with the
arrows cglib lib.

I have some C++ code that creates a subclass of RecordBatchReader
(test_stream), and returns it to some C code as a
GArrowRecordBatchReader *.

If I run the same code in C++ it runs fine, but in C I always get a
segmentation fault when performing an operation on the returned
GArrowRecordBatchReader *.

test_stream doesn't really do anything other than return a dummy
schema (it's just a test).


Sample code:

*test_stream.h*


class test_stream: public ::arrow::RecordBatchReader {

  public:
   std::shared_ptr<::arrow::Schema> schema() const override {
     return ::arrow::schema({::arrow::field("a", arrow::int32())});
   }

   arrow::Status ReadNext(std::shared_ptr<::arrow::RecordBatch> *batch)
override {
     return arrow::Status::OK();
   }

};

extern "C" GArrowRecordBatchReader* make_test_stream(){
   std::shared_ptr<::arrow::RecordBatchReader> ts =
std::make_shared<test_stream>();
   return garrow_record_batch_reader_new_raw(&ts);
}


*test.c (or test.cpp)*

GArrowRecordBatchReader *ts = make_test_stream();
GArrowSchema *schema = garrow_record_batch_reader_get_schema(ts);
<---- segfault here


Underlying break happens in arrows reader.h on this piece of code...

#define GARROW_TYPE_RECORD_BATCH_READER
#(garrow_record_batch_reader_get_type())
G_DECLARE_DERIVABLE_TYPE(GArrowRecordBatchReader,
                          garrow_record_batch_reader,
                          GARROW,
                          RECORD_BATCH_READER,
                          GObject)

It smells like its something to do with my sub classing of
RecordBatchReader but I don't know enough about glib.

Thanks, Matt


Reply via email to