Permalink
Browse files

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...
1 parent d0cde70 commit e7197601723468a2917ac61b9c68b814b1c06240 @umitanuki umitanuki committed Sep 25, 2012
Showing with 120 additions and 127 deletions.
  1. +24 −37 Makefile
  2. +27 −0 expected/dialect.out
  3. +0 −10 plcoffee--0.9.0.sql
  4. +0 −7 plcoffee.control
  5. +0 −10 plls--0.9.0.sql
  6. +0 −7 plls.control
  7. +27 −42 plv8.cc
  8. +0 −7 plv8.control
  9. +15 −0 plv8.control.common
  10. +7 −7 plv8.sql.c → plv8.sql.common
  11. +20 −0 sql/dialect.sql
View
61 Makefile
@@ -6,8 +6,7 @@
# @param V8_OUTDIR path to V8 output directory, used for library files
# @param V8_STATIC_SNAPSHOT if defined, statically link to v8 with snapshot
# @param V8_STATIC_NOSNAPSHOT if defined, statically link to v8 w/o snapshot
-# @param ENABLE_COFFEE if defined, build plcoffee
-# @param ENABLE_LIVESCRIPT if defined, build plls
+# @param DISABLE_DIALECT if defined, not build dialects (i.e. plcoffee, etc)
#
# There are three ways to build plv8.
# 1. Dynamic link to v8 (default)
@@ -34,9 +33,17 @@ SRCS = plv8.cc plv8_type.cc plv8_func.cc plv8_param.cc $(JSCS)
OBJS = $(SRCS:.cc=.o)
MODULE_big = plv8
EXTENSION = plv8
-DATA = plv8.control plv8--$(PLV8_VERSION).sql
+PLV8_DATA = plv8.control plv8--$(PLV8_VERSION).sql
+DATA = $(PLV8_DATA)
+ifndef DISABLE_DIALECT
+DATA += plcoffee.control plcoffee--$(PLV8_VERSION).sql \
+ plls.control plls--$(PLV8_VERSION).sql
+endif
DATA_built = plv8.sql
REGRESS = init-extension plv8 inline json startup_pre startup varparam
+ifndef DISABLE_DIALECT
+REGRESS += dialect
+endif
# V8 build options. See the top comment.
V8_STATIC_SNAPSHOT_LIBS = libv8_base.a libv8_snapshot.a
@@ -68,23 +75,6 @@ ifdef V8_SRCDIR
override CPPFLAGS += -I$(V8_SRCDIR)/include
endif
-# plcoffee is available only when ENABLE_COFFEE is defined.
-ifdef ENABLE_COFFEE
-ifdef ENABLE_LIVESCRIPT
- CCFLAGS := -DENABLE_COFFEE -DENABLE_LIVESCRIPT $(CCFLAGS)
- DATA = plcoffee.control plcoffee--0.9.0.sql plls.control plls--0.9.0.sql
-else
- CCFLAGS := -DENABLE_COFFEE $(CCFLAGS)
- DATA = plcoffee.control plcoffee--0.9.0.sql
-endif
-else
-# plls is available only when ENABLE_LIVESCRIPT is defined.
-ifdef ENABLE_LIVESCRIPT
- CCFLAGS := -DENABLE_LIVESCRIPT $(CCFLAGS)
- DATA = plls.control plls--0.9.0.sql
-endif
-endif
-
all:
plv8_config.h: plv8_config.h.in Makefile
@@ -96,43 +86,40 @@ plv8_config.h: plv8_config.h.in Makefile
# Convert .js to .cc
$(JSCS): %.cc: %.js
echo "extern const unsigned char $(subst -,_,$(basename $@))_binary_data[] = {" >$@
-ifdef ENABLE_COFFEE
+ifndef DISABLE_DIALECT
(od -txC -v $< | \
sed -e "s/^[0-9]*//" -e s"/ \([0-9a-f][0-9a-f]\)/0x\1,/g" -e"\$$d" ) >>$@
-else
-ifdef ENABLE_LIVESCRIPT
- (od -txC -v $< | \
- sed -e "s/^[0-9]*//" -e s"/ \([0-9a-f][0-9a-f]\)/0x\1,/g" -e"\$$d" ) >>$@
-endif
endif
echo "0x00};" >>$@
# VERSION specific definitions
ifeq ($(shell test $(PG_VERSION_NUM) -ge 90100 && echo yes), yes)
-plv8.sql:
+
DATA_built =
-install: plv8--$(PLV8_VERSION).sql
-plv8--$(PLV8_VERSION).sql: plv8.sql.c
- $(CC) -E -P $(CPPFLAGS) $< > $@
+all: $(DATA)
+%--$(PLV8_VERSION).sql: plv8.sql.common
+ sed -e 's/@LANG_NAME@/$*/g' $< | $(CC) -E -P $(CPPFLAGS) - > $@
+%.control: plv8.control.common
+ sed -e 's/@PLV8_VERSION@/$(PLV8_VERSION)/g' $< | $(CC) -E -P -DLANG_$* - > $@
subclean:
- rm -f plv8_config.h plv8--$(PLV8_VERSION).sql $(JSCS)
+ rm -f plv8_config.h $(DATA) $(JSCS)
else # < 9.1
-ifeq ($(shell test $(PG_VERSION_NUM) -ge 90000 && echo yes), yes)
-REGRESS := init $(filter-out init-extension, $(REGRESS))
+ifeq ($(shell test $(PG_VERSION_NUM) -ge 90000 && echo yes), yes)
+REGRESS := init $(filter-out init-extension dialect, $(REGRESS))
else # < 9.0
-REGRESS := init $(filter-out init-extension inline startup varparam, $(REGRESS))
+REGRESS := init $(filter-out init-extension inline startup varparam dialect, $(REGRESS))
endif
DATA = uninstall_plv8.sql
-plv8.sql.in: plv8.sql.c
- $(CC) -E -P $(CPPFLAGS) $< > $@
+%.sql.in: plv8.sql.common
+ sed -e 's/@LANG_NAME@/$*/g' $< | $(CC) -E -P $(CPPFLAGS) - > $@
subclean:
- rm -f plv8_config.h plv8.sql.in $(JSCS)
+ rm -f plv8_config.h *.sql.in $(JSCS)
endif
View
27 expected/dialect.out
@@ -0,0 +1,27 @@
+CREATE EXTENSION plcoffee;
+DO LANGUAGE plcoffee $$ plv8.elog(INFO, "foo") $$;
+INFO: foo
+CREATE EXTENSION plls;
+DO LANGUAGE plls $$ plv8.elog(INFO, "foo") $$;
+INFO: foo
+CREATE FUNCTION v8func(a int) RETURNS int[] AS $$
+return [a, a, a];
+$$ LANGUAGE plv8;
+CREATE FUNCTION coffeefunc(a int) RETURNS int[] AS $$
+return plv8.find_function('v8func')(a);
+$$ LANGUAGE plcoffee;
+SELECT coffeefunc(10);
+ coffeefunc
+------------
+ {10,10,10}
+(1 row)
+
+CREATE FUNCTION lsfunc(a int) RETURNS int[] AS $$
+return plv8.find_function('v8func')(a);
+$$ LANGUAGE plls;
+SELECT lsfunc(11);
+ lsfunc
+------------
+ {11,11,11}
+(1 row)
+
View
10 plcoffee--0.9.0.sql
@@ -1,10 +0,0 @@
-CREATE FUNCTION plcoffee_call_handler() RETURNS language_handler
- AS 'MODULE_PATHNAME' LANGUAGE C;
-CREATE FUNCTION plcoffee_inline_handler(internal) RETURNS void
- AS 'MODULE_PATHNAME' LANGUAGE C;
-CREATE FUNCTION plcoffee_call_validator(oid) RETURNS void
- AS 'MODULE_PATHNAME' LANGUAGE C;
-CREATE TRUSTED LANGUAGE plcoffee
- HANDLER plcoffee_call_handler
- INLINE plcoffee_inline_handler
- VALIDATOR plcoffee_call_validator;
View
7 plcoffee.control
@@ -1,7 +0,0 @@
-# plcoffee extension
-comment = 'PL/CoffeeScript (v8) trusted procedural language'
-default_version = '0.9.0'
-module_pathname = '$libdir/plv8'
-relocatable = false
-schema = pg_catalog
-superuser = true
View
10 plls--0.9.0.sql
@@ -1,10 +0,0 @@
-CREATE FUNCTION plls_call_handler() RETURNS language_handler
- AS 'MODULE_PATHNAME' LANGUAGE C;
-CREATE FUNCTION plls_inline_handler(internal) RETURNS void
- AS 'MODULE_PATHNAME' LANGUAGE C;
-CREATE FUNCTION plls_call_validator(oid) RETURNS void
- AS 'MODULE_PATHNAME' LANGUAGE C;
-CREATE TRUSTED LANGUAGE plls
- HANDLER plls_call_handler
- INLINE plls_inline_handler
- VALIDATOR plls_call_validator;
View
7 plls.control
@@ -1,7 +0,0 @@
-# plls extension
-comment = 'PL/LiveScript (v8) trusted procedural language'
-default_version = '0.9.0'
-module_pathname = '$libdir/plv8'
-relocatable = false
-schema = pg_catalog
-superuser = true
View
69 plv8.cc
@@ -867,22 +867,20 @@ CompileDialect(const char *src, Dialect dialect)
switch (dialect)
{
case PLV8_DIALECT_COFFEE:
-#ifndef ENABLE_COFFEE
- throw js_error("CoffeeScript is not enabled");
-#endif
+ if (coffee_script_binary_data[0] == '\0')
+ throw js_error("CoffeeScript is not enabled");
key = String::NewSymbol("CoffeeScript");
dialect_binary_data = (const char *) coffee_script_binary_data;
break;
case PLV8_DIALECT_LIVESCRIPT:
-#ifndef ENABLE_LIVESCRIPT
- throw js_error("LiveScript is not enabled");
-#endif
+ if (livescript_binary_data[0] == '\0')
+ throw js_error("LiveScript is not enabled");
key = String::NewSymbol("LiveScript");
dialect_binary_data = (const char *) livescript_binary_data;
break;
default:
throw js_error("Unknown Dialect");
- }
+ }
if (context->Global()->Get(key)->IsUndefined())
{
@@ -1033,10 +1031,12 @@ find_js_function(Oid fn_oid)
{
HeapTuple tuple;
Form_pg_proc proc;
- Oid prolang, v8langtupoid, coffeelangtupoid, lslangtupoid;
- NameData v8langname = { "plv8" },
- coffeelangname = { "plcoffee" },
- lslangname = { "plls" };
+ Oid prolang;
+ NameData langnames[] = { {"plv8"}, {"plcoffee"}, {"plls"} };
+ int langno;
+ int langlen = sizeof(langnames) / sizeof(NameData);
+ Local<Function> func;
+
tuple = SearchSysCache(PROCOID, ObjectIdGetDatum(fn_oid), 0, 0, 0);
if (!HeapTupleIsValid(tuple))
@@ -1045,47 +1045,32 @@ find_js_function(Oid fn_oid)
prolang = proc->prolang;
ReleaseSysCache(tuple);
- tuple = SearchSysCache(LANGNAME, NameGetDatum(&v8langname), 0, 0, 0);
- if (!HeapTupleIsValid(tuple))
- v8langtupoid = InvalidOid;
- else
- {
- v8langtupoid = HeapTupleGetOid(tuple);
- ReleaseSysCache(tuple);
- }
-
- tuple = SearchSysCache(LANGNAME, NameGetDatum(&coffeelangname), 0, 0, 0);
- if (!HeapTupleIsValid(tuple))
- coffeelangtupoid = InvalidOid;
- else
- {
- coffeelangtupoid = HeapTupleGetOid(tuple);
- ReleaseSysCache(tuple);
- }
+ /* Should not happen? */
+ if (!OidIsValid(prolang))
+ return func;
- tuple = SearchSysCache(LANGNAME, NameGetDatum(&lslangname), 0, 0, 0);
- if (!HeapTupleIsValid(tuple))
- lslangtupoid = InvalidOid;
- else
+ /* See if the function language is a compatible one */
+ for (langno = 0; langno < langlen; langno++)
{
- lslangtupoid = HeapTupleGetOid(tuple);
- ReleaseSysCache(tuple);
+ tuple = SearchSysCache(LANGNAME, NameGetDatum(&langnames[langno]), 0, 0, 0);
+ if (HeapTupleIsValid(tuple))
+ {
+ Oid langtupoid = HeapTupleGetOid(tuple);
+ ReleaseSysCache(tuple);
+ if (langtupoid == prolang)
+ break;
+ }
}
- Local<Function> func;
-
- /* Non-JS function */
- if (prolang == InvalidOid ||
- (v8langtupoid != prolang && coffeelangtupoid != prolang && lslangtupoid != prolang))
+ /* Not found or non-JS function */
+ if (langno >= langlen)
return func;
try
{
plv8_proc *proc = Compile(fn_oid,CurrentMemoryContext,
true, false,
- ( (coffeelangtupoid == prolang) ? PLV8_DIALECT_COFFEE
- : (lslangtupoid == prolang) ? PLV8_DIALECT_LIVESCRIPT
- : PLV8_DIALECT_NONE ));
+ (Dialect) (PLV8_DIALECT_NONE + langno));
TryCatch try_catch;
View
7 plv8.control
@@ -1,7 +0,0 @@
-# plv8 extension
-comment = 'PL/JavaScript (v8) trusted procedural language'
-default_version = '1.3.0devel'
-module_pathname = '$libdir/plv8'
-relocatable = false
-schema = pg_catalog
-superuser = true
View
15 plv8.control.common
@@ -0,0 +1,15 @@
+#if defined LANG_plv8
+## plv8 extension
+comment = 'PL/JavaScript (v8) trusted procedural language'
+#elif defined LANG_plcoffee
+## plcoffee extension
+comment = 'PL/CoffeeScript (v8) trusted procedural language'
+#elif defined LANG_plls
+## plls extension
+comment = 'PL/LiveScript (v8) trusted procedural language'
+#endif
+default_version = '@PLV8_VERSION@'
+module_pathname = '$libdir/plv8'
+relocatable = false
+schema = pg_catalog
+superuser = true
View
14 plv8.sql.c → plv8.sql.common
@@ -6,23 +6,23 @@ SET search_path = public;
BEGIN;
#endif
-CREATE FUNCTION plv8_call_handler() RETURNS language_handler
+CREATE FUNCTION @LANG_NAME@_call_handler() RETURNS language_handler
AS 'MODULE_PATHNAME' LANGUAGE C;
#if PG_VERSION_NUM >= 90000
-CREATE FUNCTION plv8_inline_handler(internal) RETURNS void
+CREATE FUNCTION @LANG_NAME@_inline_handler(internal) RETURNS void
AS 'MODULE_PATHNAME' LANGUAGE C;
#endif
-CREATE FUNCTION plv8_call_validator(oid) RETURNS void
+CREATE FUNCTION @LANG_NAME@_call_validator(oid) RETURNS void
AS 'MODULE_PATHNAME' LANGUAGE C;
-CREATE TRUSTED LANGUAGE plv8
- HANDLER plv8_call_handler
+CREATE TRUSTED LANGUAGE @LANG_NAME@
+ HANDLER @LANG_NAME@_call_handler
#if PG_VERSION_NUM >= 90000
- INLINE plv8_inline_handler
+ INLINE @LANG_NAME@_inline_handler
#endif
- VALIDATOR plv8_call_validator;
+ VALIDATOR @LANG_NAME@_call_validator;
#if PG_VERSION_NUM < 90100
COMMIT;
View
20 sql/dialect.sql
@@ -0,0 +1,20 @@
+CREATE EXTENSION plcoffee;
+DO LANGUAGE plcoffee $$ plv8.elog(INFO, "foo") $$;
+CREATE EXTENSION plls;
+DO LANGUAGE plls $$ plv8.elog(INFO, "foo") $$;
+
+CREATE FUNCTION v8func(a int) RETURNS int[] AS $$
+return [a, a, a];
+$$ LANGUAGE plv8;
+
+CREATE FUNCTION coffeefunc(a int) RETURNS int[] AS $$
+return plv8.find_function('v8func')(a);
+$$ LANGUAGE plcoffee;
+
+SELECT coffeefunc(10);
+
+CREATE FUNCTION lsfunc(a int) RETURNS int[] AS $$
+return plv8.find_function('v8func')(a);
+$$ LANGUAGE plls;
+
+SELECT lsfunc(11);

0 comments on commit e719760

Please sign in to comment.