Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > making my extensions work together

Reply
Thread Tools

making my extensions work together

 
 
Mathew
Guest
Posts: n/a
 
      08-04-2011
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


 
Reply With Quote
 
 
 
 
John Gordon
Guest
Posts: n/a
 
      08-04-2011
In <j1cs2t$j2f$(E-Mail Removed)> "Mathew" <(E-Mail Removed)> writes:

> 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?

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


--
John Gordon A is for Amy, who fell down the stairs
http://www.velocityreviews.com/forums/(E-Mail Removed) B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

 
Reply With Quote
 
 
 
 
Stefan Behnel
Guest
Posts: n/a
 
      08-04-2011
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

 
Reply With Quote
 
Mathew
Guest
Posts: n/a
 
      08-04-2011
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


"Chris Angelico" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On Thu, Aug 4, 2011 at 2:19 AM, Mathew <(E-Mail Removed)> wrote:
>> I have 2 extensions and they both access a function in a (static)
>> library.
>> The function maintains state information using a static variable.

>
> If your extensions are DLLs and they're both linking to the same
> static library, you should have two independent copies of that library
> - which would mean they don't interfere with one another. That's why
> the other extension doesn't see the change, and normally this is the
> correct and desired behaviour.
>
> Having the two be aware of each other is potentially very messy. As
> Stefan suggested, making one depend on the other would be a lot
> simpler. Alternatively, there may be ways to have the two extensions
> share data through Python itself. What are you looking to accomplish?
>
> ChrisA



 
Reply With Quote
 
Mathew
Guest
Posts: n/a
 
      08-04-2011
okay. It worked to make my 3'rd party library dynamic. Hopefully this will
help someone else in the future.


"Mathew" <(E-Mail Removed)> wrote in message
news:j1cs2t$j2f$(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
$5=Thousands! Let's work together to make this work! Kim Computer Support 1 01-14-2007 06:40 PM
$5=Thousands! Let's work together to make this work! Kim Computer Support 1 01-14-2007 06:38 PM
Unable to access extensions menu or add extensions (I've tried past suggestions) nospam@spam.com Firefox 8 12-01-2005 01:33 AM
Making programs work together. ChuckDubya@gmail.com Python 6 08-17-2005 11:55 AM
Event-Driven Woes: making wxPython and Twisted work together Daniel Bickett Python 2 12-30-2004 10:05 PM



Advertisments