Re: Problem embedding Python.

2009-10-29 Thread Brandon Keown
On Oct 27, 7:48 pm, Gabriel Genellina gagsl-...@yahoo.com.ar
wrote:
 En Tue, 27 Oct 2009 06:36:18 -0300, Brandon Keown
 keown.bran...@gmail.com escribió:

  On Oct 27, 2:47 am, Gabriel Genellina gagsl-...@yahoo.com.ar
  wrote:

  You didn't test for the fopen result; are you sure test.py exists in  
  the current directory at the time you run it?

  Ok, so I assumed that the file, if supplied without a path, would use
  current working directory, which was evidently a false assumption.

 Now that you've solved your problem, revise your conclusion. A file
 without a path *is* searched in the current working directory - but that
 directory may not be the one you think it is.

 --
 Gabriel Genellina

I'm not sure what you mean.  I executed the program from the directory
the file was in, they were in the same directory.  And when a program
executes from a path in CMD in windows, that is supposed to be the
CWD.  I'm not sure what it would be set to if not that...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem embedding Python.

2009-10-29 Thread Brandon Keown
O...K...
-- 
http://mail.python.org/mailman/listinfo/python-list


Problem embedding Python.

2009-10-27 Thread Brandon Keown
I am going to try to embed python in an application, but in simple
testing, I could not get it to work.  The following code seems like it
should work, but it crashes, and I have tried several things.  What
could I be doing wrong?

#include Python.h

int main(int argc, char* argv[])
{
FILE* fp = fopen(test.py,r);
Py_Initialize();
PyRun_SimpleFile(fp,test.py);
Py_Finalize();
return 0;
}
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem embedding Python.

2009-10-27 Thread Brandon Keown
On Oct 27, 2:47 am, Gabriel Genellina gagsl-...@yahoo.com.ar
wrote:

 Crashes, how? Try running inside a debugger to see where it crashes, or at  
 least put a few printf.
 You didn't test for the fopen result; are you sure test.py exists in the  
 current directory at the time you run it?

 --
 Gabriel Genellina

Ok, so I assumed that the file, if supplied without a path, would use
current working directory, which was evidently a false assumption.  I
put in an if statement to check to see if the pointer was null which
it was.  So I fully qualified the path in the test file.  Now it
throws an unhandled exception when it goes to execute the line with
PyRun_SimpleFile.  The following code yields the errors after it.

#include Python.h

int main(int argc, char* argv[])
{
FILE* fp = fopen(c:\\Patches\\Test\\Debug\\test.py,w);
if(fp == NULL)
printf(error);
Py_Initialize();
PyRun_SimpleFile(fp,test.py);
Py_Finalize();
return 0;
}

First-chance exception at 0x77d2dbba in Test.exe: 0xC005: Access
violation writing location 0x0014.
Unhandled exception at 0x77d2dbba in Test.exe: 0xC005: Access
violation writing location 0x0014.
First-chance exception at 0x77d2dbba in Test.exe: 0xC005: Access
violation writing location 0x0014.
Unhandled exception at 0x77d2dbba in Test.exe: 0xC005: Access
violation writing location 0x0014.

In the debug output.

This is the call stack (the first line is where execution halted).

Test.exe!main(int argc=1, char** argv=0x006d1b88)  Line 9 + 0x15 bytes
Test.exe!__tmainCRTStartup()  Line 586 + 0x19 bytes
Test.exe!mainCRTStartup()  Line 403

(There is more after this, but it goes back to system calls and
execution is halted here so I thought this was relevant).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem embedding Python.

2009-10-27 Thread Brandon Keown
I found the problem.  Evidently as posted on a few other areas of the
internet, this is a common problem when trying to use compilers that
may have different type definitions for (FILE*).  Here is workable
solution:

#include Python.h

int main(int argc, char* argv[])
{
PyObject* PyFileObject;
char* filename;
Py_Initialize();
filename = c:\\Patches\\Test\\Debug\\test.py;
PyFileObject = PyFile_FromString(filename, r);
PyRun_SimpleFile(PyFile_AsFile(PyFileObject), filename);
Py_Finalize();
return 0;
}
-- 
http://mail.python.org/mailman/listinfo/python-list


Help with chaos math extensions.

2005-10-04 Thread Brandon Keown

Hi,

   I have programmed a fractal generator (Julia Set/Mandelbrot Set) in 
python in the past, and have had good success, but it would run so 
slowly because of the overhead involved with the calculation.  I 
recently purchased VS .NET 2003 (Win XP, precomp binary of python 
2.4.2rc1) to make my own extensions.  I was wondering if anyone could 
help me figure out why I'm getting obscure memory exceptions (runtime 
errors resulting in automatic closing of Python) with my extension.  It 
seems to run okay if imported alone, but when accompanied in a list of 
instructions such as a function it crashes.  I have implemented it in C 
and C++, although I prefer the latter.  In C I got errors only with 
certain ranges in my function.  I have attached my source to this email 
and hope someone can help me.


Thanks,
Brandon


c_lib(cpp).tar.gz
Description: application/gzip
-- 
http://mail.python.org/mailman/listinfo/python-list