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

Incorrect definition of memcpy on OS X 10.9 #6575

Closed
gopherbot opened this issue Oct 13, 2013 · 3 comments
Closed

Incorrect definition of memcpy on OS X 10.9 #6575

gopherbot opened this issue Oct 13, 2013 · 3 comments
Milestone

Comments

@gopherbot
Copy link

by mazdak@chango.com:

CGO file referring to string.h and using the memcpy function gives the following error:

cannot use (type C.size_t) as type C.ulong in function argument

Sample Code:

package main        

/*
#include <stdlib.h>
#include <string.h>
*/
import "C"

import (
    "unsafe"
    "fmt"
)

func main() {
    var ksiz C.size_t
    ksiz = C.size_t(6)
    k := make([]byte, ksiz)
    kp := C.CString("string")
    C.memcpy(unsafe.Pointer(&k[0]), unsafe.Pointer(kp), C.ulong(ksiz))
    fmt.Println(k)
}

What is the expected output?

Compilation without error. Output:
[115 116 114 105 110 103]

What do you see instead?

# command-line-arguments
./memcpytest.go:17: cannot use ksiz (type C.size_t) as type C.ulong in function argument

Which compiler are you using (5g, 6g, 8g, gccgo)?

CC=clang go build

Which operating system are you using?

ProductName:    Mac OS X
ProductVersion: 10.9
BuildVersion:   13A598
Xcode 5.0.1
Build version 5A2034a

Which version are you using?  (run 'go version')

go version devel +47b2b07a837f Fri Oct 11 16:39:40 2013 -0700 darwin/amd64
@gopherbot
Copy link
Author

Comment 1 by mazdak@chango.com:

Error in my original post.
The original problem line was 
C.memcpy(unsafe.Pointer(&k[0]), unsafe.Pointer(kp), ksiz)
The fix is:
C.memcpy(unsafe.Pointer(&k[0]), unsafe.Pointer(kp), C.ulong(ksiz))

@ianlancetaylor
Copy link
Contributor

Comment 2:

This seems to be a general problem with the definition of size_t on OS X 10.9.  We fixed
it for malloc, but the problem has been reported for calloc and realloc (issue #6506) and
now memcpy.  We can't fix each one individually.

Labels changed: added go1.2maybe.

@ianlancetaylor
Copy link
Contributor

Comment 3:

Status changed to Duplicate.

Merged into issue #6506.

@rsc rsc added this to the Go1.2 milestone Apr 14, 2015
@rsc rsc removed the go1.2maybe label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants