void pointers

B

bcpkh

Hello All

Hope someone can help me, please note that at first this might look as
if it is posted to the wrong group but if you ignore the specifics I
think it is general pointer referencing issue.

I am building a plug-in library and is passed, according to the
documentation the following;

'A pointer to the OCI environment handle and server context handle are
supplied via elements zero and one of ociEnvInfo respectively.
Implementations are free to ignore this parameter, and should do so
unless it is intended to use the Oracle connection of the calling
process.'

void init(void *ociEnvInfo )

What I have tried is the following;

OCIEnv *envhp; /*OCI environment handle*/
OCISvcCtx *svchp; /*Server context handle*/

void init(void *ociEnvInfo) {

envhp = (OCIEnv*)ociEnvInfo[0];
svchp = (OCISvcCtx*)ociEnvInfo[1];

}

This compiles fine :) but I keep on getting an OCI_INVALID_HANDLE
error which means I am probably not referencing the passed pointers
correctly.

Can someone please point me in the right direction.

Thank you,

B

PS: Running HP-UX on Itanium
 
S

santosh

bcpkh said:
Hello All

Hope someone can help me, please note that at first this might look as
if it is posted to the wrong group but if you ignore the specifics I
think it is general pointer referencing issue.

I am building a plug-in library and is passed, according to the
documentation the following;

'A pointer to the OCI environment handle and server context handle are
supplied via elements zero and one of ociEnvInfo respectively.
Implementations are free to ignore this parameter, and should do so
unless it is intended to use the Oracle connection of the calling
process.'

void init(void *ociEnvInfo )

This is a syntax error.
What I have tried is the following;

OCIEnv *envhp; /*OCI environment handle*/
OCISvcCtx *svchp; /*Server context handle*/

void init(void *ociEnvInfo) {

envhp = (OCIEnv*)ociEnvInfo[0];
svchp = (OCISvcCtx*)ociEnvInfo[1];

Try:

envhp = ((OCIEnv*)ociEnvInfo)[0];
svchp = ((OCISvcCtx*)ociEnvInfo)[1];
 
B

bcpkh

Hello Santosh

I gave your suggestion a try but my compiler returns the following
error;

error #2852: expression must be a pointer to a
complete object type
envhp = ((OCIEnv*)ociEnvInfo)[0];
^

error #2852: expression must be a pointer to a
complete object type
svchp = ((OCISvcCtx*)ociEnvInfo)[1];
^
Any ideas?
This is a syntax error.
What I have tried is the following;
OCIEnv                        *envhp; /*OCI environment handle*/
OCISvcCtx             *svchp; /*Server context handle*/
void init(void *ociEnvInfo) {
  envhp = (OCIEnv*)ociEnvInfo[0];
  svchp = (OCISvcCtx*)ociEnvInfo[1];

Try:

  envhp = ((OCIEnv*)ociEnvInfo)[0];
  svchp = ((OCISvcCtx*)ociEnvInfo)[1];
 
I

Ike Naar

'A pointer to the OCI environment handle and server context handle are
supplied via elements zero and one of ociEnvInfo respectively.
Implementations are free to ignore this parameter, and should do so
unless it is intended to use the Oracle connection of the calling
process.'

void init(void *ociEnvInfo )

What I have tried is the following;

OCIEnv *envhp; /*OCI environment handle*/
OCISvcCtx *svchp; /*Server context handle*/

void init(void *ociEnvInfo) {

envhp = (OCIEnv*)ociEnvInfo[0];
svchp = (OCISvcCtx*)ociEnvInfo[1];

}

This compiles fine :) but I keep on getting an OCI_INVALID_HANDLE
error which means I am probably not referencing the passed pointers
correctly.

From your description I guess that init() expects an array of
pointers to void.
In your situation you want to pass an array of two pointers,
the first being a pointer to OCIEnv, the second being a pointer to OCISvcCtx.
If my assumption is wrong, please give more details, and ignore the rest
of this post.

The following works for me:

/* defining your types here as dummies, just to make it compile */
typedef struct OCIEnv_t OCIEnv;
typedef struct OCISvcCtx_t OCISvcCtx;

void init(void * vinfo)
{
void ** info = vinfo; /* treat passed vinfo as array of pointers to void */
OCIEnv * envhp = info[0];
OCISvcCtx * svchp = info[1];
/* more code */
}

void call_init(void)
{
OCIEnv * the_oci;
OCISvcCtx * the_svc;
void * the_info[2];
/* insert code that properly initializes the_oci and the_svc */
the_info[0] = the_oci;
the_info[1] = the_svc;
init(the_info);
}
 
N

Nick Keighley

Hope someone can help me, please note that at first this might look as
if it is posted to the wrong group but if you ignore the specifics I
think it is general pointer referencing issue.

I am building a plug-in library and is passed, according to the
documentation the following;

'A pointer to the OCI environment handle and server context handle are
supplied via elements zero and one of ociEnvInfo respectively.
Implementations are free to ignore this parameter, and should do so
unless it is intended to use the Oracle connection of the calling
process.'

void init(void *ociEnvInfo )

What I have tried is the following;

OCIEnv                  *envhp; /*OCI environment handle*/
OCISvcCtx               *svchp; /*Server context handle*/

void init(void *ociEnvInfo) {

  envhp = (OCIEnv*)ociEnvInfo[0];
  svchp = (OCISvcCtx*)ociEnvInfo[1];

}

This compiles fine :) but I keep on getting an OCI_INVALID_HANDLE
error which means I am probably not referencing the passed pointers
correctly.

I really would try this on an Oracle group (they don't bite!).
The clc people seem to be guessing wildly. The Oracle people
may *really* know what's going on.
 
B

Barry Schwarz

Hello Santosh

Please don't top-post. Your response belongs immediately following
the text it relates to.
I gave your suggestion a try but my compiler returns the following
error;

error #2852: expression must be a pointer to a
complete object type

This error tells you the compiler does not know the details of what an
OCIEnv is. It is probably a structure of some kind but the
declaration of the structure, including all its members, is not in
scope.
envhp = ((OCIEnv*)ociEnvInfo)[0];
^

error #2852: expression must be a pointer to a
complete object type

Ditto for OCISvcCtx.
svchp = ((OCISvcCtx*)ociEnvInfo)[1];
^
Any ideas?
This is a syntax error.

You don't show how you call this function. Since the argument is
apparently an array containing pointers of different types, the only
way that makes sense is an array of void pointers. In this case, the
correct parameter type would be void**. If this is not what your code
does, then we need to see how you call the function.
  envhp = (OCIEnv*)ociEnvInfo[0];
  svchp = (OCISvcCtx*)ociEnvInfo[1];

Try:

  envhp = ((OCIEnv*)ociEnvInfo)[0];
  svchp = ((OCISvcCtx*)ociEnvInfo)[1];
 
B

Barry Schwarz

Hello All

Hope someone can help me, please note that at first this might look as
if it is posted to the wrong group but if you ignore the specifics I
think it is general pointer referencing issue.

I am building a plug-in library and is passed, according to the
documentation the following;

'A pointer to the OCI environment handle and server context handle are
supplied via elements zero and one of ociEnvInfo respectively.
Implementations are free to ignore this parameter, and should do so
unless it is intended to use the Oracle connection of the calling
process.'

void init(void *ociEnvInfo )

What I have tried is the following;

OCIEnv *envhp; /*OCI environment handle*/
OCISvcCtx *svchp; /*Server context handle*/

void init(void *ociEnvInfo) {

envhp = (OCIEnv*)ociEnvInfo[0];
svchp = (OCISvcCtx*)ociEnvInfo[1];

}

This compiles fine :) but I keep on getting an OCI_INVALID_HANDLE

This cannot compile fine. [] binds tighter than (cast). The
expression is equivalent to (OCIEnv*)(ociEnfInfo[0]). You are
attempting to dereference ociEnvInfo. Since that variable is a
pointer to void, you cannot dereference it. Your compiler is required
to issue a diagnostic. If it does not, up the warning level or
upgrade to a competent implementation.
 
B

bcpkh

You don't show how you call this function.  Since the argument is
apparently an array containing pointers of different types, the only
way that makes sense is an array of void pointers.  In this case, the
correct parameter type would be void**.  If this is not what your code
does, then we need to see how you call the function.


  envhp = (OCIEnv*)ociEnvInfo[0];
  svchp = (OCISvcCtx*)ociEnvInfo[1];
Try:
  envhp = ((OCIEnv*)ociEnvInfo)[0];
  svchp = ((OCISvcCtx*)ociEnvInfo)[1];

Unfortunately I don't call the function, the library that this
function sits in, an implementation of a published interface, gets
called by the process that loads the library, access to this
application is not possible.

Below a cut and paste from the supplied header;

void init(GER_t *pStatus,
void *ociEnvInfo[],
OMinfo_t *pInfo);

init gets called by the 'parent' process once when it starts and I
need to use the passed DB info to interact with the database.
 
B

bcpkh

 santosh said:
bcpkh wrote:
[...]
'A pointer to the OCI environment handle and server context handle are
supplied via elements zero and one of ociEnvInfo respectively.
Implementations are free to ignore this parameter, and should do so
unless it is intended to use the Oracle connection of the calling
process.'
[...]
OCIEnv                *envhp; /*OCI environment handle*/
OCISvcCtx             *svchp; /*Server context handle*/
void init(void *ociEnvInfo) {
  envhp = (OCIEnv*)ociEnvInfo[0];
  svchp = (OCISvcCtx*)ociEnvInfo[1];

  envhp = ((OCIEnv*)ociEnvInfo)[0];
  svchp = ((OCISvcCtx*)ociEnvInfo)[1];

(which also gives an error)

Sounds like init is supposed to take a void**:

void init(void **ociEnvInfo) {

  envhp = ociEnvInfo[0];
  svchp = ociEnvInfo[1];

}

If for some reason it's misdeclared to take a void* in the interface,
then make a local variable that's a cast of the parameter:

void init(void *param) {

  void **ociEnvInfo = param;
  envhp = ociEnvInfo[0];
  svchp = ociEnvInfo[1];

}

Since this is C, there's no need to do any pointer casts as all the
source operands are void*.

Have tried your suggestion but, compile fine but still getting the
OCI_INVALID_HANDLE error. Thanks.
 
S

santosh

bcpkh said:
You don't show how you call this function.  Since the argument is
apparently an array containing pointers of different types, the only
way that makes sense is an array of void pointers.  In this case, the
correct parameter type would be void**.  If this is not what your
code does, then we need to see how you call the function.


envhp = (OCIEnv*)ociEnvInfo[0];
svchp = (OCISvcCtx*)ociEnvInfo[1];

envhp = ((OCIEnv*)ociEnvInfo)[0];
svchp = ((OCISvcCtx*)ociEnvInfo)[1];

Unfortunately I don't call the function, the library that this
function sits in, an implementation of a published interface, gets
called by the process that loads the library, access to this
application is not possible.

Below a cut and paste from the supplied header;

void init(GER_t *pStatus,
void *ociEnvInfo[],
OMinfo_t *pInfo);

init gets called by the 'parent' process once when it starts and I
need to use the passed DB info to interact with the database.

You can do:

evnc_something_or_the_other_ptr = ociEnvInfo[0];

and similarly for the other one.
 
B

Ben Bacarisse

bcpkh said:
Below a cut and paste from the supplied header;

void init(GER_t *pStatus,
void *ociEnvInfo[],
OMinfo_t *pInfo);

init gets called by the 'parent' process once when it starts and I
need to use the passed DB info to interact with the database.

This suggests that your prototype for init is wrong. It should look
the above. You were accessing the first parameter, whereas now it
looks like thge seond is the one you want, and rather than being a
void * it points to an array of void pointers. You function must look
like the above if that is what the called expects.

Note also that your previous code should have had errors saying, in
effect, that the definition of init does not match its prototype. If
you did not, then either you did not include this header (and it is
probably a good thing to do that) or you have the warning level set
rather low on your compiler.
 
C

CBFalconer

bcpkh said:
Hope someone can help me, please note that at first this might
look as if it is posted to the wrong group but if you ignore the
specifics I think it is general pointer referencing issue.

I am building a plug-in library and is passed, according to the
documentation the following;

'A pointer to the OCI environment handle and server context handle
are supplied via elements zero and one of ociEnvInfo respectively.
Implementations are free to ignore this parameter, and should do so
unless it is intended to use the Oracle connection of the calling
process.'

void init(void *ociEnvInfo )

You are definitely on the wrong group. We deal with standard C,
and things programmable in standard C. You have omitted the source
of the "OCI environment", without which there is no answer on this
newsgroup. I believe that has something to do with Oracle, so you
should find a newsgroup that deals with Oracle.
 
B

Ben Bacarisse

You are definitely on the wrong group. We deal with standard C,
and things programmable in standard C.

That does not seem to be the case. For example, you discussed your
allocator here and I doubt that is programmable in standard C.
You have omitted the source
of the "OCI environment", without which there is no answer on this
newsgroup.

Enough has (now) been posted to suggest an answer that is topical --
the OP's function does not match the prototype used to call it.
I believe that has something to do with Oracle, so you
should find a newsgroup that deals with Oracle.

Yes, I agree. The OP will probably get better answers in an Oracle
group, provided there is one populated with good C programmers.
 
C

CBFalconer

Ben said:
.... snip ...


That does not seem to be the case. For example, you discussed your
allocator here and I doubt that is programmable in standard C.

Huh? What is this 'allocator' jazz? One of us is confused.
 
B

Barry Schwarz

On Tue, 5 Aug 2008 03:19:23 -0700 (PDT), bcpkh

snip
Unfortunately I don't call the function, the library that this
function sits in, an implementation of a published interface, gets
called by the process that loads the library, access to this
application is not possible.

Below a cut and paste from the supplied header;

void init(GER_t *pStatus,
void *ociEnvInfo[],
OMinfo_t *pInfo);

init gets called by the 'parent' process once when it starts and I
need to use the passed DB info to interact with the database.

Now that you have shown us the true signature of the function,
everything you coded before invokes undefined behavior and the
previous recommendations you received from this group were based on a
false assumption that led, for the most part, to undefined behavior.

When you code your function to match this signature, statements of the
form
envhp = ociEnvInfo[0];
svchp = ociEnvInfo[1];
will be both syntactically and logically correct as long as the target
variables have the correct type.

What you do with them as well as what you do with the other parameters
needs to be discussed in a topical newsgroup (someone mentioned
Oracle). Once you know what to do with them, questions about how to
do it in standard C can be asked here but odds are the real expertise
will still reside in that topical newsgroup.
 
B

bcpkh

On Tue, 5 Aug 2008 03:19:23 -0700 (PDT), bcpkh


snip
Unfortunately I don't call the function, the library that this
function sits in, an implementation of a published interface, gets
called by the process that loads the library, access to this
application is not possible.
Below a cut and paste from the supplied header;
void init(GER_t *pStatus,
            void *ociEnvInfo[],
            OMinfo_t *pInfo);
init gets called by the 'parent' process once when it starts and I
need to use the passed DB info to interact with the database.

Now that you have shown us the true signature of the function,
everything you coded before invokes undefined behavior and the
previous recommendations you received from this group were based on a
false assumption that led, for the most part, to undefined behavior.

When you code your function to match this signature, statements of the
form
    envhp = ociEnvInfo[0];
    svchp = ociEnvInfo[1];
will be both syntactically and logically correct as long as the target
variables have the correct type.

What you do with them as well as what you do with the other parameters
needs to be discussed in a topical newsgroup (someone mentioned
Oracle).  Once you know what to do with them, questions about how to
do it in standard C can be asked here but odds are the real expertise
will still reside in that topical newsgroup.

Thank you for all the replies and suggestions, like I said might be
the wrong group but I did receive new insight into my problem. Thanks.

B
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top