Re: Is there conversion method to convert pyunicodeobject to pybyteobject?

2010-05-19 Thread MathanK
Got it worked with the following change.

PyUnicodeObject *p = ...whatever...;

char* tmp = (char *)p;
PyObject* arg = PyBytes_FromString (tmp); 

function( (PyBytesObject*) arg); 


From : MathanKlt;switch2mat...@gmail.comgt;
To : python-list lt;python-list@python.orggt;
Date : Sat, 15 May 2010 02:50:22 -1200
Subject : Is there conversion method to convert pyunicodeobject to pybyteobject?

Hi All,

A variable whose data type is PyUnicodeObject is to be assigned to varioable of 
PyBytesObject type 

example :
void function( (PyBytesObject* byte){} 
PyUnicodeObject *p = ...whatever...; 
function( (PyBytesObject*)p); 

compiled and got a Bus Error.

Cheers,
Mathan
-- 
http://mail.python.org/mailman/listinfo/python-list


Is there conversion method to convert pyunicodeobject to pybyteobject?

2010-05-18 Thread MathanK
Hi All,

A variable whose data type is PyUnicodeObject is to be assigned to varioable of 
PyBytesObject type 

example :

PyUnicodeObject *p = ...whatever...; 
function( (PyByteObject*p)); 

compiled and got a Bus Error.

Cheers,
Mathan
-- 
http://mail.python.org/mailman/listinfo/python-list


Getting System error with PyModule_AddIntConstant funtion

2010-05-18 Thread MathanK
Following is a Python C api which runs properly without PyModule_AddIntConstant 
function. 


But when PyModule_AddIntConstant() function is used, getting the following 
error when i call 
c. path(test call);
 SystemError: NULL result without error in PyObject_Call 


Python C api- c.c


int test(int a){
 return (2*a+a);
 }
 

 PyObject* dict = NULL;
 

 static PyObject* path(PyObject* self, PyObject* args) {
 char *cpath;
 PyUnicodeObject *path;
 PyUnicodeObject *test; 
 

 if (!PyArg_ParseTuple(args, s, amp;path))
return NULL; 
 cpath = (char *)path; 
 test = (PyUnicodeObject*)(cpath); 
 PyObject *testDict = PyDict_New();
 int testVal = PyDict_SetItem(testDict, (PyObject 
*)PyUnicode_FromString(cpath), (PyObject *)PyUnicode_FromString(cpath));
  
 return Py_BuildValue(s, test);
 }
 static PyObject* c(PyObject* self, PyObject* args) {
 
 int a;
 int result;
if(!PyArg_ParseTuple(args, i, amp;a))
 return NULL;
 result = test(a);
 return Py_BuildValue(i, result);
  
 }
 

 static PyMethodDef cmethods[] = {
 {c, c, METH_VARARGS, watch},
 {path, path, METH_VARARGS, test},
 {NULL, NULL, 0, NULL},
 };
 

 static struct PyModuleDef c_Module = {
 PyModuleDef_HEAD_INIT,
 c,
 (
   Interface.
 ),
 -1,
 cmethods
 };
 

 PyMODINIT_FUNC PyInit_c(void) {
  
 PyObject* obj = PyModule_Create(amp;c_Module);
 long lon1 = 0;
 PyModule_AddIntConstant(obj, test, lon1);
 
 }
 

 int main(int argc, wchar_t *argv[])
 {
 PyImport_AppendInittab(c, PyInit_c);
 Py_SetProgramName(argv[0]);
 Py_Initialize();
 PyImport_ImportModule(c);
 return 0;
 }
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting System error with PyModule_AddIntConstant funtion

2010-05-18 Thread MathanK
I checked for Null also. But No change in the result. Still getting the system 
error.
But when i m calling only c.c(5) function and not calling c.path(hi python c 
api) function, i m getting proper output without any system error.
Any clue? 
 
 Subject: Re: Getting System error with PyModule_AddIntConstant funtion
 From: Philip Semanchuk lt;phi...@semanchuk.comgt;
 Date: Tue, 18 May 2010 11:50:46 -0400
 To: python-list (General) lt;python-list@python.orggt;
 
 - Contents -
 
 
 On May 18, 2010, at 11:41 AM, MathanK wrote: 
 
 gt; Following is a Python C api which runs properly without 
 gt; PyModule_AddIntConstant function. 
 gt; 
 gt; 
 gt; But when PyModule_AddIntConstant() function is used, getting the 
 gt; following error when i call 
 gt; c. path(test call); 
 gt;  SystemError: NULL result without error in PyObject_Call  
 
 Hi Mathan, 
 You're not checking the return code from PyModule_Create(). Is it 
 returning NULL? 
 
 Also, there's a list specific to Python's C API. You might get a 
 better response to your question there: 
 http://mail.python.org/mailman/listinfo/capi-sig 
 
 
 bye 
 Philip 
 
 
 gt; 
 gt; 
 gt; Python C api- c.c 
 gt; 
 gt; 
 gt; int test(int a){ 
 gt; return (2*a+a); 
 gt; } 
 gt; 
 gt; 
 gt; PyObject* dict = NULL; 
 gt; 
 gt; 
 gt; static PyObject* path(PyObject* self, PyObject* args) { 
 gt; char *cpath; 
 gt; PyUnicodeObject *path; 
 gt; PyUnicodeObject *test; 
 gt; 
 gt; 
 gt; if (!PyArg_ParseTuple(args, s, amp;amp;path)) 
 gt; return NULL; 
 gt; cpath = (char *)path; 
 gt; test = (PyUnicodeObject*)(cpath); 
 gt; PyObject *testDict = PyDict_New(); 
 gt; int testVal = PyDict_SetItem(testDict, (PyObject 
 gt; *)PyUnicode_FromString(cpath), (PyObject 
 gt; *)PyUnicode_FromString(cpath)); 
 gt; 
 gt; return Py_BuildValue(s, test); 
 gt; } 
 gt; static PyObject* c(PyObject* self, PyObject* args) { 
 gt; 
 gt; int a; 
 gt; int result; 
 gt; if(!PyArg_ParseTuple(args, i, amp;amp;a)) 
 gt; return NULL; 
 gt; result = test(a); 
 gt; return Py_BuildValue(i, result); 
 gt; 
 gt; } 
 gt; 
 gt; 
 gt; static PyMethodDef cmethods[] = { 
 gt; {c, c, METH_VARARGS, watch}, 
 gt; {path, path, METH_VARARGS, test}, 
 gt; {NULL, NULL, 0, NULL}, 
 gt; }; 
 gt; 
 gt; 
 gt; static struct PyModuleDef c_Module = { 
 gt; PyModuleDef_HEAD_INIT, 
 gt; c, 
 gt; ( 
 gt; Interface. 
 gt; ), 
 gt; -1, 
 gt; cmethods 
 gt; }; 
 gt; 
 gt; 
 gt; PyMODINIT_FUNC PyInit_c(void) { 
 gt; 
 gt; PyObject* obj = PyModule_Create(amp;amp;c_Module); 
 gt; long lon1 = 0; 
 gt; PyModule_AddIntConstant(obj, test, lon1); 
 gt; 
 gt; } 
 gt; 
 gt; 
 gt; int main(int argc, wchar_t *argv[]) 
 gt; { 
 gt; PyImport_AppendInittab(c, PyInit_c); 
 gt; Py_SetProgramName(argv[0]); 
 gt; Py_Initialize(); 
 gt; PyImport_ImportModule(c); 
 gt; return 0; 
 gt; }
-- 
http://mail.python.org/mailman/listinfo/python-list


Alternate string object type for PyStringObject(available Python 2.x) in python 3.x?

2010-05-14 Thread MathanK
What is the replacement in python 3.x for PyStringObject which is available in 
python 2.x?
-- 
http://mail.python.org/mailman/listinfo/python-list