blob: 26dd2689bc55269a43158dc66c9b5d6064b945bf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
AUTOUNLINK = [ "COsdItem", "COsdMenu", "CMenuText" ]
################################################################################
#
# Add auto unlink code to SWIG director destructors like:
#
# SwigDirector_<class>::~SwigDirector_<class>() {
# SWIG_RubyUnlinkObjects(this);
# SWIG_RubyRemoveTracking(this);
# }
#
# With this code, when a C++ instance is delete, it will automatically remove
# itself from the list of tracked objects and unlink itself from the Ruby object
# it is used by. This means, that any call to a method of the C++ class from the
# Ruby object will now throw an ObjectPreviouslyDeleted exception.
#
def add_auto_unlink_code
for klass in AUTOUNLINK
@swig_code.gsub!(/(SwigDirector_#{klass}::~SwigDirector_#{klass}\(\) \{\n)(\})/m,
"\\1 SWIG_RubyUnlinkObjects(this);\n SWIG_RubyRemoveTracking(this);\n\\2")
end
end
def improve_overloaded_error
@swig_code.gsub!(/("%s )(for overloaded.*msg,)( method, prototypes)/m,
'\1(%d) \2 argc-1,\3')
end
## main ##
@swig_code = IO.read(ARGV[0])
add_auto_unlink_code if ! AUTOUNLINK.empty?
improve_overloaded_error
File.new(ARGV[1], "w").write(@swig_code)
|