FAQ
I'm trying to get a package put together that wraps the Oracle OCI
interface without using cgo. I'm getting a runtime panic during the
OCILogon process (I think), and without OCILogon, the test completes
successfully. Does anyone here have any experience with the Syscall
interface, and more importantly, can anyone tell me what I'm doing wrong?

About the best documentation I've come across is the existing Syscall
Windows API implementation<http://golang.org/src/pkg/syscall/zsyscall_windows_amd64.go>,
but Oracle is using some creative pointers in their C API.

My code is here: https://github.com/ericzhill/goci.git
Oracle OCILogon documentatation is here:
http://docs.oracle.com/cd/B10501_01/appdev.920/a96584/oci15re9.htm#556479

I have a feeling that once I get through the uphill learning curve for the
Syscall internals, this should get fleshed out pretty quickly.

Thanks in advance.

--

Search Discussions

  • Archos at Sep 27, 2012 at 2:16 pm
    You could try generate that function using go.mksyscall
    (https://github.com/kless/cutil/tree/master/go.mksyscall) which is based in
    the Perl version used to bootstrap the Go's syscalls to Windows
    (http://golang.org/src/pkg/syscall/mksyscall_windows.pl)


    El jueves, 27 de septiembre de 2012 15:04:57 UTC+1, Eric Hill escribió:
    I'm trying to get a package put together that wraps the Oracle OCI
    interface without using cgo. I'm getting a runtime panic during the
    OCILogon process (I think), and without OCILogon, the test completes
    successfully. Does anyone here have any experience with the Syscall
    interface, and more importantly, can anyone tell me what I'm doing wrong?

    About the best documentation I've come across is the existing Syscall
    Windows API implementation<http://golang.org/src/pkg/syscall/zsyscall_windows_amd64.go>,
    but Oracle is using some creative pointers in their C API.

    My code is here: https://github.com/ericzhill/goci.git
    Oracle OCILogon documentatation is here:
    http://docs.oracle.com/cd/B10501_01/appdev.920/a96584/oci15re9.htm#556479

    I have a feeling that once I get through the uphill learning curve for the
    Syscall internals, this should get fleshed out pretty quickly.

    Thanks in advance.
    --
  • Bobby Powers at Sep 27, 2012 at 6:53 pm
    you could take a look at some soon-to-be-documented code I wrote that
    does a linux-specific syscall with pointers into a go datastructure:
    https://github.com/bpowers/caps/blob/master/caps_linux.go#L123

    I based it off some code I found in the runtime, but I don't recall
    the specific reference.

    yours,
    Bobby
    On Thu, Sep 27, 2012 at 7:04 AM, Eric Hill wrote:
    I'm trying to get a package put together that wraps the Oracle OCI interface
    without using cgo. I'm getting a runtime panic during the OCILogon process
    (I think), and without OCILogon, the test completes successfully. Does
    anyone here have any experience with the Syscall interface, and more
    importantly, can anyone tell me what I'm doing wrong?

    About the best documentation I've come across is the existing Syscall
    Windows API implementation, but Oracle is using some creative pointers in
    their C API.

    My code is here: https://github.com/ericzhill/goci.git
    Oracle OCILogon documentatation is here:
    http://docs.oracle.com/cd/B10501_01/appdev.920/a96584/oci15re9.htm#556479

    I have a feeling that once I get through the uphill learning curve for the
    Syscall internals, this should get fleshed out pretty quickly.

    Thanks in advance.

    --
    --
  • Eric Hill at Sep 27, 2012 at 9:19 pm
    Thanks Archis and Bobby Powers - I'm going to muddle my way through the
    perl script to attempt to generate the correct calling conventions. We'll
    see how far I get.
    On Thursday, September 27, 2012 9:04:57 AM UTC-5, Eric Hill wrote:

    I'm trying to get a package put together that wraps the Oracle OCI
    interface without using cgo. I'm getting a runtime panic during the
    OCILogon process (I think), and without OCILogon, the test completes
    successfully. Does anyone here have any experience with the Syscall
    interface, and more importantly, can anyone tell me what I'm doing wrong?

    About the best documentation I've come across is the existing Syscall
    Windows API implementation<http://golang.org/src/pkg/syscall/zsyscall_windows_amd64.go>,
    but Oracle is using some creative pointers in their C API.

    My code is here: https://github.com/ericzhill/goci.git
    Oracle OCILogon documentatation is here:
    http://docs.oracle.com/cd/B10501_01/appdev.920/a96584/oci15re9.htm#556479

    I have a feeling that once I get through the uphill learning curve for the
    Syscall internals, this should get fleshed out pretty quickly.

    Thanks in advance.
    --
  • Archos at Sep 27, 2012 at 11:26 pm
    You get the same with the Go version, excep that it generates specific code
    for architectures in extra files, and it can translate the C++ types (if
    it is used flag -conv), althought not all types, only just types that I've
    needed

    https://github.com/kless/cutil/blob/master/go.mksyscall/mksyscall.go#L993

    El jueves, 27 de septiembre de 2012 22:19:24 UTC+1, Eric Hill escribió:
    Thanks Archis and Bobby Powers - I'm going to muddle my way through the
    perl script to attempt to generate the correct calling conventions. We'll
    see how far I get.
    On Thursday, September 27, 2012 9:04:57 AM UTC-5, Eric Hill wrote:

    I'm trying to get a package put together that wraps the Oracle OCI
    interface without using cgo. I'm getting a runtime panic during the
    OCILogon process (I think), and without OCILogon, the test completes
    successfully. Does anyone here have any experience with the Syscall
    interface, and more importantly, can anyone tell me what I'm doing wrong?

    About the best documentation I've come across is the existing Syscall
    Windows API implementation<http://golang.org/src/pkg/syscall/zsyscall_windows_amd64.go>,
    but Oracle is using some creative pointers in their C API.

    My code is here: https://github.com/ericzhill/goci.git
    Oracle OCILogon documentatation is here:
    http://docs.oracle.com/cd/B10501_01/appdev.920/a96584/oci15re9.htm#556479

    I have a feeling that once I get through the uphill learning curve for
    the Syscall internals, this should get fleshed out pretty quickly.

    Thanks in advance.
    --
  • Brainman at Sep 28, 2012 at 1:48 am

    On Friday, 28 September 2012 00:04:57 UTC+10, Eric Hill wrote:

    ... I'm getting a runtime panic during the OCILogon process (I think), ...
    Stack trace should tell you where your problem is. Try and understand what
    it says.
    ... can anyone tell me what I'm doing wrong?
    Be warned. I have never seen/used OCI before. So everything I say could be
    fiction of my imagination.

    Looking at your OCILogon code:

    >>>
    r0, _, e1 := procOCILogon.Call( // sword OCILogon (
    ...
    uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(username))),
    uintptr(len(username)),
    ...

    <<<

    According to the doco
    (http://docs.oracle.com/cd/B10500_01/appdev.920/a96584/oci15re9.htm):

    >>>
    uname_len (IN)

    The length of username, in number of bytes, regardless of the encoding.
    <<<

    I think you want to pass length of syscall.StringToUTF16(username), not
    len(username), here.

    Similar for password and database.

    Also, more importantly, I think your error handling is wrong. As I said
    earlier, I am not familiar with OCI, but searching the doco, I find this:
    http://docs.oracle.com/cd/B10500_01/appdev.920/a96584/oci02bas.htm#425597.
    You should not assume that 3rd return parameter of syscall.Proc.Call will
    have your error there. This parameter will contain current value of
    GetLastError windows api. Does OCI dll sets its value before return from
    api call? I do not think so.

    I also think your api translation is looking for trouble. Nowhere in your
    source code I can see published OCI api. You are kind of fitting everything
    in as you call syscall.Proc.Call:

    >>>
    type OCIHandle struct {
    h uintptr // Handle
    t uint // Handle type
    }

    func OCIEnvCreate(mode uint32) (henv *OCIHandle, err error) {
    var e *OCIHandle = new(OCIHandle) // Environment hand
    e.t = OCI_HTYPE_ENV

    r0, _, e1 := procOCIEnvCreate.Call( // sword OCIEnvCr
    uintptr(unsafe.Pointer(&e.h)), // OCIEnv
    uintptr(mode), // ub4
    0, // CONST dvoid
    0, // CONST dvoid
    0, // CONST dvoid
    0, // CONST void
    0, // size_t
    0) // dvoid

    ...
    }
    <<<

    It is very different from what is in the
    doco(http://docs.oracle.com/cd/B10501_01/appdev.920/a96584/oci15re4.htm):

    >>>
    sword OCIEnvCreate ( OCIEnv **envhpp,
    ub4 mode,
    ...
    ...);
    <<<

    I would translate this into:

    type OCIEnv uintptr // I can't find the definition, but I do not think it
    is important what it is.
    // Perhaps, you can define it even as "type OCIEnv
    byte", because you deal
    // with pointers here only.

    type ub4 uint32 // You need to make sure it is uint32!!!

    type sword int16 // I AM JUST GUESSING HERE. YOU NEED TO CHECK THAT.

    func OCIEnvCreate(envhpp **OCIEnv, mode ub4, ...) sword {
    ...
    }

    Do not have to think about it. It translates one to one. It is very
    important (as you have discovered) not to make even small mistakes.

    Once you have this function, the Go type system will help you not to make
    mistakes as you call it.

    You can automate generation of OCIEnvCreate function body, as it is done by
    syscall package. Just look at something similar that I have done here:

    I write http://code.google.com/p/odbc/source/browse/api/api.go by hand
    (look at comments that start with //sys). Then I use zapi_windows.go rule
    in http://code.google.com/p/odbc/source/browse/api/Makefile to generate
    http://code.google.com/p/odbc/source/browse/api/zapi_windows.go. You could
    do something similar. It is some work at the start, but makes things
    simpler, quicker and safer as you progress.

    Hope it helps.

    Alex

    --
  • Eric Hill at Sep 28, 2012 at 2:34 am
    Fan-freaking-tastic! That's exactly the kind of information I was looking
    for! I'll work through this tomorrow and see where I wind up. MANY thanks
    for the shove in the right direction.

    Thanks Alex!

    --

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedSep 27, '12 at 2:10p
activeSep 28, '12 at 2:34a
posts7
users4
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase