making my extensions work together

M

Mathew

This isn't exactly a Python question but maybe someone here has run into
this.

I have 2 extensions and they both access a function in a (static) library.
The function maintains state information using a static variable.

This doesn't work. When one of my extensions changes the variable value, the
other extension does not see the change.

Would it work if I made my library dynamic?

This is on Windows XP compiling with MSVC 2008.

-Mathew
 
J

John Gordon

In said:
This isn't exactly a Python question but maybe someone here has run into
this.
I have 2 extensions and they both access a function in a (static) library.
The function maintains state information using a static variable.

I'm not sure what you mean by "extension", but it might not be relevant.

Are these extensions, whatever they may be, part of the same program?
Or are they separate?
 
S

Stefan Behnel

Mathew, 04.08.2011 03:19:
This isn't exactly a Python question but maybe someone here has run into
this.

I have 2 extensions

With "extensions", I assume you mean extension modules for the CPython
runtime that are written in C? It would help if you were more specific in
your problem description.

and they both access a function in a (static) library.

It would help if you mentioned the names of the modules (or packages) and
of the external library.

The function maintains state information using a static variable.

That's bad design, but it happens.

This doesn't work. When one of my extensions changes the variable value, the
other extension does not see the change.

Are the two modules linked in any way or are they just arbitrary modules
that happen to be installed at the same time, trying to use the same
external C library?

If the former, consider letting them communicate with each other by making
one depend on the other. If you control the source code, you may also
consider wrapping the library only once and reusing that from the two
modules. Or, just move the configuration part into a separate module and
have both depend on that. Or, try to dump the dependency on the static
variable.

If the latter, then, well, it depends on several environmental factors that
you left out in your question.

Would it work if I made my library dynamic?

That's usually a good idea, but it's unlikely to help in this specific case.

This is on Windows XP compiling with MSVC 2008.

Others will know more here.

Stefan
 
M

Mathew

more info. I have a large 3rd party library with a function that looks like
this
void dumbfunc() {
static int statevar=0;
++statevar;
if (startvar ==3) printf("I have been called 3 times\n");
}

and I have 2 extensions, foo,py goo.py,created with SWIG, and the both make
calls to dumbfunc. In creating the extensions, I linked to the 3rd party
library.

The behavior I want to see is
foo.dumbfunc()
goo.dumbfunc()
goo.dumbfunc()
I have been called 3 times
 
M

Mathew

okay. It worked to make my 3'rd party library dynamic. Hopefully this will
help someone else in the future.
 

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,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top