Skip to content

Commit

Permalink
Load plruby-0.4.6 into trunk.
Browse files Browse the repository at this point in the history
git-svn-id: file:///home/knu/repos/ts/plruby/trunk@59 1f148aff-833f-de11-9cfd-0015170b777a
  • Loading branch information
ts committed Nov 10, 2005
1 parent dafaa18 commit f5deb48
Show file tree
Hide file tree
Showing 22 changed files with 1,791 additions and 68 deletions.
2 changes: 2 additions & 0 deletions src/conversions/basic/plruby_basic.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ pl_float_s_datum(VALUE obj, VALUE a)
return rb_float_new(result);
}

extern double round();

static VALUE
pl_float_to_datum(VALUE obj, VALUE a)
{
Expand Down
9 changes: 6 additions & 3 deletions src/conversions/bitstring/plruby_bitstring.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ pl_bit_to_datum(VALUE obj, VALUE a)
{
VarBit *ip0, *ip1;
int length;
Datum d;
Oid typoid;

typoid = plruby_datum_oid(a, &length);
Expand All @@ -87,7 +86,7 @@ pl_bit_init(int argc, VALUE *argv, VALUE obj)
{
VarBit *inst;
VALUE a, b;
void *v = 0, *v1;
void *v = 0;
int length = -1;
int taint = 0;

Expand All @@ -103,6 +102,8 @@ pl_bit_init(int argc, VALUE *argv, VALUE obj)
#else
v = (void *)PLRUBY_DFC1(bitfromint4, Int32GetDatum(NUM2LONG(a)));
if (length > 0) {
void *v1;

int ll = DatumGetInt32(PLRUBY_DFC1(bitlength, v));
if (length != ll) {
if (length < ll) {
Expand Down Expand Up @@ -349,6 +350,8 @@ pl_bit_include(VALUE obj, VALUE a)
return Qtrue;
}

extern long rb_reg_search();

static VALUE
pl_bit_subpat(VALUE obj, VALUE a, int nth)
{
Expand Down Expand Up @@ -435,7 +438,7 @@ pl_bit_aref(VALUE obj, VALUE a)
if (DatumGetInt32(PLRUBY_DFC2(bitposition, v, v0)) > 0) {
v1 = (VarBit *)ALLOC_N(char, VARSIZE(v0));
CPY_FREE(v1, v0, VARSIZE(v0));
res = Data_Wrap_Struct(rb_class_obj(obj), pl_bit_mark, free, v1);
res = Data_Wrap_Struct(CLASS_OF(obj), pl_bit_mark, free, v1);
if (OBJ_TAINTED(obj) || OBJ_TAINTED(a)) OBJ_TAINT(res);
return res;
}
Expand Down
6 changes: 3 additions & 3 deletions src/conversions/convcommon.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#include "package.h"

#include "package.h"
#include <ruby.h>
#include "package.h"
#include <postgres.h>
#include <catalog/pg_type.h>
#include <utils/builtins.h>
#include <lib/stringinfo.h>
#include "package.h"
#include <ruby.h>
#include "package.h"

#define CPY_FREE(p0_, p1_, size_) do { \
void *p2_ = (void *)p1_; \
Expand Down
4 changes: 2 additions & 2 deletions src/conversions/geometry/conversions.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{
VALUE tmp;

#if RUBY_CAN_USE_AUTOLOAD
rb_funcall(rb_mKernel, rb_intern("autoload"), 2, rb_str_new2("Point"),
rb_str_new2("plruby/plruby_geometry"));
Expand All @@ -21,6 +19,8 @@
rb_hash_aset(plruby_conversions, INT2NUM(POLYGONOID), INT2NUM(rb_intern("Polygon")));
rb_hash_aset(plruby_conversions, INT2NUM(CIRCLEOID), INT2NUM(rb_intern("Circle")));
#else
VALUE tmp;

tmp = plruby_define_void_class("Point", "plruby/plruby_geometry");
rb_hash_aset(plruby_classes, INT2NUM(POINTOID), tmp);
tmp = plruby_define_void_class("Segment", "plruby/plruby_geometry");
Expand Down
42 changes: 15 additions & 27 deletions src/conversions/geometry/plruby_geometry.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ PL_MDUMP(pl_point_mdump, point_send);
static VALUE
pl_point_s_str(VALUE obj, VALUE a)
{
char *str, *s;
Point *p;
VALUE res;

Expand Down Expand Up @@ -316,7 +315,7 @@ POINT_CALL_BOOL(pl_point_eq,point_eq);
static VALUE
pl_point_slope(VALUE obj, VALUE a)
{
Point *p0, *p1, *pr;
Point *p0, *p1;

CHECK_CLASS(obj, a);
Data_Get_Struct(obj, Point, p0);
Expand Down Expand Up @@ -375,8 +374,6 @@ PL_MDUMP(pl_lseg_mdump, lseg_send);
static VALUE
pl_lseg_s_str(VALUE obj, VALUE a)
{
char *str, *s;
int isopen;
LSEG *l;
VALUE res;

Expand Down Expand Up @@ -677,8 +674,6 @@ PL_MDUMP(pl_box_mdump, box_send);
static VALUE
pl_box_s_str(VALUE obj, VALUE a)
{
char *str, *s;
int isopen;
BOX *l;
VALUE res;

Expand Down Expand Up @@ -880,17 +875,17 @@ pl_box_cmp(VALUE obj, VALUE a)
return INT2NUM(1);
}

#define BOX_BOOL(NAME_,FUNCTION_) \
static VALUE \
NAME_(VALUE obj, VALUE a) \
{ \
BOX *p0, *p1, *pr; \
\
CHECK_CLASS(obj, a); \
Data_Get_Struct(obj, BOX, p0); \
Data_Get_Struct(a, BOX, p1); \
if (PLRUBY_DFC2(FUNCTION_, p0, p1)) return Qtrue;\
return Qfalse; \
#define BOX_BOOL(NAME_,FUNCTION_) \
static VALUE \
NAME_(VALUE obj, VALUE a) \
{ \
BOX *p0, *p1; \
\
CHECK_CLASS(obj, a); \
Data_Get_Struct(obj, BOX, p0); \
Data_Get_Struct(a, BOX, p1); \
if (PLRUBY_DFC2(FUNCTION_, p0, p1)) return Qtrue; \
return Qfalse; \
}

BOX_BOOL(pl_box_same,box_same);
Expand Down Expand Up @@ -960,7 +955,7 @@ pl_box_center(VALUE obj)
static VALUE
pl_box_closest(VALUE obj, VALUE a)
{
BOX *l0, *l1;
BOX *l0;
Point *p0, *p1;
VALUE res;

Expand Down Expand Up @@ -996,7 +991,7 @@ pl_box_closest(VALUE obj, VALUE a)
static VALUE
pl_box_intersect(VALUE obj, VALUE a)
{
BOX *l0, *l1;
BOX *l0;

Data_Get_Struct(obj, BOX, l0);
if (TYPE(a) == T_DATA) {
Expand Down Expand Up @@ -1132,7 +1127,6 @@ PL_MDUMP(pl_path_mdump, path_send);
static VALUE
pl_path_s_str(VALUE obj, VALUE a)
{
char *str, *s;
PATH *p, *m;
VALUE res;

Expand Down Expand Up @@ -1177,7 +1171,6 @@ pl_path_init(int argc, VALUE *argv, VALUE obj)
p->p[i].y = po->y;
}
else {
double x;
VALUE tmp;

b = rb_Array(b);
Expand Down Expand Up @@ -1286,8 +1279,7 @@ PATH_CALL(pl_path_div, path_div_pt);
static VALUE
pl_path_concat(VALUE obj, VALUE a)
{
PATH *p0, *p1, *p2;
VALUE res;
PATH *p0, *p1;
Point *p;

Data_Get_Struct(obj, PATH, p0);
Expand Down Expand Up @@ -1453,7 +1445,6 @@ PL_MDUMP(pl_poly_mdump, poly_send);
static VALUE
pl_poly_s_str(VALUE obj, VALUE a)
{
char *str, *s;
POLYGON *p, *m;
VALUE res;

Expand Down Expand Up @@ -1498,7 +1489,6 @@ pl_poly_init(int argc, VALUE *argv, VALUE obj)
p->p[i].y = po->y;
}
else {
double x;
VALUE tmp;

b = rb_Array(b);
Expand Down Expand Up @@ -1723,7 +1713,6 @@ PL_MDUMP(pl_circle_mdump, circle_send);
static VALUE
pl_circle_s_str(VALUE obj, VALUE a)
{
char *str, *s;
CIRCLE *p, *m;
VALUE res;

Expand All @@ -1750,7 +1739,6 @@ pl_circle_init(VALUE obj, VALUE a, VALUE b)
p->center.y = po->y;
}
else {
double x;
VALUE tmp;

a = rb_Array(a);
Expand Down
3 changes: 2 additions & 1 deletion src/conversions/network/plruby_network.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ static VALUE
pl_inet_to_datum(VALUE obj, VALUE a)
{
inet *ip0, *ip1;
Datum d;
Oid typoid;

typoid = plruby_datum_oid(a, 0);
Expand Down Expand Up @@ -293,6 +292,7 @@ pl_inet_s_caddr(VALUE obj)
CPY_FREE(ip1, ip0, VARSIZE(ip0));
res = Data_Wrap_Struct(obj, pl_inet_mark, free, ip1);
if (OBJ_TAINTED(obj)) OBJ_TAINT(res);
return res;
}

static VALUE
Expand All @@ -315,6 +315,7 @@ pl_inet_s_saddr(VALUE obj)
CPY_FREE(ip1, ip0, VARSIZE(ip0));
res = Data_Wrap_Struct(obj, pl_inet_mark, free, ip1);
if (OBJ_TAINTED(obj)) OBJ_TAINT(res);
return res;
}

static VALUE
Expand Down
50 changes: 38 additions & 12 deletions src/plruby.c
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ extra_args_mark(struct extra_args *exa)
static VALUE
pl_real_handler(struct pl_thread_st *plth)
{
VALUE result;
VALUE result = Qnil;
int state;

#ifdef PLRUBY_TIMEOUT
Expand Down Expand Up @@ -730,17 +730,31 @@ pl_func_handler(struct pl_thread_st *plth)
nargs = procStruct->pronargs;
for (i = 0; i < nargs; ++i) {
#if PG_PL_VERSION >= 74
#if PG_PL_VERSION >= 81
if (procStruct->proargtypes.values[i] == ANYARRAYOID ||
procStruct->proargtypes.values[i] == ANYELEMENTOID) {
arg_type[i] = get_fn_expr_argtype(fcinfo->flinfo, i);
if (arg_type[i] == InvalidOid) {
arg_type[i] = procStruct->proargtypes.values[i];
}
}
#else
if (procStruct->proargtypes[i] == ANYARRAYOID ||
procStruct->proargtypes[i] == ANYELEMENTOID) {
arg_type[i] = get_fn_expr_argtype(fcinfo->flinfo, i);
if (arg_type[i] == InvalidOid) {
arg_type[i] = procStruct->proargtypes[i];
}
}
#endif
else
#endif
{
#if PG_PL_VERSION >= 81
arg_type[i] = procStruct->proargtypes.values[i];
#else
arg_type[i] = procStruct->proargtypes[i];
#endif
}
}

Expand Down Expand Up @@ -924,7 +938,6 @@ pl_func_handler(struct pl_thread_st *plth)

{
Datum prosrc;
char *argf;
VALUE argname;
#if PG_PL_VERSION >= 75
bool isnull;
Expand Down Expand Up @@ -1203,24 +1216,32 @@ pl_trigger_handler(struct pl_thread_st *plth)
rb_raise(pl_ePLruby, "unknown LEVEL event (%u)", trigdata->tg_event);
}

tg_old = Qnil;
tg_new = Qnil;
rettup = NULL;
if (TRIGGER_FIRED_BY_INSERT(trigdata->tg_event)) {
rb_hash_aset(TG, rb_str_freeze_new2("op"), INT2FIX(TG_INSERT));
tg_new = plruby_build_tuple(trigdata->tg_trigtuple, tupdesc, RET_HASH);
tg_old = rb_hash_new();
rettup = trigdata->tg_trigtuple;
if (TRIGGER_FIRED_FOR_ROW(trigdata->tg_event)) {
tg_new = plruby_build_tuple(trigdata->tg_trigtuple, tupdesc, RET_HASH);
tg_old = rb_hash_new();
rettup = trigdata->tg_trigtuple;
}
}
else if (TRIGGER_FIRED_BY_DELETE(trigdata->tg_event)) {
rb_hash_aset(TG, rb_str_freeze_new2("op"), INT2FIX(TG_DELETE));
tg_old = plruby_build_tuple(trigdata->tg_trigtuple, tupdesc, RET_HASH);
tg_new = rb_hash_new();

rettup = trigdata->tg_trigtuple;
if (TRIGGER_FIRED_FOR_ROW(trigdata->tg_event)) {
tg_old = plruby_build_tuple(trigdata->tg_trigtuple, tupdesc, RET_HASH);
tg_new = rb_hash_new();
rettup = trigdata->tg_trigtuple;
}
}
else if (TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event)) {
rb_hash_aset(TG, rb_str_freeze_new2("op"), INT2FIX(TG_UPDATE));
tg_new = plruby_build_tuple(trigdata->tg_newtuple, tupdesc, RET_HASH);
tg_old = plruby_build_tuple(trigdata->tg_trigtuple, tupdesc, RET_HASH);
rettup = trigdata->tg_newtuple;
if (TRIGGER_FIRED_FOR_ROW(trigdata->tg_event)) {
tg_new = plruby_build_tuple(trigdata->tg_newtuple, tupdesc, RET_HASH);
tg_old = plruby_build_tuple(trigdata->tg_trigtuple, tupdesc, RET_HASH);
rettup = trigdata->tg_newtuple;
}
}
else {
rb_raise(pl_ePLruby, "unknown OP event (%u)", trigdata->tg_event);
Expand Down Expand Up @@ -1276,6 +1297,10 @@ pl_trigger_handler(struct pl_thread_st *plth)
break;
}

if (!TRIGGER_FIRED_FOR_ROW(trigdata->tg_event)) {
rb_raise(pl_ePLruby, "Invalid return value for per-statement trigger");
}

modattrs = ALLOCA_N(int, tupdesc->natts);
modvalues = ALLOCA_N(Datum, tupdesc->natts);
for (i = 0; i < tupdesc->natts; i++) {
Expand Down Expand Up @@ -1441,6 +1466,7 @@ pl_load_singleton(argc, argv, obj)
static VALUE plans;

extern void Init_plruby_pl();
extern void Init_plruby_trans();

static void
pl_init_all(void)
Expand Down
5 changes: 5 additions & 0 deletions src/plruby.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,14 @@
#include "access/xact.h"
#endif

#if PG_PL_VERSION >= 81
#include "utils/memutils.h"
#endif

#include "package.h"

#include <ruby.h>
#include <st.h>

#ifndef StringValuePtr
#define StringValuePtr(x) STR2CSTR(x)
Expand Down
Loading

0 comments on commit f5deb48

Please sign in to comment.