Make rstgen work with gcsafe (#20534)

* Make rstgen work with gcsafe

Co-authored-by: Danil Yarantsev <tiberiumk12@gmail.com>

* add tests and fixes

* if nimHasWarningAsError

Co-authored-by: Danil Yarantsev <tiberiumk12@gmail.com>
This commit is contained in:
ringabout
2022-10-11 00:56:01 +08:00
committed by GitHub
parent 1f2075042b
commit e290b028ab
6 changed files with 18 additions and 9 deletions

View File

@@ -333,7 +333,7 @@ proc newDocumentor*(filename: AbsoluteFile; cache: IdentCache; conf: ConfigRef,
result.jEntriesFinal = newJArray()
initStrTable result.types
result.onTestSnippet =
proc (gen: var RstGenerator; filename, cmd: string; status: int; content: string) =
proc (gen: var RstGenerator; filename, cmd: string; status: int; content: string) {.gcsafe.} =
if conf.docCmd == docCmdSkip: return
inc(gen.id)
var d = (ptr TDocumentor)(addr gen)
@@ -1732,7 +1732,7 @@ proc commandJson*(cache: IdentCache, conf: ConfigRef) =
if ast == nil: return
var d = newDocumentor(conf.projectFull, cache, conf, hasToc = true)
d.onTestSnippet = proc (d: var RstGenerator; filename, cmd: string;
status: int; content: string) =
status: int; content: string) {.gcsafe.} =
localError(conf, newLineInfo(conf, AbsoluteFile d.filename, -1, -1),
warnUser, "the ':test:' attribute is not supported by this backend")
generateJson(d, ast)
@@ -1755,7 +1755,7 @@ proc commandTags*(cache: IdentCache, conf: ConfigRef) =
if ast == nil: return
var d = newDocumentor(conf.projectFull, cache, conf, hasToc = true)
d.onTestSnippet = proc (d: var RstGenerator; filename, cmd: string;
status: int; content: string) =
status: int; content: string) {.gcsafe.} =
localError(conf, newLineInfo(conf, AbsoluteFile d.filename, -1, -1),
warnUser, "the ':test:' attribute is not supported by this backend")
var

View File

@@ -504,7 +504,7 @@ proc formatMsg*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg: string): s
conf.toFileLineCol(info) & " " & title & getMessageStr(msg, arg)
proc liMessage*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg: string,
eh: TErrorHandling, info2: InstantiationInfo, isRaw = false) {.noinline.} =
eh: TErrorHandling, info2: InstantiationInfo, isRaw = false) {.gcsafe, noinline.} =
var
title: string
color: ForegroundColor

View File

@@ -34,3 +34,7 @@ define:useStdoutAsStdmsg
experimental:strictEffects
warningAsError:Effect:on
@end
@if nimHasWarningAsError:
warningAsError:GcUnsafe2:on
@end

View File

@@ -395,7 +395,7 @@ type
suggestVersion*: int
suggestMaxResults*: int
lastLineInfo*: TLineInfo
writelnHook*: proc (output: string) {.closure.} # cannot make this gcsafe yet because of Nimble
writelnHook*: proc (output: string) {.closure, gcsafe.}
structuredErrorHook*: proc (config: ConfigRef; info: TLineInfo; msg: string;
severity: Severity) {.closure, gcsafe.}
cppCustomNamespace*: string

View File

@@ -88,7 +88,7 @@ type
## for hyperlinks. See renderIndexTerm proc for details.
id*: int ## A counter useful for generating IDs.
onTestSnippet*: proc (d: var RstGenerator; filename, cmd: string; status: int;
content: string)
content: string) {.gcsafe.}
escMode*: EscapeMode
curQuotationDepth: int
@@ -283,7 +283,7 @@ proc dispA(target: OutputTarget, dest: var string,
proc `or`(x, y: string): string {.inline.} =
result = if x.len == 0: y else: x
proc renderRstToOut*(d: var RstGenerator, n: PRstNode, result: var string)
proc renderRstToOut*(d: var RstGenerator, n: PRstNode, result: var string) {.gcsafe.}
## Writes into ``result`` the rst ast ``n`` using the ``d`` configuration.
##
## Before using this proc you need to initialise a ``RstGenerator`` with
@@ -1028,7 +1028,7 @@ proc renderCodeLang*(result: var string, lang: SourceLanguage, code: string,
proc renderNimCode*(result: var string, code: string, target: OutputTarget) =
renderCodeLang(result, langNim, code, target)
proc renderCode(d: PDoc, n: PRstNode, result: var string) =
proc renderCode(d: PDoc, n: PRstNode, result: var string) {.gcsafe.} =
## Renders a code (code block or inline code), appending it to `result`.
##
## If the code block uses the ``number-lines`` option, a table will be
@@ -1592,7 +1592,7 @@ $content
proc rstToHtml*(s: string, options: RstParseOptions,
config: StringTableRef,
msgHandler: MsgHandler = rst.defaultMsgHandler): string =
msgHandler: MsgHandler = rst.defaultMsgHandler): string {.gcsafe.} =
## Converts an input rst string into embeddable HTML.
##
## This convenience proc parses any input string using rst markup (it doesn't

View File

@@ -1684,3 +1684,8 @@ suite "local file inclusion":
discard "```nim file = ./readme.md\n```".toHtml(error=error)
check(error[] == "input(1, 23) Error: disabled directive: 'file'")
proc documentToHtml*(doc: string, isMarkdown: bool = false): string {.gcsafe.} =
var options = {roSupportMarkdown}
if isMarkdown:
options.incl roPreferMarkdown
result = rstToHtml(doc, options, defaultConfig())