3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-05 17:14:07 +00:00

return non-escaped string value for Python #3080

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2020-02-26 09:16:23 -08:00
parent dddd740846
commit f0689546f3
5 changed files with 16 additions and 8 deletions

View file

@ -70,7 +70,7 @@ Type2Str = { VOID : 'void', VOID_PTR : 'void*', INT : 'int', UINT : 'unsigned',
Type2PyStr = { VOID_PTR : 'ctypes.c_void_p', INT : 'ctypes.c_int', UINT : 'ctypes.c_uint', INT64 : 'ctypes.c_longlong',
UINT64 : 'ctypes.c_ulonglong', DOUBLE : 'ctypes.c_double', FLOAT : 'ctypes.c_float',
STRING : 'ctypes.c_char_p', STRING_PTR : 'ctypes.POINTER(ctypes.c_char_p)', BOOL : 'ctypes.c_bool', SYMBOL : 'Symbol',
PRINT_MODE : 'ctypes.c_uint', ERROR_CODE : 'ctypes.c_uint', CHAR : 'ctypes.c_char', CHAR_PTR: 'ctypes.c_char_p'
PRINT_MODE : 'ctypes.c_uint', ERROR_CODE : 'ctypes.c_uint', CHAR : 'ctypes.c_char', CHAR_PTR: 'ctypes.POINTER(ctypes.c_char)'
}
# Mapping to .NET types

View file

@ -187,6 +187,8 @@ namespace api {
char * mk_external_string(char const * str, unsigned n);
char * mk_external_string(char const * str);
char * mk_external_string(std::string && str);
sbuffer<char> m_char_buffer;
// Create a numeral of the given sort
expr * mk_numeral_core(rational const & n, sort * s);

View file

@ -150,7 +150,7 @@ extern "C" {
Z3_CATCH_RETURN("");
}
Z3_string Z3_API Z3_get_lstring(Z3_context c, Z3_ast s, unsigned* length) {
Z3_char_ptr Z3_API Z3_get_lstring(Z3_context c, Z3_ast s, unsigned* length) {
Z3_TRY;
LOG_Z3_get_lstring(c, s, length);
RESET_ERROR_CODE();
@ -163,9 +163,12 @@ extern "C" {
SET_ERROR_CODE(Z3_INVALID_ARG, "expression is not a string literal");
return "";
}
std::string s = str.as_string();
*length = (unsigned)(s.size());
return mk_c(c)->mk_external_string(s.c_str(), *length);
mk_c(c)->m_char_buffer.reset();
for (unsigned i = 0; i < str.length(); ++i) {
mk_c(c)->m_char_buffer.push_back((char)str[i]);
}
*length = str.length();
return mk_c(c)->m_char_buffer.c_ptr();
Z3_CATCH_RETURN("");
}

View file

@ -10032,10 +10032,13 @@ class SeqRef(ExprRef):
def is_string_value(self):
return Z3_is_string(self.ctx_ref(), self.as_ast())
def as_string(self):
"""Return a string representation of sequence expression."""
if self.is_string_value():
return Z3_get_string(self.ctx_ref(), self.as_ast())
string_length = ctypes.c_uint()
chars = Z3_get_lstring(self.ctx_ref(), self.as_ast(), byref(string_length))
return string_at(chars, size=string_length.value).decode('ascii')
return Z3_ast_to_string(self.ctx_ref(), self.as_ast())
def __le__(self, other):

View file

@ -3474,9 +3474,9 @@ extern "C" {
\pre Z3_is_string(c, s)
def_API('Z3_get_lstring' ,STRING ,(_in(CONTEXT), _in(AST), _out(UINT)))
def_API('Z3_get_lstring' ,CHAR_PTR ,(_in(CONTEXT), _in(AST), _out(UINT)))
*/
Z3_string Z3_API Z3_get_lstring(Z3_context c, Z3_ast s, unsigned* length);
Z3_char_ptr Z3_API Z3_get_lstring(Z3_context c, Z3_ast s, unsigned* length);
/**
\brief Create an empty sequence of the sequence sort \c seq.