Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Q: how to make Python <==> d call in both ways? any example with PyD and autowrap? #314

Open
mw66 opened this issue Jun 22, 2022 · 3 comments

Comments

@mw66
Copy link

mw66 commented Jun 22, 2022

https://forum.dlang.org/post/[email protected]

Hi,

I know with PyD, D can call Python, and with autowrap, Python can call a D .dll, I'm just wondering if someone can show an example that Python <==> d can call both ways? esp. show passing D objects to Python and then call its member function there, and vice versa.

I tried a simple example:

// in D
import pyd.pyd, pyd.embedded;

void foo(PydObject bar) {
  writeln(bar.baz());   // call PydObject's method on the D side
}


// in Python
import libDdll
libDdll.foo(pyBarObj)

The result seem working; but the dub build issues error message, even though the .so was able to be built.

libDdll ~main: building configuration "python39"...

ERROR! Autowrap could not wrap aggregate `pyd.pydobject.PydObject` for Python


ERROR! Autowrap could not wrap aggregate `deimos.python.object.PyTypeObject` for Python


ERROR! Autowrap could not wrap aggregate `deimos.python.methodobject.PyMethodDef` for Python


ERROR! Autowrap could not wrap aggregate `deimos.python.structmember.PyMemberDef` for Python


ERROR! Autowrap could not wrap aggregate `deimos.python.descrobject.PyGetSetDef` for Python

Linking...
To force a rebuild of up-to-date targets, run again with --force.

I'm wondering if these ERROR messages are actually error, since the .so can be built, and the running result seems fine.

If they are not actually real errors, can we either change them to warnings, or even completely remove them? This only cause some confusion to the user.

And we can document this usage: i.e passing Python object to D, and call its Python method on the D side.

Thanks.

@mw66
Copy link
Author

mw66 commented Jun 23, 2022

A related question: is it possible to make a round trip, e.g.

// in D:
Dtype genDObj() {...}

void foo(Dtype dObj) {
  // round trip, get back the D object here!
}

# in Python
   dObj = libDll.genDobj()   // wrap D object
   ...
   libDll.foo(dObj);   // unwrap D object?

Thanks.

@mw66
Copy link
Author

mw66 commented Jun 26, 2022

libDdll ~main: building configuration "python39"...

ERROR! Autowrap could not wrap aggregate `pyd.pydobject.PydObject` for Python


ERROR! Autowrap could not wrap aggregate `deimos.python.object.PyTypeObject` for Python


ERROR! Autowrap could not wrap aggregate `deimos.python.methodobject.PyMethodDef` for Python


ERROR! Autowrap could not wrap aggregate `deimos.python.structmember.PyMemberDef` for Python


ERROR! Autowrap could not wrap aggregate `deimos.python.descrobject.PyGetSetDef` for Python

Linking...
To force a rebuild of up-to-date targets, run again with --force.

I'm wondering if these ERROR messages are actually error, since the .so can be built, and the running result seems fine.

If they are not actually real errors, can we either change them to warnings, or even completely remove them? This only cause some confusion to the user.

Encounter a related issue:

#120 (comment)

Looks like this kind error only affect the single reported aggregate cannot be wrapped and used on the Python side, other types still can work. So I'd suggest change this to a warning message instead of error.

@atilaneves
Copy link
Collaborator

pyd lets you do this with PydObject if I'm not mistaken.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants