Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Clean up dialect supports.

Dialects are now built by default.  A new option DISABLE_DIALECT=1 suppress
to build dialects into the shared object.
  • Loading branch information...
commit e7197601723468a2917ac61b9c68b814b1c06240 1 parent d0cde70
Hitoshi Harada umitanuki authored
61 Makefile
@@ -6,8 +6,7 @@
6 6 # @param V8_OUTDIR path to V8 output directory, used for library files
7 7 # @param V8_STATIC_SNAPSHOT if defined, statically link to v8 with snapshot
8 8 # @param V8_STATIC_NOSNAPSHOT if defined, statically link to v8 w/o snapshot
9   -# @param ENABLE_COFFEE if defined, build plcoffee
10   -# @param ENABLE_LIVESCRIPT if defined, build plls
  9 +# @param DISABLE_DIALECT if defined, not build dialects (i.e. plcoffee, etc)
11 10 #
12 11 # There are three ways to build plv8.
13 12 # 1. Dynamic link to v8 (default)
@@ -34,9 +33,17 @@ SRCS = plv8.cc plv8_type.cc plv8_func.cc plv8_param.cc $(JSCS)
34 33 OBJS = $(SRCS:.cc=.o)
35 34 MODULE_big = plv8
36 35 EXTENSION = plv8
37   -DATA = plv8.control plv8--$(PLV8_VERSION).sql
  36 +PLV8_DATA = plv8.control plv8--$(PLV8_VERSION).sql
  37 +DATA = $(PLV8_DATA)
  38 +ifndef DISABLE_DIALECT
  39 +DATA += plcoffee.control plcoffee--$(PLV8_VERSION).sql \
  40 + plls.control plls--$(PLV8_VERSION).sql
  41 +endif
38 42 DATA_built = plv8.sql
39 43 REGRESS = init-extension plv8 inline json startup_pre startup varparam
  44 +ifndef DISABLE_DIALECT
  45 +REGRESS += dialect
  46 +endif
40 47
41 48 # V8 build options. See the top comment.
42 49 V8_STATIC_SNAPSHOT_LIBS = libv8_base.a libv8_snapshot.a
@@ -68,23 +75,6 @@ ifdef V8_SRCDIR
68 75 override CPPFLAGS += -I$(V8_SRCDIR)/include
69 76 endif
70 77
71   -# plcoffee is available only when ENABLE_COFFEE is defined.
72   -ifdef ENABLE_COFFEE
73   -ifdef ENABLE_LIVESCRIPT
74   - CCFLAGS := -DENABLE_COFFEE -DENABLE_LIVESCRIPT $(CCFLAGS)
75   - DATA = plcoffee.control plcoffee--0.9.0.sql plls.control plls--0.9.0.sql
76   -else
77   - CCFLAGS := -DENABLE_COFFEE $(CCFLAGS)
78   - DATA = plcoffee.control plcoffee--0.9.0.sql
79   -endif
80   -else
81   -# plls is available only when ENABLE_LIVESCRIPT is defined.
82   -ifdef ENABLE_LIVESCRIPT
83   - CCFLAGS := -DENABLE_LIVESCRIPT $(CCFLAGS)
84   - DATA = plls.control plls--0.9.0.sql
85   -endif
86   -endif
87   -
88 78 all:
89 79
90 80 plv8_config.h: plv8_config.h.in Makefile
@@ -96,43 +86,40 @@ plv8_config.h: plv8_config.h.in Makefile
96 86 # Convert .js to .cc
97 87 $(JSCS): %.cc: %.js
98 88 echo "extern const unsigned char $(subst -,_,$(basename $@))_binary_data[] = {" >$@
99   -ifdef ENABLE_COFFEE
  89 +ifndef DISABLE_DIALECT
100 90 (od -txC -v $< | \
101 91 sed -e "s/^[0-9]*//" -e s"/ \([0-9a-f][0-9a-f]\)/0x\1,/g" -e"\$$d" ) >>$@
102   -else
103   -ifdef ENABLE_LIVESCRIPT
104   - (od -txC -v $< | \
105   - sed -e "s/^[0-9]*//" -e s"/ \([0-9a-f][0-9a-f]\)/0x\1,/g" -e"\$$d" ) >>$@
106   -endif
107 92 endif
108 93 echo "0x00};" >>$@
109 94
110 95 # VERSION specific definitions
111 96 ifeq ($(shell test $(PG_VERSION_NUM) -ge 90100 && echo yes), yes)
112   -plv8.sql:
  97 +
