niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Programming » python
mixing SWIG generated and Python-level usertype?
Post new topic   Reply to topic Page 1 of 1 [1 Post] View previous topic :: View next topic
Author Message
Bo Peng
*nix forums addict


Joined: 27 Feb 2005
Posts: 59

PostPosted: Wed Feb 02, 2005 6:30 am    Post subject: mixing SWIG generated and Python-level usertype? Reply with quote

Dear list,

My SWIG generated module (myModule) needs an array-like object (carray)
to work. Carray objects are created both internally (in C++ level) and
through Python so I have to load it when myModule initializes.

carray is modified from arraymodule.c and is quite simple:

static PyMethodDef a_methods[] =
{
{"carray", a_array, METH_VARARGS, a_array_doc},
{ /* sentinel */
NULL, NULL
}
};

Currently, I load a_methods directly using code (error checking ignored)

PyObject* mm = PyImport_AddModule("__main__");
PyObject* dict = PyModule_GetDict(mm);
PyObject* v = PyCFunction_New(a_methods, NULL);
PyDict_SetItemString(dict, a_methods->ml_name, v);

There are several problems with this approach:

1. use of __main__? carray can not be accessed directly within other
libraries. ('from myModule import *' DOES NOT import carray!) I tried to
use __builtins__ but it does not work for some reason out of my
understanding of Python. I am not sure how to add carray to myModule
dictionary.

2. No type object? I am not sure what is the purpose of ArrayType but
the usual init_module should be
m = Py_InitModule3("carray", a_methods, module_doc);
d = PyModule_GetDict(m);
PyDict_SetItemString(dict, "ArrayType", (PyObject *)&Arraytype);

When I add ArrayType to __main__ , access to ArrayType leads to a quick
core dump.

I do not feel comfortable with my current approach. Could anyone tell me
some better (more standard) way?

Many thanks in advance.
Bo
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [1 Post] View previous topic :: View next topic
The time now is Thu Jan 08, 2009 11:13 pm | All times are GMT
navigation Forum index » Programming » python
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts Python proficiency test Kent Johnson python 0 Fri Jul 21, 2006 10:47 am
No new posts Since there was talk of if-then-else not being allowed in... Casey Hawthorne python 5 Fri Jul 21, 2006 3:41 am
No new posts Using python code from Java? fortepianissimo python 4 Thu Jul 20, 2006 5:36 pm
No new posts FAQ 1.9 How does Perl compare with other languages like J... PerlFAQ Server Perl 0 Thu Jul 20, 2006 7:03 am
No new posts Depricated String Functions in Python Anoop python 14 Thu Jul 20, 2006 6:26 am

Credit Card | Guitar Lessons | Mortgage Calculator | Mobile Phones | Loans
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.2280s ][ Queries: 16 (0.1553s) ][ GZIP on - Debug on ]