From 4a302436f0d2fe1ff914e1721ada89ba854b1667 Mon Sep 17 00:00:00 2001 From: Adam Radziszewski <adam.radziszewski@pwr.wroc.pl> Date: Tue, 11 Oct 2011 15:35:55 +0200 Subject: [PATCH] fix unsafe reference in SWIG lexeme.tag() --- swig/lexeme.i | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/swig/lexeme.i b/swig/lexeme.i index 964f434..c78ade4 100644 --- a/swig/lexeme.i +++ b/swig/lexeme.i @@ -5,6 +5,7 @@ %{ #include <unicode/unistr.h> #include <libcorpus2/lexeme.h> +/* #include <boost/make_shared.hpp> */ %} %include "tag.i" @@ -17,6 +18,8 @@ %rename(__op_eq__) Corpus2::Lexeme::operator==(const Lexeme& other) const; %rename(__op_lw__) Corpus2::Lexeme::operator<(const Lexeme& other) const; +/* %template(TagPtr) boost::shared_ptr<Corpus2::Tag>; */ + namespace Corpus2 { class Lexeme { public: @@ -32,7 +35,7 @@ namespace Corpus2 { void set_lemma(const UnicodeString& l); void set_lemma_utf8(const std::string& l); - const Tag& tag() const; +/* const Tag& tag() const; UNSAFE */ void set_tag(const Tag& tag); bool is_null() const; @@ -42,6 +45,13 @@ namespace Corpus2 { bool operator<(const Lexeme& other) const; bool operator==(const Lexeme& other) const; }; + + %extend Lexeme { + /* Override lex.tag() with a version that returns a copy. */ + Corpus2::Tag tag() { + return Corpus2::Tag(self->tag().get_pos(), self->tag().get_values()); + } + } } using namespace std; -- GitLab