Skip to content

Commit

Permalink
Export filedescriptor.
Browse files Browse the repository at this point in the history
  • Loading branch information
whilo committed Jun 19, 2017
1 parent 900ac8e commit 68ed56a
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/org/python/core/PyFile.java
Expand Up @@ -612,6 +612,12 @@ final PyObject file_fileno() {
return PyJavaType.wrapJavaObject(file.fileno());
}

// HACK to expose file descriptor
//@ExposedMethod(doc = BuiltinDocs.file_fileno_doc)
final public int fd() {
return ((PyInteger)((FileIO)file.fileno()).__int__()).getValue();
}

@ExposedMethod(names = {"__str__", "__repr__"}, doc = BuiltinDocs.file___str___doc)
final String file_toString() {
String state = file.closed() ? "closed" : "open";
Expand Down

3 comments on commit 68ed56a

@Stewori
Copy link

@Stewori Stewori commented on 68ed56a Jun 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should at least check that file.fileno() is a FileIO to eliminate this as an issue source. For debugging something hackish like if (!(file.fileno() instanceof FileIO)) System.out.println("Warning: JyNI will crash now because fileno is no FileIO"); would be sufficient.

@whilo
Copy link
Owner Author

@whilo whilo commented on 68ed56a Jun 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, thx.

@Stewori
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It just occurred to that JVM would throw a ClassCastException, so securing it via isinstance is not so crucial. Did too much Python and C recently...
Anyway, an explicit check doesn't hurt either.

Please sign in to comment.