113 98 DATA_built =
114   -install: plv8--$(PLV8_VERSION).sql
115   -plv8--$(PLV8_VERSION).sql: plv8.sql.c
116   - $(CC) -E -P $(CPPFLAGS) $< > $@
  99 +all: $(DATA)
  100 +%--$(PLV8_VERSION).sql: plv8.sql.common
  101 + sed -e 's/@LANG_NAME@/$*/g' $< | $(CC) -E -P $(CPPFLAGS) - > $@
  102 +%.control: plv8.control.common
  103 + sed -e 's/@PLV8_VERSION@/$(PLV8_VERSION)/g' $< | $(CC) -E -P -DLANG_$* - > $@
117 104 subclean:
118   - rm -f plv8_config.h plv8--$(PLV8_VERSION).sql $(JSCS)
  105 + rm -f plv8_config.h $(DATA) $(JSCS)
119 106
120 107 else # < 9.1
121   -ifeq ($(shell test $(PG_VERSION_NUM) -ge 90000 && echo yes), yes)
122 108
123   -REGRESS := init $(filter-out init-extension, $(REGRESS))
  109 +ifeq ($(shell test $(PG_VERSION_NUM) -ge 90000 && echo yes), yes)
  110 +REGRESS := init $(filter-out init-extension dialect, $(REGRESS))
124 111
125 112 else # < 9.0
126 113
127   -REGRESS := init $(filter-out init-extension inline startup varparam, $(REGRESS))
  114 +REGRESS := init $(filter-out init-extension inline startup varparam dialect, $(REGRESS))
128 115
129 116 endif
130 117
131 118 DATA = uninstall_plv8.sql
132   -plv8.sql.in: plv8.sql.c
133   - $(CC) -E -P $(CPPFLAGS) $< > $@
  119 +%.sql.in: plv8.sql.common
  120 + sed -e 's/@LANG_NAME@/$*/g' $< | $(CC) -E -P $(CPPFLAGS) - > $@
134 121 subclean:
135   - rm -f plv8_config.h plv8.sql.in $(JSCS)
  122 + rm -f plv8_config.h *.sql.in $(JSCS)
136 123
137 124 endif
138 125
27 expected/dialect.out
... ... @@ -0,0 +1,27 @@
  1 +CREATE EXTENSION plcoffee;
  2 +DO LANGUAGE plcoffee $$ plv8.elog(INFO, "foo") $$;
  3 +INFO: foo
  4 +CREATE EXTENSION plls;
  5 +DO LANGUAGE plls $$ plv8.elog(INFO, "foo") $$;
  6 +INFO: foo
  7 +CREATE FUNCTION v8func(a int) RETURNS int[] AS $$
  8 +return [a, a, a];
  9 +$$ LANGUAGE plv8;
  10 +CREATE FUNCTION coffeefunc(a int) RETURNS int[] AS $$
  11 +return plv8.find_function('v8func')(a);
  12 +$$ LANGUAGE plcoffee;
  13 +SELECT coffeefunc(10);
  14 + coffeefunc
  15 +------------
  16 + {10,10,10}
  17 +(1 row)
  18 +
  19 +CREATE FUNCTION lsfunc(a int) RETURNS int[] AS $$
  20 +return plv8.find_function('v8func')(a);
  21 +$$ LANGUAGE plls;
  22 +SELECT lsfunc(11);
  23 + lsfunc
  24 +------------
  25 + {11,11,11}
  26 +(1 row)
  27 +
