Skip to content

Commit

Permalink
Merge branch 'rurban/nci-void-gh904'
Browse files Browse the repository at this point in the history
  • Loading branch information
Reini Urban committed Jan 2, 2013
2 parents f77520a + 7cc5558 commit 9540be4
Show file tree
Hide file tree
Showing 14 changed files with 176 additions and 66 deletions.
1 change: 0 additions & 1 deletion .gitignore
Expand Up @@ -283,7 +283,6 @@ cachegrind.out.*
/src/exec_dep.c
/src/exec_dep.h
/src/extend_vtable.c
/src/extra_nci_thunks.c
/src/fingerprint.c
/src/glut_callbacks.c
/src/glut_nci_thunks.c
Expand Down
3 changes: 3 additions & 0 deletions ChangeLog
Expand Up @@ -20,6 +20,9 @@
+ Improved Configure.pl probes for --with-llvm
+ Replace / slashes with \ on windows for all Makefiles automatically.
This improves cygwin interaction, like remote or cronjob smoking on windows.
- Tools
+ Improved nci_thunk_gen (v0.02): handle void sig, add declaration
+ Fixed nci examples
- Documentation
+ Re-added docs/ops, the generated ops summary and docs/packfile-c.pod
+ Improved pdd10_embedding
Expand Down
1 change: 1 addition & 0 deletions MANIFEST
Expand Up @@ -2105,6 +2105,7 @@ t/tools/dev/headerizer/testlib/missingheaderfile.in [test]
t/tools/dev/headerizer/testlib/nci_pmc.in [test]
t/tools/dev/headerizer/testlib/none.in [test]
t/tools/dev/headerizer/testlib/validheader.in [test]
t/tools/dev/nci_thunk_gen.t [test]
t/tools/dev/pmctree.t [test]
t/tools/dev/search_ops.t [test]
t/tools/dev/search_ops/samples.pm [test]
Expand Down
13 changes: 8 additions & 5 deletions config/gen/makefiles/root.in
Expand Up @@ -3216,9 +3216,10 @@ src/glut_callbacks$(O): \

src/glut_nci_thunks.c: $(NCI_THUNK_GEN)
$(NCI_THUNK_GEN) \
--dynext \
--loader-name=Parrot_glut_nci_loader \
--loader-storage-class=PARROT_DYNEXT_EXPORT \
--output=src/glut_nci_thunks.c \
--no-warn-dups \
< src/glut_nci_thunks.nci

src/glut_nci_thunks$(O) : $(PARROT_H_HEADERS) \
Expand All @@ -3231,11 +3232,13 @@ $(LIBGLUTCB_SO): $(LIBPARROT) src/glut_callbacks$(O) src/glut_nci_thunks$(O)
$(LINKARGS) @opengl_lib@
$(ADDGENERATED) "$@" "[library]"

src/extra_nci_thunks.c : src/nci/extra_thunks.nci $(NCI_THUNK_GEN)
$(NCI_THUNK_GEN) --dynext --no-warn-dups \
--output=src/extra_nci_thunks.c < src/nci/extra_thunks.nci
src/nci/extra_thunks.c : src/nci/extra_thunks.nci $(DEV_TOOLS_DIR)/nci_thunk_gen.pir
$(PERL) $(DEV_TOOLS_DIR)/mk_nci_thunks.pl

src/nci/core_thunks.c : src/nci/core_thunks.nci $(DEV_TOOLS_DIR)/nci_thunk_gen.pir
$(PERL) $(DEV_TOOLS_DIR)/mk_nci_thunks.pl

bootstrap-nci : src/nci/core_thunks.nci src/nci/extra_thunks.nci $(NCI_THUNK_GEN)
bootstrap-nci : src/nci/core_thunks.nci src/nci/extra_thunks.nci
$(PERL) $(DEV_TOOLS_DIR)/mk_nci_thunks.pl

