Skip to content

Instantly share code, notes, and snippets.

Yi Wang wangkuiyi

  • Ant Financial USA
  • San Francisco Bay Area, CA
Block or report user

Report or block wangkuiyi

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@helinwang
helinwang / gostring.md
Last active Dec 6, 2018
Call go (or c) code from python with string as argument and string as return value
View gostring.md

go code (foo.go) compiled into a shared library and a c header (foo.h) is generated.

For calling go from c, please see here

Arguments

The code below shows two ways of passing string parameter to go function:

  1. Using GoString structure as argument, without making a copy in go code: no conversion to go string needed.
  2. Using c_char_p as argument, making a copy in go code when converting to go string.

When using the first method without the copy, I don't know how python will do the memory management with the pointer passed into go. So the second method is preferred.

You can’t perform that action at this time.