Пример #1
0
SeedValue seed_mpfr_nexttoward (SeedContext ctx,
                                SeedObject function,
                                SeedObject this_object,
                                gsize argument_count,
                                const SeedValue args[],
                                SeedException *exception)
{
    mpfr_ptr rop, op;

    CHECK_ARG_COUNT("mpfr.nexttoward", 1);

    rop = seed_object_get_private(this_object);

    if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
    {
        op = seed_object_get_private(args[0]);
    }
    else
    {
        TYPE_EXCEPTION("mpfr.nexttoward", "mpfr_t");
    }

    mpfr_nexttoward(rop, op);

    return seed_make_null(ctx);
}
Пример #2
0
SeedValue seed_mpfr_sub (SeedContext ctx,
                         SeedObject function,
                         SeedObject this_object,
                         gsize argument_count,
                         const SeedValue args[],
                         SeedException *exception)
{
    mpfr_rnd_t rnd;
    mpfr_ptr rop, op1, op2;
    gdouble dop1, dop2;
    gint ret;
    seed_mpfr_t argt1, argt2;
    /* only want 1 double argument. alternatively, could accept 2,
       add those, and set from the result*/

    CHECK_ARG_COUNT("mpfr.sub", 3);

    rop = seed_object_get_private(this_object);
    rnd = seed_value_to_mpfr_rnd_t(ctx, args[2], exception);

    argt1 = seed_mpfr_arg_type(ctx, args[0], exception);
    argt2 = seed_mpfr_arg_type(ctx, args[1], exception);

    if ( (argt1 & argt2) == SEED_MPFR_MPFR )
    {
        /* both mpfr_t */
        op1 = seed_object_get_private(args[0]);
        op2 = seed_object_get_private(args[1]);
        ret = mpfr_sub(rop, op1, op2, rnd);
    }
    else if ( (argt1 | argt2) == (SEED_MPFR_MPFR | SEED_MPFR_DOUBLE) )
    {
        /* a double and an mpfr_t. Figure out the order */
        if ( argt1 == SEED_MPFR_MPFR )
        {
            op1 = seed_object_get_private(args[0]);
            dop2 = seed_value_to_double(ctx, args[1], exception);
            mpfr_sub_d(rop, op1, dop2, rnd);
        }
        else
        {
            dop1 = seed_value_to_double(ctx, args[0], exception);
            op2 = seed_object_get_private(args[1]);
            mpfr_d_sub(rop, dop1, op2, rnd);
        }
    }
    else if ( (argt1 & argt2) == SEED_MPFR_DOUBLE )
    {
        /* 2 doubles. hopefully doesn't happen */
        dop1 = seed_value_to_double(ctx, args[0], exception);
        dop2 = seed_value_to_double(ctx, args[1], exception);
        ret = mpfr_set_d(rop, dop1 - dop2, rnd);
    }
    else
    {
        TYPE_EXCEPTION("mpfr.sub", "double or mpfr_t");
    }

    return seed_value_from_int(ctx, ret, exception);
}
Пример #3
0
SeedValue seed_mpfr_remainder (SeedContext ctx,
                               SeedObject function,
                               SeedObject this_object,
                               gsize argument_count,
                               const SeedValue args[],
                               SeedException *exception)
{
    mpfr_rnd_t rnd;
    mpfr_ptr rop, op1, op2;
    gint ret;

    CHECK_ARG_COUNT("mpfr.remainder", 3);

    rop = seed_object_get_private(this_object);
    rnd = seed_value_to_mpfr_rnd_t(ctx, args[2], exception);

    if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) &&
         seed_value_is_object_of_class(ctx, args[1], mpfr_class))
    {
        op1 = seed_object_get_private(args[0]);
        op2 = seed_object_get_private(args[1]);
    }
    else
    {
        TYPE_EXCEPTION("mpfr.remainder", "mpfr_t");
    }

    ret = mpfr_remainder(rop, op1, op2, rnd);

    return seed_value_from_int(ctx, ret, exception);
}
Пример #4
0
SeedValue seed_mpfr_cmpabs (SeedContext ctx,
                            SeedObject function,
                            SeedObject this_object,
                            gsize argument_count,
                            const SeedValue args[],
                            SeedException *exception)
{
    mpfr_ptr rop, op;
    gint ret;

    CHECK_ARG_COUNT("mpfr.cmpabs", 1);

    rop = seed_object_get_private(this_object);

    if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
    {
        op = seed_object_get_private(args[0]);
    }
    else
    {
        TYPE_EXCEPTION("mpfr.cmpabs", "mpfr_t");
    }

    ret = mpfr_cmpabs(rop, op);

    return seed_value_from_int(ctx, ret, exception);
}
Пример #5
0
static SeedValue
seed_cairo_surface_write_to_png (SeedContext ctx,
				 SeedObject function,
				 SeedObject this_object,
				 gsize argument_count,
				 const SeedValue arguments[],
				 SeedException *exception)
{
  cairo_status_t ret;
  cairo_surface_t *surf;
  gchar *filename;
  CHECK_THIS();

  if (argument_count != 1)
    {
      EXPECTED_EXCEPTION("write_to_png", "1 argument");
    }

  surf = seed_object_get_private (this_object);
  filename = seed_value_to_string (ctx, arguments[0], exception);

  ret = cairo_surface_write_to_png (surf, filename);
  g_free (filename);

  return seed_value_from_long (ctx, ret, exception);
}
Пример #6
0
static SeedValue
seed_cairo_pattern_add_color_stop_rgba (SeedContext ctx,
				       SeedObject function,
				       SeedObject this_object,
				       gsize argument_count,
				       const SeedValue arguments[],
				       SeedException *exception)
{
  gdouble offset, r, g, b, a;
  cairo_pattern_t *pat;
  CHECK_THIS();
  if (argument_count != 5)
    {
      EXPECTED_EXCEPTION("add_color_stop_rgba", "5 arguments");
    }

  pat = seed_object_get_private (this_object);
  offset = seed_value_to_double (ctx, arguments[0], exception);
  r = seed_value_to_double (ctx, arguments[1], exception);
  g = seed_value_to_double (ctx, arguments[2], exception);
  b = seed_value_to_double (ctx, arguments[3], exception);
  a = seed_value_to_double (ctx, arguments[4], exception);

  cairo_pattern_add_color_stop_rgba (pat, offset, r, g, b, a);

  return seed_make_undefined (ctx);
}
Пример #7
0
void pipe_finalize(SeedObject pipeobj)
{
  pipe_priv *priv = seed_object_get_private(pipeobj);
  g_io_channel_unref(priv->read);
  g_io_channel_unref(priv->write);
  g_free(priv);
}
Пример #8
0
static gboolean
seed_ffi_set_signature (SeedContext ctx,
			  SeedObject this_object,
			  SeedString property_name,
			  SeedValue value,
			  SeedException *exception)
{
  seed_ffi_function_priv *priv = seed_object_get_private (this_object);
  
  if (priv->signature_obj)
    {
      seed_make_exception (ctx, exception, "FFIError",
			   "Can not reset signature of function once set");
      return FALSE;
    }
  else if (!seed_value_is_object (ctx, value))
    {
      seed_make_exception (ctx, exception, "FFIError",
			   "Signature must be an object");
      return FALSE;
    }
  else
    {
      if (!seed_ffi_build_signature (ctx, priv, (SeedObject) value, exception))
	return FALSE;
    }
  return TRUE;
}
Пример #9
0
static void
exports_finalize (SeedObject obj)
{
    Exports *priv;
    BigDBusConnectFuncs const *connect_funcs = NULL;

    priv = seed_object_get_private (obj);
    if (priv == NULL)
        return; /* we are the prototype, not a real instance, so constructor never called */

    if (priv->which_bus == DBUS_BUS_SESSION) {
        connect_funcs = &session_connect_funcs;
    } else if (priv->which_bus == DBUS_BUS_SYSTEM) {
        connect_funcs = &system_connect_funcs;
    } else
        g_assert_not_reached();

    big_dbus_remove_connect_funcs(connect_funcs, priv);

    if (priv->connection_weak_ref != NULL) {
        on_bus_closed(priv->connection_weak_ref, priv);
    }

    g_slice_free(Exports, priv);
}
Пример #10
0
static SeedValue
seed_ffi_library_get_property (SeedContext ctx,
			       SeedObject this_object,
			       SeedString property_name,
			       SeedException *exception)
{
  SeedValue ret;
  GModule *mod;
  gchar *prop;
  gsize len = seed_string_get_maximum_size (property_name);
  gpointer symbol;
  seed_ffi_library_priv *priv;
  
  prop = g_alloca (len);
  seed_string_to_utf8_buffer (property_name, prop, len);
  
  priv = seed_object_get_private (this_object);
  mod = priv->mod;
  
  if ((ret = g_hash_table_lookup (priv->symbols, prop)))
    return ret;

  if (!g_module_symbol (mod, prop, &symbol))
    {
      return NULL;
    }
  return seed_ffi_make_function (ctx, this_object, symbol, prop, priv->symbols);
}
Пример #11
0
static void
seed_ffi_library_finalize (SeedObject obj)
{
  seed_ffi_library_priv *priv;
  priv = seed_object_get_private (obj);
  
  g_module_close (priv->mod);
}
Пример #12
0
SeedValue seed_sqlite_close(SeedContext ctx,
			    SeedObject function,
			    SeedObject this_object,
			    size_t argument_count,
			    const SeedValue arguments[],
			    SeedException * exception)
{
  sqlite3 *db = seed_object_get_private(this_object);
  sqlite3_close(db);
  return seed_value_from_boolean(ctx, TRUE, exception);
}
Пример #13
0
SeedValue seed_mpfr_root (SeedContext ctx,
                         SeedObject function,
                         SeedObject this_object,
                         gsize argument_count,
                         const SeedValue args[],
                         SeedException *exception)
{
    mpfr_rnd_t rnd;
    mpfr_ptr rop, op;
    gint ret;
    gulong k;

    CHECK_ARG_COUNT("mpfr.root", 3);

    rop = seed_object_get_private(this_object);
    rnd = seed_value_to_mpfr_rnd_t(ctx, args[2], exception);

    if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
    {
        op = seed_object_get_private(args[0]);
    }
    else
    {
        TYPE_EXCEPTION("mpfr.root", "mpfr_t");
    }

    if ( seed_value_is_number(ctx, args[1]) )
    {
        k = seed_value_to_ulong(ctx, args[1], exception);
    }
    else
    {
        TYPE_EXCEPTION("mpfr.root", "unsigned long int");
    }


    ret = mpfr_root(rop, op, k, rnd);

    return seed_value_from_int(ctx, ret, exception);
}
Пример #14
0
static SeedValue
seed_ffi_get_signature (SeedContext ctx,
			  SeedObject this_object,
			  SeedString property_name,
			  SeedException *exception)
{
  seed_ffi_function_priv *priv = seed_object_get_private (this_object);
  
  if (priv->signature_obj)
    return priv->signature_obj;
  else
    return seed_make_null (ctx);
}
Пример #15
0
SeedValue seed_mpfr_nextabove (SeedContext ctx,
                               SeedObject function,
                               SeedObject this_object,
                               gsize argument_count,
                               const SeedValue args[],
                               SeedException *exception)
{
    mpfr_ptr rop;

    CHECK_ARG_COUNT("mpfr.nextabove", 0);

    rop = seed_object_get_private(this_object);

    mpfr_nextabove(rop);
    return seed_make_null(ctx);
}
Пример #16
0
SeedValue seed_mpfr_integer_p (SeedContext ctx,
                               SeedObject function,
                               SeedObject this_object,
                               gsize argument_count,
                               const SeedValue args[],
                               SeedException *exception)
{
    mpfr_ptr rop;
    gboolean ret;

    CHECK_ARG_COUNT("mpfr.integer", 0);
    rop = seed_object_get_private(this_object);
    ret = mpfr_integer_p(rop);

    return seed_value_from_boolean(ctx, ret, exception);
}
Пример #17
0
static void
seed_ffi_function_finalize (SeedObject obj)
{
  seed_ffi_function_priv *priv = seed_object_get_private (obj);
  
  if (priv->signature_obj)
    {
      seed_value_unprotect (eng->context, priv->signature_obj);
      
      g_slice_free1 (priv->n_args * sizeof(GType), priv->args);
    }
  
  g_free (priv->name);
  g_slice_free1 (sizeof(seed_ffi_function_priv), priv); 

  seed_value_unprotect (eng->context, priv->module_obj);
}
Пример #18
0
SeedValue seed_sqlite_exec(SeedContext ctx,
			   SeedObject function,
			   SeedObject this_object,
			   size_t argument_count,
			   const SeedValue arguments[],
			   SeedException * exception)
{
  gchar *statement;
  gchar *sqlite_error = 0;
  sqlite3 *db;
  int rc;

  if (argument_count < 1)
    {
      seed_make_exception(ctx, exception, "ArgumentError",
			  "sqlite.Database.exec expected 1 or 2 arguments");
      return seed_make_null(ctx);
    }

  statement = seed_value_to_string(ctx, arguments[0], exception);
  db = seed_object_get_private(this_object);

  g_assert(db);

  rc = sqlite3_exec(db, statement,
		    seed_sqlite_exec_callback,
		    argument_count == 2 ? arguments[1] : 0, &sqlite_error);
  g_free(statement);

  if (rc != SQLITE_OK)
    {
      if (sqlite_error)
	{
		seed_make_exception(ctx, exception, "SqliteError",
				    sqlite_error, NULL);
	  sqlite3_free(sqlite_error);
	}
      return seed_make_null(ctx);
    }

  return seed_value_from_int(ctx, rc, exception);

}
Пример #19
0
static SeedValue
seed_ffi_function_call (SeedContext ctx,
			SeedObject function,
			SeedObject this_object,
			gsize argument_count,
			const SeedValue arguments[],
			SeedException *exception)
{
  GArgument rvalue;
  GArgument *gargs;
  ffi_type *rtype;
  ffi_type **atypes;
  gpointer *args;
  int i;
  ffi_cif cif;

  seed_ffi_function_priv *priv = seed_object_get_private (function);
  
  if (argument_count != priv->n_args)
    {
      seed_make_exception (ctx, exception, "ArgumentError", "%s expected %d arguments got %zd",
			   priv->name, priv->n_args, argument_count);
      return seed_make_null (ctx);
    }
  atypes = g_alloca (sizeof (ffi_type *) * (argument_count));
  args = g_alloca (sizeof (gpointer) * (argument_count));
  gargs = g_alloca (sizeof (GArgument) * (argument_count));

  for (i = 0; i < argument_count; i++)
    {
      atypes[i] = gtype_to_ffi_type (ctx, arguments[i], priv->args[i], &(gargs[i]), &args[i],exception);
    }
  rtype = return_type_to_ffi_type (priv->ret_val);
		   
  if (ffi_prep_cif (&cif, FFI_DEFAULT_ABI, argument_count, rtype, atypes) != FFI_OK)
    g_assert_not_reached();
  
  ffi_call (&cif, priv->symbol, &rvalue, args);
  
  return value_from_ffi_type (ctx, priv->ret_val, &rvalue, exception);
}
Пример #20
0
SeedValue seed_mpfr_prec_round (SeedContext ctx,
                                SeedObject function,
                                SeedObject this_object,
                                gsize argument_count,
                                const SeedValue args[],
                                SeedException *exception)
{
    mpfr_rnd_t rnd;
    mp_prec_t prec;
    mpfr_ptr rop;
    gint ret;

    CHECK_ARG_COUNT("mpfr.prec_round", 2);

    rop = seed_object_get_private(this_object);
    prec = seed_value_to_mpfr_prec_t(ctx, args[0], exception);
    rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);

    ret = mpfr_prec_round(rop, prec, rnd);

    return seed_value_from_int(ctx, ret, exception);
}
Пример #21
0
SeedValue seed_mpfr_cmp_si_2exp (SeedContext ctx,
                                 SeedObject function,
                                 SeedObject this_object,
                                 gsize argument_count,
                                 const SeedValue args[],
                                 SeedException *exception)
{
    mpfr_ptr op1;
    gulong op2;
    mp_exp_t exp;
    gint ret;

    CHECK_ARG_COUNT("mpfr.cmp_si_2exp", 2);

    op1 = seed_object_get_private(this_object);

    if ( seed_value_is_number(ctx, args[0]) )
    {
        op2 = seed_value_to_ulong(ctx, args[0], exception);
    }
    else
    {
        TYPE_EXCEPTION("mpfr.cmp_si_2exp", "long int");
    }

    if ( seed_value_is_number(ctx, args[1]) )
    {
        exp = seed_value_to_mp_exp_t(ctx, args[1], exception);
    }
    else
    {
        TYPE_EXCEPTION("mpfr.cmp_si_2exp", "mp_exp_t");
    }

    ret = mpfr_cmp_si_2exp(op1, op2, exp);

    return seed_value_from_int(ctx, ret, exception);
}
Пример #22
0
static gboolean
add_connect_funcs(SeedContext ctx,
		  SeedObject obj,
                  DBusBusType which_bus)
{
   Exports *priv;
   BigDBusConnectFuncs const *connect_funcs;

   priv = seed_object_get_private (obj);
   if (priv == NULL)
       return FALSE;

   if (which_bus == DBUS_BUS_SESSION) {
       connect_funcs = &session_connect_funcs;
   } else if (which_bus == DBUS_BUS_SYSTEM) {
       connect_funcs = &system_connect_funcs;
   } else
       g_assert_not_reached();

   priv->which_bus = which_bus;
   big_dbus_add_connect_funcs_sync_notify(connect_funcs, priv);

   return TRUE;
}
Пример #23
0
static SeedValue
seed_cairo_pdf_surface_set_size (SeedContext ctx,
				 SeedObject function,
				 SeedObject this_object,
				 gsize argument_count,
				 const SeedValue arguments[],
				 SeedException *exception)
{
  cairo_surface_t *surf;
  gdouble x, y;

  CHECK_THIS();
  if (argument_count != 2)
    {
      EXPECTED_EXCEPTION("set_size", "2 arguments");
    }
  surf = seed_object_get_private (this_object);
  x = seed_value_to_double (ctx, arguments[0], exception);
  y = seed_value_to_double (ctx, arguments[1], exception);

  cairo_pdf_surface_set_size (surf, x, y);

  return seed_make_undefined (ctx);
}
Пример #24
0
void sqlite_database_finalize(SeedObject object)
{
  sqlite3 *db = seed_object_get_private(object);
  if (db)
    sqlite3_close(db);
}
Пример #25
0
SeedValue seed_mpfr_pow (SeedContext ctx,
                         SeedObject function,
                         SeedObject this_object,
                         gsize argument_count,
                         const SeedValue args[],
                         SeedException * exception)
{
    mpfr_rnd_t rnd;
    mpfr_ptr rop, op1, op2;
    gint ret;
    glong iop;
    gulong uiop1, uiop2;
    seed_mpfr_t argt1, argt2;
    /* only want 1 double argument. alternatively, could accept 2,
       add those, and set from the result*/

    CHECK_ARG_COUNT("mpfr.pow", 3);

    rop = seed_object_get_private(this_object);
    rnd = seed_value_to_mpfr_rnd_t(ctx, args[2], exception);

    argt1 = seed_mpfr_arg_type(ctx, args[0], exception);
    argt2 = seed_mpfr_arg_type(ctx, args[1], exception);

    if ( (argt1 & argt2) == SEED_MPFR_MPFR )
    {
        /* both mpfr_t */
        op1 = seed_object_get_private(args[0]);
        op2 = seed_object_get_private(args[1]);
        ret = mpfr_pow(rop, op1, op2, rnd);
    }
    else if ( (argt1 | argt2) == (SEED_MPFR_MPFR | SEED_MPFR_DOUBLE) )
    {
        /* a double and an mpfr_t. Figure out the order */
        /* FIXME: is this switching ui and si bad? si_pow doesn't exist,
           and it's all from double anyway */
        if ( argt1 == SEED_MPFR_MPFR )
        {
            op1 = seed_object_get_private(args[0]);
            iop = seed_value_to_long(ctx, args[1], exception);
            ret = mpfr_pow_si(rop, op1, iop, rnd);
        }
        else
        {
            uiop1 = seed_value_to_ulong(ctx, args[0], exception);
            op2 = seed_object_get_private(args[1]);
            ret = mpfr_ui_pow(rop, uiop1, op2, rnd);
        }
    }
    else if ( (argt1 & argt2) == SEED_MPFR_DOUBLE )
    {
        /* pretend both ui */
        uiop1 = seed_value_to_ulong(ctx, args[0], exception);
        uiop2 = seed_value_to_ulong(ctx, args[1], exception);
        ret = mpfr_ui_pow_ui(rop, uiop1, uiop2, rnd);
    }
    else
    {
        TYPE_EXCEPTION("mpfr.pow", "int or unsigned int and mpfr_t");
    }

    return seed_value_from_int(ctx, ret, exception);
}