## SUFFIX OVERRIDE
Expand Down
6 changes: 3 additions & 3 deletions docs/pdds/draft/pdd16_native_call.pod
@@ -1,4 +1,4 @@
# Copyright (C) 2001-2010, Parrot Foundation.
# Copyright (C) 2001-2012, Parrot Foundation.

=head1 [DRAFT] PDD 16: Native Call Interface (NCI)

Expand Down Expand Up @@ -197,7 +197,7 @@ any C type that Parrot supports as NCI value.
The position of the C<user_data> is specified with the C<U> function
signature, when creating the callback PMC:

cb_PMC = new_callback cb_Sub, user_data, "tU"
cb_PMC = new_callback cb_Sub, user_data, "SU"

Given a Parrot function C<cb_Sub>, and a C<user_data> PMC, this creates a
callback PMC C<cb_PMC>, which expects the user data as the second argument.
Expand Down Expand Up @@ -273,7 +273,7 @@ it call back into Parrot.
userdata = 42

.local pmc callback_sub
callback_sub = new_callback sub, userdata, "vtU"
callback_sub = new_callback sub, userdata, "vSU"

# set up NCI

Expand Down
12 changes: 6 additions & 6 deletions examples/nci/PQt.cpp
@@ -1,6 +1,6 @@
/*
# Copyright (C) 2001-2003, Parrot Foundation.
# Copyright (C) 2001-2012, Parrot Foundation.
=head1 NAME
Expand All @@ -12,18 +12,18 @@ Compile with:
*NIX:
$ g++ -fPIC -I$QTDIR/include -I$QTDIR/include/QtGui -L$QTDIR -c PQt.cpp
$ g++ -fPIC -I$QTDIR/include -I$QTDIR/include/QtGui -L$QTDIR examples/nci/PQt.cpp -shared -o runtime/parrot/dynext/libPQt.so $QTDIR/lib/libQtCore4.so $QTDIR/lib/libQtGui4.so
$ gcc -shared -o libPQt.so PQt.o $QTDIR/lib/libQtCore4.so $QTDIR/lib/libQtGui4.so
Debian:
$ apt-get install libqt4-dev
$ g++ -shared -fPIC -o runtime/parrot/dynext/libPQt.so examples/nci/PQt.cpp -I/usr/include/qt4/QtGui -I/usr/include/qt4 -lQtGui -lQtCore
Windows:
> "%VS90COMNTOOLS%\vsvars32.bat"
> set INCLUDE=%QTDIR%\include;%QTDIR%\include\QtGui;%INCLUDE%
> set LIB=%QTDIR%\lib;%LIB%
> cl /LD PQt.cpp QtGui4.lib QtCore4.lib
Or something like that...
Expand Down
7 changes: 4 additions & 3 deletions examples/nci/QtHelloWorld.pasm
@@ -1,4 +1,4 @@
# Copyright (C) 2001-2003, Parrot Foundation.
# Copyright (C) 2001-2012, Parrot Foundation.

=head1 NAME

Expand Down Expand Up @@ -35,7 +35,7 @@ rebuilding Parrot.
set P2, P5 # remember pApp
# get and invoke QLabel_new
dlfunc P0, P1, "QLabel_new", "pt"
dlfunc P0, P1, "QLabel_new", "pS"
# if you need more labels, save P0 = QLabel_new() function
set_args "0", "Hello, world!"
get_results "0", P5
Expand All @@ -58,7 +58,8 @@ rebuilding Parrot.
=head1 SEE ALSO
F<examples/nci/PQt.C>, F<docs/pdds/pdd03_calling_conventions.pod>.
F<examples/nci/QTHelloWorld.pir>,
F<examples/nci/PQt.cpp>, F<docs/pdds/pdd03_calling_conventions.pod>.
=cut
Expand Down
5 changes: 3 additions & 2 deletions examples/nci/QtHelloWorld.pir
Expand Up @@ -45,7 +45,7 @@ rebuilding Parrot.
.local pmc QLabel_new, pLabel
.local string caption
caption = "Hello, world!"
dlfunc QLabel_new, libpqt, "QLabel_new", "pt"
dlfunc QLabel_new, libpqt, "QLabel_new", "pS"
pLabel = QLabel_new(caption)
.local pmc QLabel_resize
Expand All @@ -64,7 +64,8 @@ rebuilding Parrot.
=head1 SEE ALSO
F<examples/nci/PQt.C>, F<docs/pdds/pdd03_calling_conventions.pod>.
F<examples/nci/PQt.cpp>, F<docs/pdds/pdd03_calling_conventions.pod>,
F<docs/pdds/draft/pdd16_native_call.pod>.
=cut
Expand Down
20 changes: 9 additions & 11 deletions src/nci/core_thunks.c
Expand Up @@ -8,14 +8,10 @@
*/

