<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Aaron Berg wrote:
<blockquote TYPE=CITE>I made a file called crw.c inside that file looks
like this:
<p>#include <stdio.h>
<br>#include<stdlib.h>
<p>int Cread(int fd,  void *buf, unsigned count)
<br>{
<br>    int fd;
<br>    char buffer[1024];
<p>    Data = read(fd, *buf, count);
<br>    return Data;
<br>}
<p>In another file called crwwrapper.c I have this code:
<p>#include "Python.h"
<p>extern in Cread(int, void, unsigned);
<p>PyObject *crw_Cread(PyObject *self PyObject *args)
<br>{
<br>    int fd, r;
<br>    char buffer[1024];
<br>    unsigned count;
<p>if(!PyArg_ParseTuple(args, "ii",&fd,&buf,&count)){
<br>return NULL;
<br>}
<br>    /*call c function*/
<br>    r = Cread(fd, buf,count);
<br>return Py_buildValue("i", r);
<br>}
<br>/*method table*/
<br>static pyMethodDef crwmethods[] = {
<br>    ("Cread", crw_Cread, METH_VARARGS}, {NULL, NULL}
<br>};
<p>/*module initialization function*/
<br>void initcrw(){
<br>    Py_IniModule("crw", crwmethods);
<br>---------------------------------------
<p>Could anyone tell me what I am doing wrong if anything?
<br>I am trying to wrap the C function read() around python so I can read
directly from a network socket. something that python doesn't allow you
to do if I understand correctly.
<p>Thanks people,
<br>Aaron C Berg</blockquote>
I made a typo
<br>extern in Cread(int, void, unsigned);
<br>should be
<br>extern int Cread(int, void, unsigned);
<br> </html>