Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Global variables in a C extension for Python

Reply
Thread Tools

Global variables in a C extension for Python

 
 
Lorenzo Di Gregorio
Guest
Posts: n/a
 
      12-28-2011
Hello,

I've written a C extension for Python which works so far, but now I've
stumbled onto a simple problem for which I just can't find any example
on the web, so here I am crying for help

I'll trying to reduce the problem to a minimal example. Let's say I
need to call from Python functions of a C program like:

static int counter = 0;
void do_something(...) {
.... counter++; ...
}
void do_something_else(...) {
.... counter++; ...
}

So they access a common global variable. I've written the wrappers
for the functions, but I'd like to place "counter" in the module's
space and have wrappers accessing it like self->counter. I do not
need to make "counter" visible to Python, I just need the global
static variable available for C.

I've got somehow a clue of how this should work, but not much more
than a clue, and I'd appreciate to see a simple example.

Best Regards,
Lorenzo
 
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
Initialize global variable before any other global variables jubelbrus C++ 5 07-20-2007 06:38 PM
FWSM/PIX and Dynamic PAT using global IP range vs. global interface vs. global IP Hoffa Cisco 1 10-25-2006 06:50 PM
FWSM/PIX and Dynamic PAT using global IP range vs. global interface vs. global IP Hoffa Cisco 0 10-25-2006 01:04 PM
Global variables on par with ASP's global.asa Wayne ASP .Net 2 11-11-2003 10:58 PM
Global variables - application variables vs include file mark4asp ASP General 1 09-03-2003 01:30 PM



Advertisments