/* src/nci/core_thunks.c
* Copyright (C) 2010, Parrot Foundation.
* Copyright (C) 2010-2012, Parrot Foundation.
* Overview:
* Native Call Interface routines. The code needed to build a
* parrot to C call frame is in here
* Data Structure and Algorithms:
* History:
* Notes:
* References:
* Native Call Interface routines.
* Code to call C from parrot.
*/


Expand All @@ -32,18 +28,20 @@
#endif

/* HEADERIZER HFILE: none */

void
Parrot_nci_load_core_thunks(PARROT_INTERP);
/* HEADERIZER STOP */

/* All our static functions that call in various ways. Yes, terribly
hackish, but that is just fine */
/* All our static functions that call in various ways. */



void
Parrot_nci_load_core_thunks(PARROT_INTERP)
{
Parrot_nci_load_core_thunks(PARROT_INTERP) {
PMC * const iglobals = interp->iglobals;
PMC *nci_funcs;
PMC *temp_pmc;

PARROT_ASSERT(!(PMC_IS_NULL(iglobals)));

Expand Down
52 changes: 41 additions & 11 deletions src/nci/extra_thunks.c
Expand Up @@ -8,14 +8,10 @@
*/

/* src/nci/extra_thunks.c
* Copyright (C) 2010, Parrot Foundation.
* Copyright (C) 2010-2012, Parrot Foundation.
* Overview:
* Native Call Interface routines. The code needed to build a
* parrot to C call frame is in here
* Data Structure and Algorithms:
* History:
* Notes:
* References:
* Native Call Interface routines.
* Code to call C from parrot.
*/


Expand All @@ -32,10 +28,12 @@
#endif

/* HEADERIZER HFILE: none */

void
Parrot_nci_load_extra_thunks(PARROT_INTERP);
/* HEADERIZER STOP */

/* All our static functions that call in various ways. Yes, terribly
hackish, but that is just fine */
/* All our static functions that call in various ways. */


static void
Expand Down Expand Up @@ -3293,10 +3291,30 @@ pcf_STRING_ptr_ptr_INTVAL(PARROT_INTERP, PMC *nci, SHIM(PMC *self))
t_0 = v_0;
Parrot_pcc_set_call_from_c_args(interp, call_object, "S", t_0);
}
static void
pcf_ptr_void(PARROT_INTERP, PMC *nci, SHIM(PMC *self))
{
typedef void *(* func_t)(void);
func_t fn_pointer;
void *orig_func;
PMC * const ctx = CURRENT_CONTEXT(interp);
PMC * const call_object = Parrot_pcc_get_signature(interp, ctx);
PMC * t_0; void * v_0;
GETATTR_NCI_orig_func(interp, nci, orig_func);
fn_pointer = (func_t)D2FPTR(orig_func);
v_0 = (*fn_pointer)();
if (v_0 != NULL) {
t_0 = Parrot_pmc_new(interp, enum_class_UnManagedStruct);
VTABLE_set_pointer(interp, t_0, v_0);
}
else {
t_0 = PMCNULL;
};
Parrot_pcc_set_call_from_c_args(interp, call_object, "P", t_0);
}

void
Parrot_nci_load_extra_thunks(PARROT_INTERP)
{
Parrot_nci_load_extra_thunks(PARROT_INTERP) {
PMC * const iglobals = interp->iglobals;
PMC *nci_funcs;
PMC *temp_pmc;
Expand Down Expand Up @@ -4938,6 +4956,18 @@ Parrot_nci_load_extra_thunks(PARROT_INTERP)
VTABLE_set_pmc_keyed(interp, nci_funcs, sig_pmc, temp_pmc);
}

{
const int n = 2;
static const int sig[] = { 29, 28, };
PMC *sig_pmc = Parrot_pmc_new_init_int(interp, enum_class_FixedIntegerArray, n);
int i;
for (i = 0; i < n; i++)
VTABLE_set_integer_keyed_int(interp, sig_pmc, i, sig[i]);
temp_pmc = Parrot_pmc_new(interp, enum_class_UnManagedStruct);
VTABLE_set_pointer(interp, temp_pmc, (void *)pcf_ptr_void);
VTABLE_set_pmc_keyed(interp, nci_funcs, sig_pmc, temp_pmc);
}


}

Expand Down
6 changes: 6 additions & 0 deletions src/nci/extra_thunks.nci
Expand Up @@ -285,3 +285,9 @@ STRING (ptr, INTVAL)

# NCI::Utils
STRING (ptr, ptr, INTVAL)

# examples/nci/Qt
p v
p p
v pii
v p
4 changes: 2 additions & 2 deletions t/library/nciutils.t
@@ -1,5 +1,5 @@
#!./parrot
# Copyright (C) 2001-2010, Parrot Foundation.
# Copyright (C) 2001-2012, Parrot Foundation.

=head1 NAME

Expand All @@ -11,7 +11,7 @@ t/library/nciutils.t -- Tests for NCI::Utils

=head1 DESCRIPTION

Testing Perl 6 objects.
Testing NCI::Utils calls to libc and libnci_test.

=cut

Expand Down
46 changes: 46 additions & 0 deletions t/tools/dev/nci_thunk_gen.t
@@ -0,0 +1,46 @@
#! perl
# Copyright (C) 2013, Parrot Foundation.

use strict;
use warnings;
use lib qw(lib);

use Test::More tests => 2;
use Parrot::Config;

my ($cc, $cc_inc, $ccflags, $cc_warn, $cc_o_out, $cc_shared, $cc_debug, $clock_best)
= @PConfig{qw(cc cc_inc ccflags ccwarn cc_o_out cc_shared cc_debug clock_best)};
my $cflags = "$cc_inc $ccflags $cc_debug $clock_best $cc_shared";
my $cmd = q(echo "p v"|./parrot tools/dev/nci_thunk_gen.pir --output=test_nci.c);
system ($cmd);
ok (-f "test_nci.c", "test_nci.c created") or diag $cmd;

$cmd = qq($cc $cflags $cc_warn -I. -Isrc ${cc_o_out}test_nci.o -c test_nci.c);
system ($cmd);
ok (-f "test_nci.o", "test_nci.o created") or diag $cmd;

unlink ("test_nci.*");

__END__
=head1 NAME
t/tools/dev/nci_thunk_gen.t - test bugs in tools/dev/nci_thunk_gen.pir
=head1 SYNOPSIS
% prove t/tools/dev/nci_thunk_gen.t
=head1 DESCRIPTION
Test basic F<nci_thunk_gen.pir> usage.
Test that the sig "p v" compiles to valid C code [GH #904].
=cut
# Local Variables:
# mode: cperl
# cperl-indent-level: 4
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4:

0 comments on commit 9540be4

Please sign in to comment.