10 plcoffee--0.9.0.sql
... ... @@ -1,10 +0,0 @@
1   -CREATE FUNCTION plcoffee_call_handler() RETURNS language_handler
2   - AS 'MODULE_PATHNAME' LANGUAGE C;
3   -CREATE FUNCTION plcoffee_inline_handler(internal) RETURNS void
4   - AS 'MODULE_PATHNAME' LANGUAGE C;
5   -CREATE FUNCTION plcoffee_call_validator(oid) RETURNS void
6   - AS 'MODULE_PATHNAME' LANGUAGE C;
7   -CREATE TRUSTED LANGUAGE plcoffee
8   - HANDLER plcoffee_call_handler
9   - INLINE plcoffee_inline_handler
10   - VALIDATOR plcoffee_call_validator;
7 plcoffee.control
... ... @@ -1,7 +0,0 @@
1   -# plcoffee extension
2   -comment = 'PL/CoffeeScript (v8) trusted procedural language'
3   -default_version = '0.9.0'
4   -module_pathname = '$libdir/plv8'
5   -relocatable = false
6   -schema = pg_catalog
7   -superuser = true
10 plls--0.9.0.sql
... ... @@ -1,10 +0,0 @@
1   -CREATE FUNCTION plls_call_handler() RETURNS language_handler
2   - AS 'MODULE_PATHNAME' LANGUAGE C;
3   -CREATE FUNCTION plls_inline_handler(internal) RETURNS void
4   - AS 'MODULE_PATHNAME' LANGUAGE C;
5   -CREATE FUNCTION plls_call_validator(oid) RETURNS void
6   - AS 'MODULE_PATHNAME' LANGUAGE C;
7   -CREATE TRUSTED LANGUAGE plls
8   - HANDLER plls_call_handler
9   - INLINE plls_inline_handler
10   - VALIDATOR plls_call_validator;
7 plls.control
... ... @@ -1,7 +0,0 @@
1   -# plls extension
2   -comment = 'PL/LiveScript (v8) trusted procedural language'
3   -default_version = '0.9.0'
4   -module_pathname = '$libdir/plv8'
5   -relocatable = false
6   -schema = pg_catalog
7   -superuser = true
69 plv8.cc
@@ -867,22 +867,20 @@ CompileDialect(const char *src, Dialect dialect)
867 867 switch (dialect)
868 868 {
869 869 case PLV8_DIALECT_COFFEE:
870   -#ifndef ENABLE_COFFEE
871   - throw js_error("CoffeeScript is not enabled");
872   -#endif
  870 + if (coffee_script_binary_data[0] == '\0')
  871 + throw js_error("CoffeeScript is not enabled");
873 872 key = String::NewSymbol("CoffeeScript");
874 873 dialect_binary_data = (const char *) coffee_script_binary_data;
875 874 break;
876 875 case PLV8_DIALECT_LIVESCRIPT:
877   -#ifndef ENABLE_LIVESCRIPT
878   - throw js_error("LiveScript is not enabled");
879   -#endif
  876 + if (livescript_binary_data[0] == '\0')
  877 + throw js_error("LiveScript is not enabled");
880 878 key = String::NewSymbol("LiveScript");
881 879 dialect_binary_data = (const char *) livescript_binary_data;
882 880 break;
883 881 default:
884 882 throw js_error("Unknown Dialect");
885   - }
  883 + }
