Repository: apache/arrow
File: c_glib/arrow-glib/compute.cpp (C++)

Code before:
static void
garrow_execute_context_class_init(GArrowExecuteContextClass *klass)
{
  auto gobject_class = G_OBJECT_CLASS(klass);

  gobject_class->finalize = garrow_execute_context_finalize;
}

/**
 * garrow_execute_context_new:
 * @thread_pool: (nullable): A #GArrowThreadPool or %NULL.
 *
 * Returns: A newly created #GArrowExecuteContext.
 *
 * Since: 1.0.0
 */
GArrowExecuteContext *
garrow_execute_context_new(GArrowThreadPool *thread_pool)
{
  auto execute_context = g_object_new(GARROW_TYPE_EXECUTE_CONTEXT, NULL);
  auto priv = GARROW_EXECUTE_CONTEXT_GET_PRIVATE(execute_context);

  auto arrow_thread_pool = garrow_thread_pool_get_raw(thread_pool);
  priv->thread_pool = arrow_thread_pool;
  new (&priv->context)
    arrow::compute::ExecContext(arrow::default_memory_pool(), arrow_thread_pool.get());

  return GARROW_EXECUTE_CONTEXT(execute_context);
}

typedef struct GArrowFunctionOptionsPrivate_
{
  arrow::compute::FunctionOptions *options;
} GArrowFunctionOptionsPrivate;

G_DEFINE_TYPE_WITH_PRIVATE(GArrowFunctionOptions, garrow_function_options, G_TYPE_OBJECT)

#define GARROW_FUNCTION_OPTIONS_GET_PRIVATE(object)                                      \
  static_cast<GArrowFunctionOptionsPrivate *>(                                           \
    garrow_function_options_get_instance_private(GARROW_FUNCTION_OPTIONS(object)))

static void
garrow_function_options_finalize(GObject *object)
{
  auto priv = GARROW_FUNCTION_OPTIONS_GET_PRIVATE(object);
  delete priv->options;
  G_OBJECT_CLASS(garrow_function_options_parent_class)->finalize(object);
}

static void
garrow_function_options_init(GArrowFunctionOptions *object)

Review comment (suggestion):
We should not use placement new here. We should do the following in `_set_property()`:

```cpp
priv->context = arrow::compute::ExecContext(...);
```

Code after:
static void
garrow_execute_context_finalize(GObject *object)
{
  auto priv = GARROW_EXECUTE_CONTEXT_GET_PRIVATE(object);
  priv->context.~shared_ptr();
  G_OBJECT_CLASS(garrow_execute_context_parent_class)->finalize(object);
}

static void
garrow_execute_context_set_property(GObject *object,
                                    guint prop_id,
                                    const GValue *value,
                                    GParamSpec *pspec)
{
  auto priv = GARROW_EXECUTE_CONTEXT_GET_PRIVATE(object);

  switch (prop_id) {
  case PROP_EXECUTOR:
    {
      priv->executor = GARROW_EXECUTOR(g_value_dup_object(value));
      auto arrow_executor = garrow_executor_get_raw(priv->executor);
      priv->context =
        std::make_shared<arrow::compute::ExecContext>(arrow::default_memory_pool(),
                                                      arrow_executor.get());
      break;
    }
  default:
    G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
    break;
  }
}

static void
garrow_execute_context_get_property(GObject *object,
                                    guint prop_id,
                                    GValue *value,
                                    GParamSpec *pspec)
{
  auto priv = GARROW_EXECUTE_CONTEXT_GET_PRIVATE(object);

  switch (prop_id) {
  case PROP_EXECUTOR:
    g_value_set_object(value, priv->executor);
    break;
  default:
    G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
    break;
  }
}

static void