diff --git a/src/runtime/c/pgf/linearizer.cxx b/src/runtime/c/pgf/linearizer.cxx index 9bc552b8c..59837c865 100644 --- a/src/runtime/c/pgf/linearizer.cxx +++ b/src/runtime/c/pgf/linearizer.cxx @@ -310,10 +310,20 @@ void PgfLinearizer::free_ref(object x) PgfLinearizationOutput::PgfLinearizationOutput() : printer(NULL,0,NULL) { bind = true; + nonexist = false; capit = false; allcapit = false; } +PgfText *PgfLinearizationOutput::get_text() +{ + if (nonexist) { + free(printer.get_text()); + return NULL; + } + return printer.get_text(); +} + void PgfLinearizationOutput::symbol_token(PgfText *tok) { if (!bind) { @@ -375,6 +385,7 @@ void PgfLinearizationOutput::end_phrase(PgfText *cat, int fid, PgfText *ann, Pgf void PgfLinearizationOutput::symbol_ne() { + nonexist = true; } void PgfLinearizationOutput::symbol_bind() diff --git a/src/runtime/c/pgf/linearizer.h b/src/runtime/c/pgf/linearizer.h index aef2d5df8..731add0ca 100644 --- a/src/runtime/c/pgf/linearizer.h +++ b/src/runtime/c/pgf/linearizer.h @@ -4,14 +4,15 @@ class PGF_INTERNAL_DECL PgfLinearizationOutput : public PgfLinearizationOutputIface { PgfPrinter printer; bool bind; + bool nonexist; bool capit; bool allcapit; public: PgfLinearizationOutput(); - PgfText *get_text() { return printer.get_text(); }; - + PgfText *get_text(); + virtual void symbol_token(PgfText *tok); virtual void begin_phrase(PgfText *cat, int fid, PgfText *ann, PgfText *fun); virtual void end_phrase(PgfText *cat, int fid, PgfText *ann, PgfText *fun); diff --git a/src/runtime/c/pgf/printer.cxx b/src/runtime/c/pgf/printer.cxx index d65cc6b83..fbec41f32 100644 --- a/src/runtime/c/pgf/printer.cxx +++ b/src/runtime/c/pgf/printer.cxx @@ -71,11 +71,13 @@ again: { PgfText *PgfPrinter::get_text() { - if (res == NULL) { - res = (PgfText*) malloc(sizeof(PgfText)); - res->size = 0; + PgfText *tmp = res; + if (tmp == NULL) { + tmp = (PgfText*) malloc(sizeof(PgfText)); + tmp->size = 0; } - return res; + res = NULL; + return tmp; } void PgfPrinter::flush_lambdas() diff --git a/src/runtime/haskell/PGF2.hsc b/src/runtime/haskell/PGF2.hsc index 2ca6f3053..382ab0ff1 100644 --- a/src/runtime/haskell/PGF2.hsc +++ b/src/runtime/haskell/PGF2.hsc @@ -584,7 +584,9 @@ linearize c e = bracket (newStablePtr e) freeStablePtr $ \c_e -> withForeignPtr marshaller $ \m -> bracket (withPgfExn "linearize" (pgf_linearize (c_db c) c_revision c_e m)) free $ \c_text -> - peekText c_text + if c_text == nullPtr + then return "" + else peekText c_text -- | Generates all possible linearizations of an expression linearizeAll :: Concr -> Expr -> [String]