Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[GH #904] Allow void as valid arg sig, fix nci_pv, add test

The previous nci_pv fix did compile, but not work, this sets up the call pmc properly.
  • Loading branch information...
commit 91a999abf9968d5fa4273eb1b04b83cc8bc50389 1 parent cdc9969
Reini Urban rurban authored
7 examples/nci/PQt.cpp
View
@@ -1,6 +1,6 @@
/*
-# Copyright (C) 2001-2012, Parrot Foundation.
+# Copyright (C) 2001-2013, Parrot Foundation.
=head1 NAME
@@ -19,6 +19,11 @@ Compile with:
$ 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
+Macports:
+
+ $ sudo port install qt4-mac
+ $ c++ -I/opt/local/include -I/opt/local/Library/Frameworks/QtGui.framework/Header -undefined dynamic_lookup -o runtime/parrot/dynext/libPQt.dylib examples/nci/PQt.cpps -L/opt/local/lib -lQtGui -lQtCore
+
Windows:
> "%VS90COMNTOOLS%\vsvars32.bat"
23 examples/nci/QtHelloWorld.pir
View
@@ -1,4 +1,4 @@
-# Copyright (C) 2009, Parrot Foundation.
+# Copyright (C) 2009-2013, Parrot Foundation.
=head1 NAME
@@ -14,9 +14,10 @@ Sample "Hello World" with Qt, via Parrot Native Call Interface (NCI). See
F<docs/pdds/pdd03_calling_conventions.pod>.
Qt - A cross-platform application and UI framework
-(L<http://www.qtsoftware.com/about/news/lgpl-license-option-added-to-qt>). You'll need to build
-F<libPQt.so> or F<PQt.dll> and install it in F<runtime/parrot/dynext> for this to
-work, see F<examples/nci/PQt.C> for more information.
+(L<http://www.qtsoftware.com/about/news/lgpl-license-option-added-to-qt>).
+You'll need to build F<libPQt.so> or F<PQt.dll> and install it in
+F<runtime/parrot/dynext> for this to work, see F<examples/nci/PQt.cpp>
+for more information.
Note that this will either need JIT for building the NCI-functions on
the fly. If this is not available try adding missing signatures to
@@ -38,26 +39,30 @@ rebuilding Parrot.
loaded:
print "Loaded\n"
+ load_bytecode 'NCI/Utils.pbc'
+ .local pmc dlfancy
+ dlfancy = get_hll_global ['NCI';'Utils'], 'dlfancy'
+
.local pmc QApplication_new, pApp
- dlfunc QApplication_new, libpqt, "QApplication_new", "pv"
+ QApplication_new = dlfunc libpqt, "QApplication_new", "pv"
pApp = QApplication_new()
.local pmc QLabel_new, pLabel
.local string caption
caption = "Hello, world!"
- dlfunc QLabel_new, libpqt, "QLabel_new", "pS"
+ QLabel_new = dlfancy(libpqt, "QLabel_new", "pt")
pLabel = QLabel_new(caption)
.local pmc QLabel_resize
- dlfunc QLabel_resize, libpqt, "QLabel_resize", "vpii"
+ QLabel_resize = dlfunc libpqt, "QLabel_resize", "vpii"
QLabel_resize(pLabel, 120, 30)
.local pmc QLabel_show
- dlfunc QLabel_show, libpqt, "QLabel_show", "vp"
+ QLabel_show = dlfunc libpqt, "QLabel_show", "vp"
QLabel_show(pLabel)
.local pmc QApplication_exec
- dlfunc QApplication_exec, libpqt,"QApplication_exec", "vp"
+ QApplication_exec = dlfunc libpqt, "QApplication_exec", "vp"
QApplication_exec(pApp)
.end
1  src/nci/extra_thunks.c
View
@@ -3300,6 +3300,7 @@ pcf_ptr_void(PARROT_INTERP, PMC *nci, SHIM(PMC *self))
PMC * const ctx = CURRENT_CONTEXT(interp);
PMC * const call_object = Parrot_pcc_get_signature(interp, ctx);
PMC * t_0; void * v_0;
+ Parrot_pcc_fill_params_from_c_args(interp, call_object, "");
GETATTR_NCI_orig_func(interp, nci, orig_func);
fn_pointer = (func_t)D2FPTR(orig_func);
v_0 = (*fn_pointer)();
3  src/nci/signatures.c
View
@@ -159,6 +159,9 @@ ncidt_to_pcc(PARROT_INTERP, PARROT_DATA_TYPE t)
case enum_type_PMC:
return 'P';
+ case enum_type_void:
+ return 'v';
+
default:
Parrot_ex_throw_from_c_args(interp, NULL, 0, "Unhandled NCI type: `%Ss'",
Parrot_dt_get_datatype_name(interp, t));
20 src/nci_test.c
View
@@ -1,5 +1,5 @@
/*
-Copyright (C) 2001-2011, Parrot Foundation.
+Copyright (C) 2001-2013, Parrot Foundation.
=head1 NAME
@@ -98,6 +98,7 @@ PARROT_DYNEXT_EXPORT void nci_vP(void *);
PARROT_DYNEXT_EXPORT void nci_vpii(ARGMOD(Outer *), int, int);
PARROT_DYNEXT_EXPORT void nci_vv(void);
PARROT_DYNEXT_EXPORT void nci_vp(ARGIN(const Opaque*));
+PARROT_DYNEXT_EXPORT void * nci_pv(void);
PARROT_DYNEXT_EXPORT void nci_vfff(float, float, float);
PARROT_DYNEXT_EXPORT char * nci_cstring_cstring(const char *);
@@ -995,6 +996,23 @@ nci_vp(ARGIN(const Opaque *inOpaque))
/*
+=item C<PARROT_DYNEXT_EXPORT void * nci_pv(void)>
+
+Return the pointer to the global variable C<nci_dlvar_int>.
+
+=cut
+
+*/
+
+PARROT_DYNEXT_EXPORT
+void*
+nci_pv(void)
+{
+ return &nci_dlvar_int;
+}
+
+/*
+
=item C<static void validate_float(float f, double checkval)>
Check that a float value f is has an error ratio of less than 0.01
42 t/pmc/nci.t
View
@@ -1,5 +1,5 @@
#! perl
-# Copyright (C) 2001-2011, Parrot Foundation.
+# Copyright (C) 2001-2013, Parrot Foundation.
use strict;
use warnings;
@@ -38,7 +38,7 @@ SKIP: {
unless ( -e "runtime/parrot/dynext/libnci_test$PConfig{load_ext}" ) {
plan skip_all => "Please make libnci_test$PConfig{load_ext}";
}
- plan tests => 60;
+ plan tests => 61;
pir_output_is( << 'CODE', << 'OUTPUT', 'load library fails' );
.sub test :main
@@ -486,6 +486,44 @@ libnci_test was successfully loaded
OUTPUT
}
+ pir_output_is( << 'CODE', << 'OUTPUT', "nci_pv" );
+
+.include "datatypes.pasm"
+
+.sub test :main
+
+ # load libnci_test.so
+ .local string library_name
+ library_name = 'libnci_test'
+ .local pmc libnci_test
+ libnci_test = loadlib library_name
+ unless libnci_test goto NOT_LOADED
+ print library_name
+ say " was successfully loaded"
+
+ # address of nci_dlvar_int
+ .local pmc nci_dlvar_int
+ nci_dlvar_int = dlvar libnci_test, "nci_dlvar_int"
+
+ .local pmc nci_pv
+ nci_pv = dlfunc libnci_test, "nci_pv", "pv"
+ $P0 = nci_pv()
+ unless nci_dlvar_int goto NOT_LOADED
+ say "nci_dlvar_int is a ptr"
+ unless $P0 goto NOT_LOADED
+ say "nci_pv returned non-NULL ptr"
+ if $P0 != nci_dlvar_int goto NOT_LOADED
+ say "nci_pv same ptr as nci_dlvar_int"
+
+NOT_LOADED:
+.end
+CODE
+libnci_test was successfully loaded
+nci_dlvar_int is a ptr
+nci_pv returned non-NULL ptr
+nci_pv same ptr as nci_dlvar_int
+OUTPUT
+
pasm_output_is( <<'CODE', <<'OUTPUT', 'nci_dd - PASM' );
.pcc_sub :main main:
loadlib P1, "libnci_test"
7 tools/dev/nci_thunk_gen.pir
View
@@ -670,8 +670,13 @@ TEMPLATE
$P0 = 'map_from_sig_table'('sig_char', sig :flat)
$S0 = shift $P0
pcc_sig = join "", $P0
- if pcc_sig == "v" goto return
+ if pcc_sig != "v" goto end_handle_v
+ preamble = 'sprintf'(<<'TEMPLATE')
+ Parrot_pcc_fill_params_from_c_args(interp, call_object, "");
+TEMPLATE
+ goto return
+ end_handle_v:
.local string fill_params
$I0 = elements sig
dec $I0
Please sign in to comment.
Something went wrong with that request. Please try again.