diff --git a/Cargo.toml b/Cargo.toml index cf7907d..e7172a8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,11 +2,12 @@ name = "postgres_extension" version = "0.0.1" -authors = ["Daniel Fagnan "] +authors = ["Daniel Fagnan ", + "Jeff Davis "] [lib] name = "postgres_extension" -crate-type = ["dylib"] +crate-type = ["rlib"] [dependencies] libc = "*" diff --git a/macros/Cargo.toml b/macros/Cargo.toml index 621bebc..0ce1d34 100644 --- a/macros/Cargo.toml +++ b/macros/Cargo.toml @@ -2,8 +2,9 @@ name = "postgres_extension_macros" version = "0.0.1" -authors = ["Daniel Fagnan "] +authors = ["Daniel Fagnan ", + "Jeff Davis "] [lib] name = "postgres_extension_macros" -crate-type = ["dylib", "rlib"] +crate-type = ["rlib"] diff --git a/macros/src/lib.rs b/macros/src/lib.rs index b13b97d..1262aad 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -1,58 +1,3 @@ -#![feature(plugin_registrar, quote, box_syntax, rustc_private)] -#![allow(unused_imports)] - -extern crate syntax; -extern crate syntax_ext; -extern crate rustc; -extern crate rustc_front; -extern crate rustc_plugin; - -use rustc_plugin::Registry; -use syntax::ext::base::{MultiDecorator, MultiModifier}; -use syntax::parse::token::intern; -use rustc::front::map::blocks::MaybeFnLike; - -use syntax::ext::base::{ExtCtxt, Annotatable}; -use syntax::codemap::Span; -use syntax::ptr::P; - -use syntax::ast::{Item, ItemFn, MetaItem}; -use syntax::attr; -use syntax_ext::deriving::generic::{combine_substructure, EnumMatching, FieldInfo, MethodDef, Struct, Substructure, TraitDef, ty}; -use syntax::parse::token::InternedString; - -#[plugin_registrar] -pub fn plugin_registrar(reg: &mut Registry) { - reg.register_syntax_extension(intern("pg_export"), MultiModifier(box expand_pg_export)); -} - -pub fn expand_pg_export(cx: &mut ExtCtxt, span: Span, _: &MetaItem, item: Annotatable) -> Annotatable { - - //TODO: enforce func type check - // if !func.is_fn_like() { - // cx.span_err(span, "you can only export a function to PostgreSQL."); - // } - - match item { - Annotatable::Item(it) => { - let mut new_it = (*it).clone(); - new_it.attrs.push(attr::mk_attr_outer(attr::mk_attr_id(), attr::mk_word_item(InternedString::new("no_mangle")))); - Annotatable::Item(P(new_it)) - } - Annotatable::ImplItem(it) => { - let mut new_it = (*it).clone(); - new_it.attrs.push(attr::mk_attr_outer(attr::mk_attr_id(), attr::mk_word_item(InternedString::new("no_mangle")))); - Annotatable::ImplItem(P(new_it)) - } - Annotatable::TraitItem(tt) => { - let mut new_it = (*tt).clone(); - new_it.attrs.push(attr::mk_attr_outer(attr::mk_attr_id(), attr::mk_word_item(InternedString::new("no_mangle")))); - Annotatable::TraitItem(P(new_it)) - } - } - -} - /// Postgres has a macro called `PG_MODULE_MAGIC` that is supposed /// to be called within extensions. This generates a bunch /// of metadata structures that Postgres reads to determine diff --git a/plugin/Cargo.toml b/plugin/Cargo.toml new file mode 100644 index 0000000..f92d00b --- /dev/null +++ b/plugin/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "postgres_extension_plugin" +version = "0.0.1" +authors = ["Daniel Fagnan ", + "Jeff Davis "] + +[dependencies] + +[lib] +crate-type = ["dylib"] + diff --git a/plugin/src/lib.rs b/plugin/src/lib.rs new file mode 100644 index 0000000..e7c0f7a --- /dev/null +++ b/plugin/src/lib.rs @@ -0,0 +1,54 @@ +#![feature(plugin_registrar, quote, box_syntax, rustc_private)] +#![allow(unused_imports)] + +extern crate syntax; +extern crate syntax_ext; +extern crate rustc; +extern crate rustc_plugin; + +use rustc_plugin::Registry; +use syntax::ext::base::{MultiDecorator, MultiModifier}; +use syntax::parse::token::intern; +use rustc::hir::map::blocks::MaybeFnLike; + +use syntax::ext::base::{ExtCtxt, Annotatable}; +use syntax::codemap::Span; +use syntax::ptr::P; + +use syntax::ast::{Item, MetaItem}; +use syntax::attr; +use syntax_ext::deriving::generic::{combine_substructure, EnumMatching, FieldInfo, MethodDef, Struct, Substructure, TraitDef, ty}; +use syntax::parse::token::InternedString; + +#[plugin_registrar] +pub fn plugin_registrar(reg: &mut Registry) { + reg.register_syntax_extension(intern("pg_export"), MultiModifier(box expand_pg_export)); +} + +pub fn expand_pg_export(_cx: &mut ExtCtxt, _span: Span, _: &MetaItem, item: Annotatable) -> Annotatable { + + //TODO: enforce func type check + // if !func.is_fn_like() { + // cx.span_err(span, "you can only export a function to PostgreSQL."); + // } + + match item { + Annotatable::Item(it) => { + let mut new_it = (*it).clone(); + new_it.attrs.push(attr::mk_attr_outer(attr::mk_attr_id(), attr::mk_word_item(InternedString::new("no_mangle")))); + Annotatable::Item(P(new_it)) + } + Annotatable::ImplItem(it) => { + let mut new_it = (*it).clone(); + new_it.attrs.push(attr::mk_attr_outer(attr::mk_attr_id(), attr::mk_word_item(InternedString::new("no_mangle")))); + Annotatable::ImplItem(P(new_it)) + } + Annotatable::TraitItem(tt) => { + let mut new_it = (*tt).clone(); + new_it.attrs.push(attr::mk_attr_outer(attr::mk_attr_id(), attr::mk_word_item(InternedString::new("no_mangle")))); + Annotatable::TraitItem(P(new_it)) + } + } + +} + diff --git a/src/lib.rs b/src/lib.rs index 79a0c8a..2b9675f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,4 @@ -#![feature(core)] +#![allow(non_camel_case_types)] extern crate libc; extern crate core; @@ -14,7 +14,7 @@ type fmNodePtr = *mut c_void; type fmAggrefPtr = *mut c_void; /// A trait that is implemented for all Postgres-compatible data types. -trait PgType {} +pub trait PgType {} #[allow(dead_code)] extern { @@ -460,6 +460,7 @@ pub struct FunctionCallInfoData { } pub struct FunctionCallInfo<'a> { + #[allow(dead_code)] ptr: *mut FunctionCallInfoData, marker: PhantomData<&'a FunctionCallInfoData> } @@ -468,11 +469,12 @@ pub struct FunctionCallInfo<'a> { /// a pointer-sized unsigned integer that acts like /// a pointer. pub struct Datum { + #[allow(dead_code)] val: usize } impl Datum { - pub fn new_str(value: &str) -> Datum { + pub fn new_str(_value: &str) -> Datum { // We need to allocate our string onto the heap // and with the custom `palloc` allocator. `palloc` // allocates memory into contexts such that they