public inbox for [email protected]  
help / color / mirror / Atom feed
From: Christian Ferrari <[email protected]>
To: [email protected]
Subject: Re: Integration of Psycopg with XTA
Date: Tue, 2 Oct 2018 20:07:50 +0000 (UTC)
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
	<[email protected]>
	<CA+mi_8a5Sm=Zum+8uRX+gDLrzzEU+F-x5xjommxL5e7jLBxHkg@mail.gmail.com>
	<[email protected]>
	<CA+mi_8bZ-hxA2DTshOh15b1GdbET8+EVO5eh9N2qyyfvDgXKCw@mail.gmail.com>
	<[email protected]>
	<[email protected]>

Hi Federico,I have been able to test _raw_pgconn using SWIG, as documented here https://sourceforge.net/p/swig/mailman/message/27919299/ , the trick to use PyCapsule and SWIG together is to specifically map the type with a directive like this one:
%typemap(in) PGconn * {
  $1 = (PGconn *) PyCapsule_GetPointer($input, "psycopg2.connection._raw_pgconn");
}

This is interesting because PyCapsule is for sure a "clean" way to pass the pointer from Psycopg to XTA.

A couple of questions to understand how to implement it as a re-usable deliverable.
In current branch, _raw_pgconn is a property, it's not a method, I have to retrieve it as below:
pgconn = rm1._raw_pgconn
xar1 = PostgresqlXaResource(pgconn, "PostgreSQL", "dbname=testdb")

what do you think about a "getter method":
pgconn = rm1._raw_pgconn()
the name of the method does not really matter to me.
_raw_pgconn() create a Capsule object that should be destroyed.What do you think about a factory to create and destroy a PyCapsule that contains the PGconn pointer?
Kind RegardsCh.F.

-------------------------------------------------------------
Good design can't stop bad implementation
 

    Il giovedì 27 settembre 2018, 22:11:35 CEST, Federico Di Gregorio <[email protected]> ha scritto:  
 
 On 09/27/2018 09:57 PM, Christian Ferrari wrote:
> Thanks, for the fix, now the function works, but unfortunately it's a 
> dead end in the SWIG realm...Here's the statement: 
> http://www.swig.org/Doc2.0/SWIGDocumentation.html#Python_nn18
> [...]
> *However, the inverse operation is not possible, i.e., you can't build a 
> SWIG pointer object from a raw integer value.*
> [...]
> 
> PyCapsule https://docs.python.org/2/c-api/capsule.html, suggested by 
> Federico seems a more viable approach:
> https://bfroehle.com/2011/07/18/python-capsules/
> 
> If Psycopg was able to retrieve a PyCapsule, XTA should be able to use 
> it and the Python interpreter would be a gateway between two C/C++ 
> distinct modules (Psycopg and XTA).
> I'm going to perform some experiments in the XTA wrapper before coming 
> back to this mail thread.

If you want the capsule, just pull from my report:

https://github.com/fogzot/psycopg2/tree/feature-expose-pgconn

and use the feature-expose-pgconn branch.

federico

-- 
Federico Di Gregorio                        [email protected]
DNDG srl                                                  http://dndg.it
  Everything will be OK at the end. If it's not OK, it's not the end.
                                                              -- Unknown

  

view thread (22+ 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: Integration of Psycopg with XTA
  In-Reply-To: <[email protected]>

* 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