public inbox for [email protected]  
help / color / mirror / Atom feed
From: Francois-Guillaume Ribreau <[email protected]>
To: [email protected]
Subject: Best practice: call an internal postgresql function (e.g. raw_parser) from another C/Rust binary
Date: Tue, 3 Nov 2020 22:38:19 +0100
Message-ID: <CAOpx105CqjtkDLxyT6P0ftyWCHgigm7jhutonbitCg-YUw5eGQ@mail.gmail.com> (raw)

Hello!

(PostgreSQL rocks)

I wonder what is the easiest way to extract and (ab)use the raw_parser
function out of postgresql codebase, as a library, so I can use it from my
own code in Rust.

My C is rusty (pun intended) so I tried this:

cd src/backend/parser
gcc -I../../include -fpic -c parser.c

so raw_parser is present (yey):

nm parser.o | grep raw_parser
0000000000000000 T _raw_parser

but I missed lots of other implementation files (doh) ^^

 nm parser.o | grep U
                 U _ScanKeywordTokens
                 U _ScanKeywords
                 U _base_yyparse
                 U _cancel_scanner_errposition_callback
                 U _core_yylex
                 U _errcode
                 U _errfinish
                 U _errhint
                 U _errmsg
                 U _errmsg_internal
                 U _errstart
                 U _isxdigit
                 U _palloc
                 U _parser_init
                 U _pg_unicode_to_server
                 U _repalloc
                 U _scanner_errposition
                 U _scanner_finish
                 U _scanner_init
                 U _scanner_isspace
                 U _scanner_yyerror
                 U _setup_scanner_errposition_callback
                 U _strlen
                 U _truncate_identifier

I started to include them one by one but the task is tedious and I'm pretty
sure there is an easier way :)

So I did take a look at various makefile in contrib/ folder but I'm not
sure adapting them will do want I want, I do not want to make an extension
for postgresql but instead generate an .a library that I can access from
Rust through FFI.

Does anyone tried this before?

PS: If you are interested, here is the repository:
https://github.com/FGRibreau/poc-pgsql-parser


view thread (4+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: Best practice: call an internal postgresql function (e.g. raw_parser) from another C/Rust binary
  In-Reply-To: <CAOpx105CqjtkDLxyT6P0ftyWCHgigm7jhutonbitCg-YUw5eGQ@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox