2121#include < memory>
2222#include < string>
2323
24+ #include " common.h"
25+
2426namespace llvm {
2527class Function ;
2628}
@@ -32,41 +34,6 @@ class QualType;
3234
3335namespace ebpf {
3436
35- class TableDesc ;
36-
37- // / FileDesc is a helper class for managing open file descriptors. Copy is
38- // / disallowed (call dup instead), and cleanup happens automatically.
39- class FileDesc {
40- friend TableDesc;
41-
42- private:
43- FileDesc &operator =(const FileDesc &that) {
44- fd = ::dup (that.fd );
45- return *this ;
46- }
47- FileDesc (const FileDesc &that) { *this = that; }
48-
49- public:
50- FileDesc (int fd = -1 ) : fd(fd) {}
51- FileDesc &operator =(FileDesc &&that) {
52- fd = that.fd ;
53- that.fd = -1 ;
54- return *this ;
55- }
56- FileDesc (FileDesc &&that) { *this = std::move (that); }
57- ~FileDesc () {
58- if (fd >= 0 )
59- ::close (fd);
60- }
61- FileDesc dup () const { return FileDesc (*this ); }
62-
63- operator int () { return fd; }
64- operator int () const { return fd; }
65-
66- private:
67- int fd;
68- };
69-
7037typedef int (*sscanf_fn)(const char *, void *);
7138typedef int (*snprintf_fn)(char *, size_t , const void *);
7239
@@ -77,8 +44,22 @@ typedef int (*snprintf_fn)(char *, size_t, const void *);
7744// / so that objects of this class can reside in stl containers.
7845class TableDesc {
7946 private:
80- TableDesc (const TableDesc &) = default ;
81- TableDesc &operator =(const TableDesc &) = default ;
47+ TableDesc (const TableDesc &that)
48+ : name(that.name),
49+ fd (that.fd.dup()),
50+ type(that.type),
51+ key_size(that.key_size),
52+ leaf_size(that.leaf_size),
53+ max_entries(that.max_entries),
54+ flags(that.flags),
55+ key_desc(that.key_desc),
56+ leaf_desc(that.leaf_desc),
57+ key_sscanf(that.key_sscanf),
58+ leaf_sscanf(that.leaf_sscanf),
59+ key_snprintf(that.key_snprintf),
60+ leaf_snprintf(that.leaf_snprintf),
61+ is_shared(that.is_shared),
62+ is_extern(that.is_extern) {}
8263
8364 public:
8465 TableDesc ()
@@ -109,7 +90,10 @@ class TableDesc {
10990 is_shared(false ),
11091 is_extern(false ) {}
11192 TableDesc (TableDesc &&that) = default;
93+
11294 TableDesc &operator =(TableDesc &&that) = default ;
95+ TableDesc &operator =(const TableDesc &that) = delete ;
96+
11397 TableDesc dup () const { return TableDesc (*this ); }
11498
11599 std::string name;
0 commit comments