mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-25 18:06:05 +00:00

Summary: This patch adds SWIG typemaps that can convert arbitrary python file objects into lldb_private::File. A SBFile may be initialized from a python file using the constructor. There are also alternate, tagged constructors that allow python files to be borrowed, and for the caller to control whether or not the python I/O methods will be called even when a file descriptor is available.I Reviewers: JDevlieghere, jasonmolenda, labath Reviewed By: labath Subscribers: zturner, amccarth, lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D68188 llvm-svn: 374225
83 lines
2.4 KiB
OpenEdge ABL
83 lines
2.4 KiB
OpenEdge ABL
//===-- SWIG Interface for SBFile -----------------------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
namespace lldb {
|
|
|
|
%feature("docstring",
|
|
"Represents a file."
|
|
) SBFile;
|
|
|
|
class SBFile
|
|
{
|
|
public:
|
|
|
|
SBFile();
|
|
|
|
%feature("docstring", "
|
|
Initialize a SBFile from a file descriptor. mode is
|
|
'r', 'r+', or 'w', like fdopen.");
|
|
SBFile(int fd, const char *mode, bool transfer_ownership);
|
|
|
|
%feature("docstring", "initialize a SBFile from a python file object");
|
|
SBFile(FileSP file);
|
|
|
|
%extend {
|
|
static lldb::SBFile MakeBorrowed(lldb::FileSP BORROWED) {
|
|
return lldb::SBFile(BORROWED);
|
|
}
|
|
static lldb::SBFile MakeForcingIOMethods(lldb::FileSP FORCE_IO_METHODS) {
|
|
return lldb::SBFile(FORCE_IO_METHODS);
|
|
}
|
|
static lldb::SBFile MakeBorrowedForcingIOMethods(lldb::FileSP BORROWED_FORCE_IO_METHODS) {
|
|
return lldb::SBFile(BORROWED_FORCE_IO_METHODS);
|
|
}
|
|
}
|
|
|
|
%pythoncode {
|
|
@classmethod
|
|
def Create(cls, file, borrow=False, force_io_methods=False):
|
|
"""
|
|
Create a SBFile from a python file object, with options.
|
|
|
|
If borrow is set then the underlying file will
|
|
not be closed when the SBFile is closed or destroyed.
|
|
|
|
If force_scripting_io is set then the python read/write
|
|
methods will be called even if a file descriptor is available.
|
|
"""
|
|
if borrow:
|
|
if force_io_methods:
|
|
return cls.MakeBorrowedForcingIOMethods(file)
|
|
else:
|
|
return cls.MakeBorrowed(file)
|
|
else:
|
|
if force_io_methods:
|
|
return cls.MakeForcingIOMethods(file)
|
|
else:
|
|
return cls(file)
|
|
}
|
|
|
|
~SBFile ();
|
|
|
|
%feature("autodoc", "Read(buffer) -> SBError, bytes_read") Read;
|
|
SBError Read(uint8_t *buf, size_t num_bytes, size_t *OUTPUT);
|
|
|
|
%feature("autodoc", "Write(buffer) -> SBError, written_read") Write;
|
|
SBError Write(const uint8_t *buf, size_t num_bytes, size_t *OUTPUT);
|
|
|
|
void Flush();
|
|
|
|
bool IsValid() const;
|
|
|
|
operator bool() const;
|
|
|
|
SBError Close();
|
|
};
|
|
|
|
} // namespace lldb
|