Dll causes Python to crash when using memset

I've been working on a project where I'm trying to use an old CodeBase library, written in C++, in Python. What I want is to use CodeBase to reindex a .dbf-file that has a .cdx-index. But currently, Python is crashing during runtime. A more detailed explanation will follow further down.

As for Python, I'm using ctypes to load the dll and then execute a function I added myself which should cause no problems, since it doesn't use a single line of code that CodeBase itself isn't using. Python Code:

import ctypes  
cb_interface = ctypes.CDLL("C4DLL.DLL")  
cb_interface.reindex_file("C:\\temp\\list.dbf")  

Here's the CodeBase function I added, but it requires some amount of knowledge that I can't provide right now, without blowing this question up quite a bit. If neccessary, I will provide further insight, as much as I can:

S4EXPORT int reindex_file(const char* file){
    CODE4 S4PTR *code;
    DATA4 S4PTR *data;

    code4initLow(&code, 0, S4VERSION, sizeof(CODE4));
    data = d4open(code, file);
    d4reindex(data);

    return 1;
}

According to my own debugging, my problem happens in code4initLow. Python crashes with a window saying "python.exe has stopped working", when the dll reaches the following line of code:

memset( (void *)c4, 0, sizeof( CODE4 ) ) ;

c4 here is the same object as code in the previous code-block.

Is there some problem with a dll trying to alter memory during runtime? Could it be a python problem that would go away if I were to create a .exe-file from my python script?

If someone could answer me these questions and/or provide a solution for my python-crashing-problem, I would greatly appreciate it.

And last but not least, this is my first question here. If I have accidently managed to violate a written or unwritten rule here, I apologize and promise to fix that as soon as possible.

Answers


Like Joachim Pileborg saying the problem is, to pass a Nullpointer to code4initLow. ("Alternative") Solution is to allocate Memory for the struct CODE4 S4PTR *code = (CODE4*)malloc(sizeof(CODE4));, then pass the Pointer like code4initLow(code, 0, S4VERSION, sizeof(CODE4));.


First of all the pointer code doesn't point anywhere as it is uninitialized. Secondly you don't actually try to fill the structure, since you pass memset a pointer to the pointer.

What you should probably do is declare code as a normal structure instance (and not a pointer), and then use &code when passing it to d4open.


Need Your Help

CakePHP different passwords using AuthComponent

php cakephp hash xdebug

Using AuthComponent i'm having trouble with passwords. One in debugging displays diffent than in saved in database.