diff options
| author | Andreas Källberg <anka.213@gmail.com> | 2020-09-05 21:11:12 +0200 |
|---|---|---|
| committer | Andreas Källberg <anka.213@gmail.com> | 2020-09-05 21:11:12 +0200 |
| commit | 56f94da772566a1960d889c14c420ee832038365 (patch) | |
| tree | 86737b1039dfa03b3fb289cdb309b80a5f35f759 /src/runtime/python | |
| parent | 57ce76dbc121ee554675b9ee6136441ec0bb5710 (diff) | |
| parent | bca0691cb028fe33ae1b77e71752d4e937490ff1 (diff) | |
Merge remote-tracking branch 'origin/master' into fix-newer-cabal
Diffstat (limited to 'src/runtime/python')
| -rw-r--r-- | src/runtime/python/pypgf.c | 34 |
1 files changed, 2 insertions, 32 deletions
diff --git a/src/runtime/python/pypgf.c b/src/runtime/python/pypgf.c index 07d534db5..e009d9e72 100644 --- a/src/runtime/python/pypgf.c +++ b/src/runtime/python/pypgf.c @@ -1412,7 +1412,7 @@ pypgf_literal_callback_match(PgfLiteralCallback* self, PgfConcr* concr, ExprObject* pyexpr; #if PY_MAJOR_VERSION >= 3 - size_t chars; + int chars; if (!PyArg_ParseTuple(result, "Ofi", &pyexpr, &ep->prob, &chars)) return NULL; *poffset = unicode_to_utf8_offset(sentence, chars); @@ -1421,37 +1421,7 @@ pypgf_literal_callback_match(PgfLiteralCallback* self, PgfConcr* concr, return NULL; #endif - ep->expr = pyexpr->expr; - - { - // This is an uggly hack. We first show the expression ep->expr - // and then we read it back but in out_pool. The whole purpose - // of this is to copy the expression from the temporary pool - // that was created in the Java binding to the parser pool. - // There should be a real copying function or even better - // there must be a way to avoid copying at all. - - GuPool* tmp_pool = gu_local_pool(); - - GuExn* err = gu_exn(tmp_pool); - GuStringBuf* sbuf = gu_new_string_buf(tmp_pool); - GuOut* out = gu_string_buf_out(sbuf); - - pgf_print_expr(ep->expr, NULL, 0, out, err); - - GuIn* in = gu_data_in((uint8_t*) gu_string_buf_data(sbuf), - gu_string_buf_length(sbuf), - tmp_pool); - - ep->expr = pgf_read_expr(in, out_pool, tmp_pool, err); - if (!gu_ok(err) || gu_variant_is_null(ep->expr)) { - PyErr_SetString(PGFError, "The expression cannot be parsed"); - gu_pool_free(tmp_pool); - return NULL; - } - - gu_pool_free(tmp_pool); - } + ep->expr = pgf_clone_expr(pyexpr->expr, out_pool); Py_DECREF(result); |
