Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Codegen produces code that the old GCs don't like #18616

Closed
Araq opened this issue Jul 30, 2021 · 0 comments · Fixed by #24561
Closed

Codegen produces code that the old GCs don't like #18616

Araq opened this issue Jul 30, 2021 · 0 comments · Fixed by #24561

Comments

@Araq
Copy link
Member

Araq commented Jul 30, 2021

This code crashes at runtime and with -d:useSysAssert -d:useGcAssert it's clear why: The RTTI based copy operation is not entirely correct for const data.

import std/unittest, asyncdispatch

type
  ClientResponse = object
    status*: int
    data*: string

template asyncTest*(name: string, body: untyped): untyped =
  test name:
    waitFor((
      proc() {.async, gcsafe.} =
        body
    )())

suite "Test suite":
  asyncTest "test1":
    const PostVectors = [
      (
        ("/test/post", "somebody0908", "text/html",
        "app/type1;q=0.9,app/type2;q=0.8"),
        ClientResponse(status: 200, data: "type1[text/html,somebody0908]")
      ),
      (
        ("/test/post", "somebody0908", "text/html",
        "app/type2;q=0.8,app/type1;q=0.9"),
        ClientResponse(status: 200, data: "type1[text/html,somebody0908]")
      ),
      (
        ("/test/post", "somebody09", "text/html",
         "app/type2,app/type1;q=0.9"),
        ClientResponse(status: 200, data: "type2[text/html,somebody09]")
      ),
      (
        ("/test/post", "somebody09", "text/html", "app/type1;q=0.9,app/type2"),
        ClientResponse(status: 200, data: "type2[text/html,somebody09]")
      ),
      (
        ("/test/post", "somebody", "text/html", "*/*"),
        ClientResponse(status: 200, data: "type1[text/html,somebody]")
      ),
      (
        ("/test/post", "somebody", "text/html", ""),
        ClientResponse(status: 200, data: "type1[text/html,somebody]")
      ),
      (
        ("/test/post", "somebody", "text/html", "app/type2"),
        ClientResponse(status: 200, data: "type2[text/html,somebody]")
      ),
      (
        ("/test/post", "somebody", "text/html", "app/type3"),
        ClientResponse(status: 406, data: "")
      )
    ]

    for item in PostVectors:
      echo item

  asyncTest "test2":
    const PostVectors = [
      (
        "/test/post", "somebody0908", "text/html",
        "app/type1;q=0.9,app/type2;q=0.8",
        ClientResponse(status: 200, data: "type1[text/html,somebody0908]")
      ),
      (
        "/test/post", "somebody0908", "text/html",
        "app/type2;q=0.8,app/type1;q=0.9",
        ClientResponse(status: 200, data: "type1[text/html,somebody0908]")
      ),
      (
        "/test/post", "somebody09", "text/html",
        "app/type2,app/type1;q=0.9",
        ClientResponse(status: 200, data: "type2[text/html,somebody09]")
      ),
      (
        "/test/post", "somebody09", "text/html", "app/type1;q=0.9,app/type2",
        ClientResponse(status: 200, data: "type2[text/html,somebody09]")
      ),
      (
        "/test/post", "somebody", "text/html", "*/*",
        ClientResponse(status: 200, data: "type1[text/html,somebody]")
      ),
      (
        "/test/post", "somebody", "text/html", "",
        ClientResponse(status: 200, data: "type1[text/html,somebody]")
      ),
      (
        "/test/post", "somebody", "text/html", "app/type2",
        ClientResponse(status: 200, data: "type2[text/html,somebody]")
      ),
      (
        "/test/post", "somebody", "text/html", "app/type3",
        ClientResponse(status: 406, data: "")
      )
    ]

    for item in PostVectors:
      echo item
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants