in reply to Re^3: How to keep C variables "alive" between invocations with Inline::C
in thread How to keep C variables "alive" between invocations with Inline::C

Could you add a method to your sample please?

I tried adding this method:

Node* insert( Node* root ) { warn("insert\n"); // DEBUG return root; }

But I get the classic: Can't locate object method "insert" via package "Node" at ...


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
RIP an inspiration; A true Folk's Guy
  • Comment on Re^4: How to keep C variables "alive" between invocations with Inline::C
  • Download Code

Replies are listed 'Best First'.
Re^5: How to keep C variables "alive" between invocations with Inline::C
by ikegami (Patriarch) on Sep 28, 2010 at 01:41 UTC

    Works for me. What your build output and your .c?

    But I've found that it creates a second scalar that points to root, so DESTROY is now being called twice for the same pointer.

      Okay. Forget it. Mismatch (case) between package name and struct typedef!

      C:\test>ICobject.pl Starting Build Preprocess Stage Finished Build Preprocess Stage Starting Build Parse Stage Finished Build Parse Stage Starting Build Glue 1 Stage Finished Build Glue 1 Stage Starting Build Glue 2 Stage Finished Build Glue 2 Stage Starting Build Glue 3 Stage Finished Build Glue 3 Stage Starting Build Compile Stage Starting "perl Makefile.PL" Stage Writing Makefile for ICobject Finished "perl Makefile.PL" Stage Starting "make" Stage Microsoft (R) Program Maintenance Utility Version 9.00.21022.08 Copyright (C) Microsoft Corporation. All rights reserved. C:\Perl64\bin\perl.exe C:\Perl64\lib\ExtUtils\xsubpp -typemap + C:\Perl cl -c -IC:/test -nologo -GF -W3 -MD -Zi -DNDEBUG -Ox -GL -fp +:precise ICobject.c Running Mkbootstrap for ICobject () C:\Perl64\bin\perl.exe -MExtUtils::Command -e "chmod" -- 644 I +Cobject. C:\Perl64\bin\perl.exe -MExtUtils::Mksymlists -e "Mksymlists( +'NAME'=> link -out:blib\arch\auto\ICobject\ICobject.dll -dll -nologo -n +odefault Creating library blib\arch\auto\ICobject\ICobject.lib and object bl +ib\arch\ Generating code Finished generating code if exist blib\arch\auto\ICobject\ICobject.dll.manifest mt -nol +ogo -man if exist blib\arch\auto\ICobject\ICobject.dll.manifest del bli +b\arch\a C:\Perl64\bin\perl.exe -MExtUtils::Command -e "chmod" -- 755 b +lib\arch C:\Perl64\bin\perl.exe -MExtUtils::Command -e "cp" -- ICobject +.bs blib C:\Perl64\bin\perl.exe -MExtUtils::Command -e "chmod" -- 644 b +lib\arch Finished "make" Stage Starting "make install" Stage Microsoft (R) Program Maintenance Utility Version 9.00.21022.08 Copyright (C) Microsoft Corporation. All rights reserved. Files found in blib\arch: installing files in blib\lib into architectu +re depen Installing C:\test\_Inline\lib\auto\ICobject\ICobject.dll Installing C:\test\_Inline\lib\auto\ICobject\ICobject.exp Installing C:\test\_Inline\lib\auto\ICobject\ICobject.lib Installing C:\test\_Inline\lib\auto\ICobject\ICobject.pdb Finished "make install" Stage Starting Cleaning Up Stage Finished Cleaning Up Stage Finished Build Compile Stage new SV = RV(0xe7bd8) at 0xe7bc8 REFCNT = 1 FLAGS = (PADMY,ROK) RV = 0x3a89d70 SV = PVMG(0x3a2ff78) at 0x3a89d70 REFCNT = 1 FLAGS = (OBJECT,IOK,pIOK) IV = 867784 NV = 0 PV = 0 STASH = 0x1cde08 "Node" Node=SCALAR(0x3a89d70) Can't locate object method "insert" via package "Node" at C:\test\ICob +ject.pl
      #! perl -slw package NODE; use Inline C => Config => BUILD_NOISY => 1; #, TYPEMAPS => './ICobject +.tmap'; use Inline C => <<'END_C', NAME => 'ICobject', CLEAN_AFTER_BUILD => 0 +; struct _node { struct _node *left; struct _node *right; }; typedef struct _node Node; Node* new( char *class ) { Node* node; warn("new\n"); // DEBUG Newx(node, 1, Node); // node->... = ...; return node; } Node* insert( Node* root ) { warn("insert\n"); // DEBUG return root; } void DESTROY(Node* node) { warn("DESTROY\n"); // DEBUG Safefree(node); } END_C package main; use strict; use Devel::Peek; my $tree = NODE->new(); print Dump $tree; print $tree; $tree->insert( 'fred', 3 );

      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.