886 884
887 885 if (context->Global()->Get(key)->IsUndefined())
888 886 {
@@ -1033,10 +1031,12 @@ find_js_function(Oid fn_oid)
1033 1031 {
1034 1032 HeapTuple tuple;
1035 1033 Form_pg_proc proc;
1036   - Oid prolang, v8langtupoid, coffeelangtupoid, lslangtupoid;
1037   - NameData v8langname = { "plv8" },
1038   - coffeelangname = { "plcoffee" },
1039   - lslangname = { "plls" };
  1034 + Oid prolang;
  1035 + NameData langnames[] = { {"plv8"}, {"plcoffee"}, {"plls"} };
  1036 + int langno;
  1037 + int langlen = sizeof(langnames) / sizeof(NameData);
  1038 + Local<Function> func;
  1039 +
1040 1040
1041 1041 tuple = SearchSysCache(PROCOID, ObjectIdGetDatum(fn_oid), 0, 0, 0);
1042 1042 if (!HeapTupleIsValid(tuple))
@@ -1045,47 +1045,32 @@ find_js_function(Oid fn_oid)
1045 1045 prolang = proc->prolang;
1046 1046 ReleaseSysCache(tuple);
1047 1047
1048   - tuple = SearchSysCache(LANGNAME, NameGetDatum(&v8langname), 0, 0, 0);
1049   - if (!HeapTupleIsValid(tuple))
1050   - v8langtupoid = InvalidOid;
1051   - else
1052   - {
1053   - v8langtupoid = HeapTupleGetOid(tuple);
1054   - ReleaseSysCache(tuple);
1055   - }
1056   -
1057   - tuple = SearchSysCache(LANGNAME, NameGetDatum(&coffeelangname), 0, 0, 0);
1058   - if (!HeapTupleIsValid(tuple))
1059   - coffeelangtupoid = InvalidOid;
1060   - else
1061   - {
1062   - coffeelangtupoid = HeapTupleGetOid(tuple);
1063   - ReleaseSysCache(tuple);
1064   - }
  1048 + /* Should not happen? */
  1049 + if (!OidIsValid(prolang))
  1050 + return func;
1065 1051
1066   - tuple = SearchSysCache(LANGNAME, NameGetDatum(&lslangname), 0, 0, 0);
1067   - if (!HeapTupleIsValid(tuple))
1068   - lslangtupoid = InvalidOid;
1069   - else
  1052 + /* See if the function language is a compatible one */
  1053 + for (langno = 0; langno < langlen; langno++)
1070 1054 {
1071   - lslangtupoid = HeapTupleGetOid(tuple);
1072   - ReleaseSysCache(tuple);
  1055 + tuple = SearchSysCache(LANGNAME, NameGetDatum(&langnames[langno]), 0, 0, 0);
  1056 + if (HeapTupleIsValid(tuple))
  1057 + {
  1058 + Oid langtupoid = HeapTupleGetOid(tuple);
  1059 + ReleaseSysCache(tuple);
  1060 + if (langtupoid == prolang)
  1061 + break;
  1062 + }
1073 1063 }
1074 1064
1075   - Local<Function> func;
1076   -
1077   - /* Non-JS function */
1078   - if (prolang == InvalidOid ||
1079   - (v8langtupoid != prolang && coffeelangtupoid != prolang && lslangtupoid != prolang))
  1065 + /* Not found or non-JS function */
  1066 + if (langno >= langlen)
1080 1067 return func;
1081 1068
1082 1069 try
1083 1070 {
1084 1071 plv8_proc *proc = Compile(fn_oid,CurrentMemoryContext,
1085 1072 true, false,
1086   - ( (coffeelangtupoid == prolang) ? PLV8_DIALECT_COFFEE
1087   - : (lslangtupoid == prolang) ? PLV8_DIALECT_LIVESCRIPT
1088   - : PLV8_DIALECT_NONE ));
  1073 + (Dialect) (PLV8_DIALECT_NONE + langno));
1089 1074
1090 1075 TryCatch try_catch;
1091 1076
7 plv8.control
... ... @@ -1,7 +0,0 @@
1   -# plv8 extension
2   -comment = 'PL/JavaScript (v8) trusted procedural language'
3   -default_version = '1.3.0devel'
4   -module_pathname = '$libdir/plv8'
5   -relocatable = false
6   -schema = pg_catalog
7   -superuser = true
15 plv8.control.common
... ... @@ -0,0 +1,15 @@
  1 +#if defined LANG_plv8
  2 +## plv8 extension
  3 +comment = 'PL/JavaScript (v8) trusted procedural language'
  4 +#elif defined LANG_plcoffee
  5 +## plcoffee extension
  6 +comment = 'PL/CoffeeScript (v8) trusted procedural language'
  7 +#elif defined LANG_plls
  8 +## plls extension
  9 +comment = 'PL/LiveScript (v8) trusted procedural language'
  10 +#endif
  11 +default_version = '@PLV8_VERSION@'
  12 +module_pathname = '$libdir/plv8'
  13 +relocatable = false
  14 +schema = pg_catalog
  15 +superuser = true
14 plv8.sql.c → plv8.sql.common
@@ -6,23 +6,23 @@ SET search_path = public;
6 6 BEGIN;
7 7 #endif
8 8
9   -CREATE FUNCTION plv8_call_handler() RETURNS language_handler
  9 +CREATE FUNCTION @LANG_NAME@_call_handler() RETURNS language_handler
10 10 AS 'MODULE_PATHNAME' LANGUAGE C;
11 11
12 12 #if PG_VERSION_NUM >= 90000
13   -CREATE FUNCTION plv8_inline_handler(internal) RETURNS void
  13 +CREATE FUNCTION @LANG_NAME@_inline_handler(internal) RETURNS void
14 14 AS 'MODULE_PATHNAME' LANGUAGE C;
15 15 #endif
16 16
17   -CREATE FUNCTION plv8_call_validator(oid) RETURNS void
  17 +CREATE FUNCTION @LANG_NAME@_call_validator(oid) RETURNS void
18 18 AS 'MODULE_PATHNAME' LANGUAGE C;
19 19
20   -CREATE TRUSTED LANGUAGE plv8
21   - HANDLER plv8_call_handler
  20 +CREATE TRUSTED LANGUAGE @LANG_NAME@
  21 + HANDLER @LANG_NAME@_call_handler
22 22 #if PG_VERSION_NUM >= 90000
23   - INLINE plv8_inline_handler
  23 + INLINE @LANG_NAME@_inline_handler
24 24 #endif
25   - VALIDATOR plv8_call_validator;
  25 + VALIDATOR @LANG_NAME@_call_validator;
26 26
27 27 #if PG_VERSION_NUM < 90100
28 28 COMMIT;
20 sql/dialect.sql
... ... @@ -0,0 +1,20 @@
  1 +CREATE EXTENSION plcoffee;
  2 +DO LANGUAGE plcoffee $$ plv8.elog(INFO, "foo") $$;
  3 +CREATE EXTENSION plls;
  4 +DO LANGUAGE plls $$ plv8.elog(INFO, "foo") $$;
  5 +
  6 +CREATE FUNCTION v8func(a int) RETURNS int[] AS $$
  7 +return [a, a, a];
  8 +$$ LANGUAGE plv8;
  9 +
  10 +CREATE FUNCTION coffeefunc(a int) RETURNS int[] AS $$
  11 +return plv8.find_function('v8func')(a);
  12 +$$ LANGUAGE plcoffee;
  13 +
  14 +SELECT coffeefunc(10);
  15 +
  16 +CREATE FUNCTION lsfunc(a int) RETURNS int[] AS $$
  17 +return plv8.find_function('v8func')(a);
  18 +$$ LANGUAGE plls;
  19 +
  20 +SELECT lsfunc(11);

0 comments on commit e719760

Please sign in to comment.
Something went wrong with that request. Please try again.