Extending and Embedding Perl

Free Download

Authors:

Edition: illustrated edition

ISBN: 9781930110823, 1930110820

Size: 4 MB (4041101 bytes)

Pages: 384/384

File format:

Language:

Publishing Year:

Category:

Tim Jenness, Simon Cozens9781930110823, 1930110820

An explanation of how to expand the functionality and usefulness of the Perl programming language, this guide delves into the complex issues of using real code examples from the Perl source. Detailed is how to use Perl from C programs, such as writing interfaces to C libraries, techniques on implementing Perl callbacks for C libraries, passing Perl hashes and arrays between Perl and C. Additionally, developers are provided with an API reference for the internal C interface to Perl and a reference on the typemap system.

Table of contents :
contents……Page 7
preface……Page 13
acknowledgments……Page 15
about this book……Page 16
author online……Page 19
about the cover illustration……Page 20
1.1 Hello, world……Page 21
1.2 The C compiler……Page 22
1.3 Header files……Page 23
1.4 The main function……Page 24
1.5.1 Function parameters……Page 26
1.5.2 Automatic variables……Page 27
1.5.3 Global variables……Page 28
1.5.4 Static variables……Page 29
1.6 Data types……Page 30
1.6.1 C types……Page 31
1.6.2 Types defined in Perl……Page 35
1.7 Casting……Page 36
1.8.1 Statements and blocks……Page 37
1.8.2 The break and continue statements……Page 38
1.8.3 The switch statement……Page 39
1.9 Macros and the C preprocessor……Page 40
1.11 Summary……Page 43
2.1 Perl modules……Page 44
2.1.1 Module distributions……Page 46
2.2.1 The Perl module……Page 50
2.2.2 The XS file……Page 51
2.2.3 Example: “Hello, world”……Page 52
2.2.4 Return values……Page 56
2.2.5 Arguments and return values……Page 57
2.3.1 Modifying input variables……Page 58
2.3.2 Output arguments……Page 59
2.3.3 Compiler constants……Page 60
2.4 What about Makefile.PL?……Page 64
2.5 Interface design: part 1……Page 67
2.5.2 Don’t supply what is already known……Page 68
2.5.5 Use double precision……Page 69
2.7 Summary……Page 70
3.1 Arrays……Page 71
3.2 Pointers……Page 73
3.2.1 Pointers and arrays……Page 75
3.2.2 Pointers to functions……Page 77
3.3 Strings……Page 78
3.3.1 Arrays of strings……Page 79
3.4 Structures……Page 80
3.5 File I/O……Page 82
3.6 Memory management……Page 83
3.6.1 Allocating memory at runtime……Page 84
3.6.3 Manipulating memory……Page 85
3.6.4 Memory manipulation and Perl……Page 87
3.7 C Traps for the Perl programmer……Page 88
3.9 Summary……Page 89
4.1 General concepts……Page 90
4.1.2 Looking inside: Devel::Peek……Page 91
4.1.3 The flag system……Page 92
4.2.1 The SvNULL type……Page 94
4.2.3 SvPV: string values……Page 96
4.2.4 SvPVIV: integers……Page 98
4.2.5 SvPVNV: floating-point numbers……Page 99
4.2.7 SvOOK: offset strings……Page 100
4.3 Magic variables: SvPVMG……Page 101
4.4 Array variables……Page 105
4.5 Hashes……Page 107
4.6 Globs……Page 111
4.7 Namespaces and stashes……Page 114
4.8 Lexical “my” variables……Page 115
4.9 Code blocks……Page 116
4.9.1 Important CV flags……Page 117
4.11 Summary……Page 119
The Perl 5 API……Page 120
5.2.1 Special SVs……Page 121
5.2.2 Creating SVs……Page 123
5.2.3 Accessing data……Page 130
5.2.4 Manipulating data……Page 139
5.2.5 String functions……Page 144
5.2.6 References……Page 149
5.3.1 Creation and destruction……Page 152
5.3.2 Manipulating elements……Page 156
5.3.3 Testing and changing array size……Page 162
5.4.1 Creation and destruction……Page 164
5.4.2 Manipulating elements……Page 166
5.5.1 Memory management……Page 170
5.5.2 Unicode data handling……Page 175
5.5.3 Everything else……Page 178
5.6 Summary……Page 182
Advanced XS programming……Page 183
6.1 Pointers and things……Page 184
6.2 Filehandles……Page 186
6.3 Typemaps……Page 187
6.4 The argument stack……Page 189
6.5.1 C structures as black boxes……Page 190
6.5.2 C structures as objects……Page 196
6.5.3 C structures as hashes……Page 199
6.6.1 Passing numeric arrays from Perl to C……Page 203
6.6.2 Passing numeric arrays from C to Perl……Page 210
6.6.3 The Perl Data Language……Page 212
6.6.4 Benchmarks……Page 218
6.6.5 Character strings……Page 219
6.7 Callbacks……Page 222
6.7.1 Immediate callbacks……Page 223
6.7.2 Deferred callbacks……Page 226
6.7.3 Multiple callbacks……Page 227
6.8.1 Linking Perl to C++……Page 229
6.8.2 Linking Perl to Fortran……Page 236
6.9 Interface design: part 2……Page 243
6.10 Older Perls……Page 244
6.11 What’s really going on?……Page 245
6.11.1 What does xsubpp generate?……Page 246
6.13 Summary……Page 250
Alternatives to XS……Page 251
7.1 The h2xs program……Page 252
7.2 SWIG……Page 253
7.2.1 Data structures……Page 256
7.3 The Inline module……Page 258
7.3.1 What is going on?……Page 259
7.3.2 Additional Inline examples……Page 260
7.3.3 Inline and CPAN……Page 265
7.3.4 Inline module summary……Page 266
7.4 The PDL::PP module……Page 267
7.4.1 The .pd file……Page 268
7.4.2 The Makefile.PL file……Page 269
7.5 Earlier alternatives……Page 271
7.6 Further reading……Page 272
7.7 Summary……Page 273
8.1 When to embed……Page 274
8.4 “Hello C” from Perl……Page 275
8.5 Passing data……Page 277
8.6 Calling Perl routines……Page 279
8.6.1 Stack manipulation……Page 281
8.6.3 Trapping errors with eval……Page 283
8.6.4 Calling Perl methods in C……Page 284
8.7 Using C in Perl in C……Page 285
8.8 Embedding wisdom……Page 286
8.9 Summary……Page 287
9.1 Goals……Page 288
9.2 Preparing the ground……Page 289
9.3 Configuration options……Page 290
9.4.1 Binary options……Page 293
9.4.2 Quad-state options……Page 294
9.4.3 String options……Page 295
9.5 Summary……Page 296
10.1.1 The Perl library……Page 297
10.1.5 The parser and tokenizer……Page 298
10.2.1 BNF and parsing……Page 299
10.2.3 Parsing some Perl……Page 301
10.3.1 Basic tokenizing……Page 302
10.3.2 Sublexing……Page 304
10.4.1 The basic op……Page 305
10.4.3 Different flavors of ops……Page 306
10.4.4 Tying it all together……Page 308
10.4.5 PP Code……Page 310
10.4.7 Scratchpads and targets……Page 313
10.4.9 Op code trees summary……Page 314
10.6.1 What is the Perl compiler?……Page 315
10.6.2 B:: modules……Page 316
10.6.3 What B and O provide……Page 319
10.6.4 Using B for simple tasks……Page 320
10.8 Summary……Page 323
11.1.1 Perl versioning……Page 324
11.1.4 Pumpkins and pumpkings……Page 325
11.2 Debugging aids……Page 326
11.2.2 The built-in debugger: perl -D……Page 327
11.2.4 External debuggers……Page 330
11.3.1 How to solve problems……Page 337
11.3.2 Autogenerated files……Page 338
11.3.3 The patch itself……Page 339
11.3.6 Submitting your patch……Page 340
11.4.1 A history……Page 341
11.4.2 Design and implementation……Page 342
11.6 Summary……Page 343
A.1 Quick refresher……Page 344
A.2.1 T_SV……Page 345
A.2.2 T_SVREF……Page 346
A.2.4 T_HVREF……Page 347
A.2.5 T_CVREF……Page 348
A.2.6 T_SYSRET……Page 349
A.2.8 T_IV……Page 350
A.2.10 T_ENUM……Page 351
A.2.13 T_SHORT……Page 352
A.2.15 T_LONG……Page 353
A.2.17 T_CHAR……Page 354
A.2.19 T_FLOAT……Page 355
A.2.21 T_DOUBLE……Page 356
A.2.23 T_PTR……Page 357
A.2.24 T_PTRREF……Page 358
A.2.25 T_PTROBJ……Page 359
A.2.27 T_OPAQUEPTR……Page 360
A.2.28 T_OPAQUE……Page 362
A.2.30 T_PACKEDARRAY……Page 363
A.2.31 T_ARRAY……Page 364
A.2.32 T_STDIO……Page 366
A.2.33 T_INOUT……Page 367
Perl……Page 368
C……Page 369
Appendix C: Perl API index……Page 370
index……Page 375

Reviews

There are no reviews yet.

Be the first to review “Extending and Embedding Perl”
Shopping Cart
Scroll to Top