SWI-Prolog: [FATAL ERROR: at Mon Sep 28 11:18:32 2020 Too many stacked strings]

I’m using: SWI-Prolog version 8.2.1 on 64-bit win10 by import swip in python, here the fact set is about 150000. When I execute the test.py, I get this error:

SWI-Prolog: [FATAL ERROR: at Mon Sep 28 11:18:32 2020 Too many stacked strings]

from the manual, I found that the stack is 256M on 64-bit OS and could be changed by swipl --stack-limit=32g, but I don’t know how to use it on win10, can anyone help me?

This is caused by calling the SWI-Prolog APIs that produce temporary buffered strings. Such code should use (from the C api)

  PL_STRINGS_MARK()
  <do your thing>
  PL_STRINGS_RELEASE()

See SWI-Prolog.h for details. This notably applies to the PL_get_chars() family of functions. I don’t know how to deal with that from Python. I think this was discussed before, so you may find more info in an older answer.

thank you, I try to find it fom older answers.

May also be on a github issue. I’m afraid I do not recall :frowning: If you find it, please link!

this is the answer about this problem on github issue, but I could not solve it:https://github.com/SWI-Prolog/swipl-devel/issues/660

Thanks for linking. I can’t say much how to actually use this in Python. It refers to a PR on PySWI, so I guess you can apply that. Possibly there are other parts of the PySWI API for which this needs to be applied.

Seems you can use with PL_STRINGS_MARK(): in the suspicious loop of your application and if that help see whether you can push this down to the relevant SWI-Prolog API call? I’m not a Python guy.