Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g7Qxd-0005uc-1f for psycopg@arkaria.postgresql.org; Tue, 02 Oct 2018 20:08:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g7Qxa-0001zt-9W for psycopg@arkaria.postgresql.org; Tue, 02 Oct 2018 20:07:58 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g7QxZ-0001zm-Vm for psycopg@lists.postgresql.org; Tue, 02 Oct 2018 20:07:58 +0000 Received: from sonic306-20.consmr.mail.ir2.yahoo.com ([77.238.176.206]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g7QxW-0007Yx-By for psycopg@lists.postgresql.org; Tue, 02 Oct 2018 20:07:57 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1538510872; bh=y5UrfsVHYmbiDzEDVDFryGH7X/+z+zRL+5YD5MM1i80=; h=Date:From:Reply-To:To:In-Reply-To:References:Subject:From:Subject; b=ctlNfdYhwA+A3hHjRupO7NCSaPvq3AR/OMa0aG16TQLoULcWePTD2vbqBd7q4WxeAZOB0pQMfWc6aOmG02PRXhHfT77aGojDuASIHtuSt8QxqyZm23tPLn3L1Eto4Zi7Wtzy4dCcsiKiwlU6Kx6S7p/GLh/nwT965q0c5E+xp2gAUrW9r/cSGhqyRoJatrLhlQxSsgKzBL/GoZMCTMMsuakJ+sUpHo9bs7kn+RoHqBEhnVPGCD74G+yPP3OWiaIYXW91A3yNLkK7uld3zY81VKejh9KLgt5vswBULdoKByEw0UgWE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Qbab28JkeFFU6KtIchBrMTEDjxXlYQD YMWXP.MR4 Received: from sonic.gate.mail.ne1.yahoo.com by sonic306.consmr.mail.ir2.yahoo.com with HTTP; Tue, 2 Oct 2018 20:07:52 +0000 Date: Tue, 2 Oct 2018 20:07:50 +0000 (UTC) From: Christian Ferrari Reply-To: Christian Ferrari To: psycopg@lists.postgresql.org Message-ID: <106450562.4254785.1538510870700@mail.yahoo.com> In-Reply-To: References: <2001056273.7945904.1537909025251.ref@mail.yahoo.com> <2001056273.7945904.1537909025251@mail.yahoo.com> <1171000727.19526618.1537994198139@mail.yahoo.com> <2038369023.20583382.1538078255866@mail.yahoo.com> Subject: Re: Integration of Psycopg with XTA MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_4254784_604447355.1538510870697" X-Mailer: WebService/1.1.12512 YMailNorrin Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:62.0) Gecko/20100101 Firefox/62.0 Content-Length: 9084 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk ------=_Part_4254784_604447355.1538510870697 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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 t= o use PyCapsule and SWIG together is to specifically map the type with a di= rective like this one: %typemap(in) PGconn * { =C2=A0 $1 =3D (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 deli= verable. In current branch, _raw_pgconn is a property, it's not a method, I have to = retrieve it as below: pgconn =3D rm1._raw_pgconn xar1 =3D PostgresqlXaResource(pgconn, "PostgreSQL", "dbname=3Dtestdb") what do you think about a "getter method": pgconn =3D 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 P= Gconn pointer? Kind RegardsCh.F. ------------------------------------------------------------- Good design can't stop bad implementation =20 Il gioved=C3=AC 27 settembre 2018, 22:11:35 CEST, Federico Di Gregorio = ha scritto: =20 =20 On 09/27/2018 09:57 PM, Christian Ferrari wrote: > Thanks, for the fix, now the function works, but unfortunately it's a=20 > dead end in the SWIG realm...Here's the statement:=20 > http://www.swig.org/Doc2.0/SWIGDocumentation.html#Python_nn18 > [...] > *However, the inverse operation is not possible, i.e., you can't build a= =20 > SWIG pointer object from a raw integer value.* > [...] >=20 > PyCapsule https://docs.python.org/2/c-api/capsule.html, suggested by=20 > Federico seems a more viable approach: > https://bfroehle.com/2011/07/18/python-capsules/ >=20 > If Psycopg was able to retrieve a PyCapsule, XTA should be able to use=20 > it and the Python interpreter would be a gateway between two C/C++=20 > distinct modules (Psycopg and XTA). > I'm going to perform some experiments in the XTA wrapper before coming=20 > 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 --=20 Federico Di Gregorio=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 federico.digregorio@dndg.it DNDG srl=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 http://dndg.it =C2=A0 Everything will be OK at the end. If it's not OK, it's not the end. =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 -- Un= known =20 ------=_Part_4254784_604447355.1538510870697 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi Federico,
I have been able to test _raw_pgconn using SWIG, as documented her= e https://sourceforge.net/p/swig/mailman/mess= age/27919299/ , the trick to use PyCapsule and SWIG together is to spec= ifically map the type with a directive like this one:

%= typemap(in) PGconn * {
  $1 =3D (PGconn *) PyCapsule_GetPointer($in= put, "psycopg2.connection._raw_pgconn");
}

This is in= teresting because PyCapsule is for sure a "clean" way to pass the pointer f= rom Psycopg to XTA.


A couple of que= stions to understand how to implement it as a re-usable deliverable.
<= div>
In current branch, _raw_pgconn is a property, it's not a= method, I have to retrieve it as below:

pgc= onn =3D rm1._raw_pgconn
xar1 =3D PostgresqlXaResource(pgconn, "PostgreSQ= L", "dbname=3Dtestdb")

what do you think about a "getter= method":

pgconn =3D rm1._raw_pgconn()

the name of the method does not rea= lly matter to me.

_raw_pgconn() create a Capsule o= bject that should be destroyed.
What do you think about a factory= to create and destroy a PyCapsule that contains the PGconn pointer?
<= div>
Kind Regards
Ch.F.
<= br>
------------------------------= -------------------------------
Good = design can't stop bad implementation


=20
=20
Il gioved=C3=AC 27 settembre 2018, 22:11:35 CEST, Feder= ico Di Gregorio <fog@dndg.it> ha scritto:


On 09/27/2018 09:57 PM, Christian Fer= rari wrote:

> Thanks, for the fix, now the function works, b= ut unfortunately it's a
> dead end in the SWIG realm.= ..Here's the statement:
> http://www.swig.org/Doc2.0/SWIGDocumentation.html#Pyt= hon_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 appro= ach:
> https://bfr= oehle.com/2011/07/18/python-capsules/
>
> If Psycopg was able to retrieve a PyCapsule, XTA should be a= ble to use
> it and the Python interpreter would be a= gateway between two C/C++
> distinct modules (Psycop= g and XTA).
> I'm going to perform some experiments in= the XTA wrapper before coming
> back to this mail th= read.


If you want the capsule, j= ust pull from my report:

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

and use the= feature-expose-pgconn branch.

federic= o

--
Federico Di Gr= egorio                   =     federico.digregorio@dndg.it
DNDG srl               = ;                     &nb= sp;             http://dndg.it
  Everything will be OK at the end. If it's not OK, it's not= the end.
             = ;                     &nb= sp;                     &= nbsp;     -- Unknown


------=_Part_4254784_604447355.1538510870697--