porting non-malloc code to malloc

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • micromysore@gmail.com

    #1

    porting non-malloc code to malloc

    Hi,
    I want to post some code which has defn like

    struct AVPicture {
    int *data[4];
    int linesize[4];
    }
    the is noe recognised by matlab, so i need to port to some form like
    struct AVPicture {
    int **data;
    int *linesize;
    }

    Now whatz the best way to go about this process

    1. write a wrapper header, but how to initialize the constants ?? like
    ... **data to *data[]
    2. rewrites the source .. [impossible]

    -madan

  • Michael Mair

    #2
    Re: porting non-malloc code to malloc

    micromysore@gma il.com wrote:[color=blue]
    > Hi,
    > I want to post some code which has defn like
    >
    > struct AVPicture {
    > int *data[4];
    > int linesize[4];
    > }
    > the is noe recognised by matlab, so i need to port to some form like
    > struct AVPicture {
    > int **data;
    > int *linesize;
    > }[/color]

    Maybe it is just me but I cannot make much sense out of
    this. Why do you want to post code but do not do it?
    Matlab offers an interface for C code but this is a Matlab
    thing, not a C thing.
    What is the problem with the above structures?
    That you have to pass only pointers to your data or that
    you want to be able to size the arrays as you need them or ...?

    [color=blue]
    > Now whatz the best way to go about this process
    >
    > 1. write a wrapper header, but how to initialize the constants ?? like
    > .. **data to *data[][/color]

    What constants? Do you mean macros?
    [color=blue]
    > 2. rewrites the source .. [impossible][/color]

    Please try to state your problem more clearly and provide
    a minimal example which exhibits the erroneous behaviour or
    shows the difference you need.


    Cheers
    Michael
    --
    E-Mail: Mine is an /at/ gmx /dot/ de address.

    Comment

    • micromysore@gmail.com

      #3
      Re: porting non-malloc code to malloc

      Matlab has the ability to load MSVC compliant DLL's, atleast thatz what
      they claim.

      matlab has a function called loadlibary, which can can load my DLL
      for ex: loadlibrary('my lib.dll','mylib .h')
      where mylib.h is the interface header file.

      the problem with matlab is that, it works perfectly laod the dll as
      long as there are pointers to functions , and sized constants (ex. int
      linesize[4]) ..

      Now my problem, is that the DLL i have already has those sized
      constants. I need to write a wrapper, which basically converts the
      single or 2D pointers, to the corresponding formats.
      for ex. the matlab interface needs int *linesize, but the DLL has int
      linesize[4].

      -madan

      Comment

      • Walter Roberson

        #4
        Re: porting non-malloc code to malloc

        In article <1108772244.556 024.48020@f14g2 000cwb.googlegr oups.com>,
        <micromysore@gm ail.com> wrote:
        :Now my problem, is that the DLL i have already has those sized
        :constants. I need to write a wrapper, which basically converts the
        :single or 2D pointers, to the corresponding formats.
        :for ex. the matlab interface needs int *linesize, but the DLL has int
        :linesize[4].

        If you were to pass an arbitrary structure into a C function, by
        casting the pointer to void*, then there is no standard way for the
        function to be able to figure out what the structure looks like
        internally. (Some implimentations might have non-standard ways.) You
        will thus not be able to write a C function which can be passed an
        arbitrary structure and which will construct the appropriate new
        structure.

        Similarily, if you try to work it at the preprocessor level, you will
        find that the preprocessor has no way to refer to items such as "the
        first element of the named parameter". You thus will not be able to do
        what you want by a preprocessor macro being passed an arbitrary
        structure.

        If you were willing to rewrite all your structure definitions, then you
        could perhaps [in newer versions of C] write something like a
        "DEFINE_STRUCTU RE" macro that took as arguments all the pieces of the
        structure, and which emitted both the regular 'struct' definition and
        the modified definition you needed. Except that you want more than just
        that -- you would also want to emit a pair of function that converted
        between the two forms. I don't know if that is possible with a variable
        number of arguments even in C99 [I haven't looked at what the C99
        preprocessor is capable of.]


        What I would suggest to you is that your problem would be most easily
        solved outside the C program itself, by using some preprocessing
        of your header files. As the preprocessing would be largely
        textual, I would suggest that a program such as perl might be
        easier to impliment this in than in pure C. The idea would be
        to write a program (e.g., perl script) which read your header
        files that define your structures, and emitted code that
        defined the modified header and defines functions to do the
        conversion. If you have lots of code, you could get fancier and
        add a script that read through the code, figured out which
        structures were referenced, and inserted #include statements
        into the code to import the modified structure definitions
        and conversion functions.
        --
        We don't need no side effect-ing
        We don't need no scope control
        No global variables for execution
        Hey! Did you leave those args alone? -- decvax!utzoo!ut csrgv!roderick

        Comment

        Working...