Skip to content

Commit c10c2a1

Browse files
committed
Document how to specify the ABI/API version of a lib in NativeCall
1 parent 142b4cf commit c10c2a1

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

doc/Language/nativecall.pod

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,8 @@ TBD more
278278
You can type your C<Pointer> with passing the type as parameter. It works with native type
279279
but also C<CArray> and C<CStruct> defined type. NativeCall will not implicitly alloc the memory for it
280280
even when calling new on them.
281-
It's mostly useful in the case of a C routine returning one or if emebeded in a C<CStruct>.
281+
It's mostly useful in the case of a C routine returning a pointer, or if it's a pointer
282+
embeded in a C<CStruct>.
282283
283284
You have to call C<.deref> on it to access the embeded type.
284285
@@ -313,7 +314,39 @@ to callbacks.
313314
314315
=comment TODO
315316
316-
TBD
317+
TBD more
318+
319+
The C<native> trait accept simple lib name or a full path. It's common to
320+
have the lib parameter defined as a constant than can be modified via an
321+
environment variable. This is an example from the mysql binding in C<DBIIsh>
322+
323+
constant LIB = %*ENV<DBIISH_MYSQL_LIB> || 'libmysqlclient';
324+
# and later
325+
sub mysql_affectied_rows( .. ) returns int32 is native(LIB)
326+
327+
=head2 ABI/API Version
328+
329+
If you write C<native('libfoo')> NativeCall will search libfoo.so under Unix like system (libfoo.dynlib on Os X).
330+
In most modern system it will requiere you or the user of your module to install
331+
the develepment package because it's recommanded to always provide an API/ABI version to a
332+
shared library, so libfoo.so ends often being a symbolic link provided only by a devel package.
333+
334+
To avoid that, the C<native> trait allow you to specify the API/ABI version. It can be a full
335+
version or just a part of it (Try to stick to Major version, some BSD does not care for minor)
336+
337+
sub foo is native('libfoo', 1); # Will try to load libfoo.so.1
338+
sub foo is native('libfoo', v1.2.3); # Will try to load libfoo.so.1.2.3
339+
340+
#From DBIish Pg driver
341+
constant LIB = %*ENV<DBIISH_PG_LIB> || ('libpq', 5);
342+
343+
344+
=head2 Routine
345+
346+
the C<native> trait also accept a C<Callable> as argument, allowing you to provide your
347+
own way to handle the way it will find the library file to load.
348+
349+
sub foo is native(sub {'libfoo.so.42'});
317350
318351
=head2 Calling into the standard library
319352

0 commit comments

Comments
 (0)