|
1 | 1 | #include"postgres.h"
|
| 2 | + |
2 | 3 | #undef _
|
| 4 | + |
3 | 5 | #include"fmgr.h"
|
4 | 6 | #include"plperl.h"
|
5 | 7 | #include"plperl_helpers.h"
|
6 | 8 | #include"hstore.h"
|
7 | 9 |
|
8 | 10 | PG_MODULE_MAGIC;
|
9 | 11 |
|
| 12 | +externvoid_PG_init(void); |
| 13 | + |
| 14 | +/* Linkage to functions in hstore module */ |
| 15 | +typedefHStore*(*hstoreUpgrade_t) (Datumorig); |
| 16 | +statichstoreUpgrade_thstoreUpgrade_p; |
| 17 | +typedefint (*hstoreUniquePairs_t) (Pairs*a,int32l,int32*buflen); |
| 18 | +statichstoreUniquePairs_thstoreUniquePairs_p; |
| 19 | +typedefHStore*(*hstorePairs_t) (Pairs*pairs,int32pcount,int32buflen); |
| 20 | +statichstorePairs_thstorePairs_p; |
| 21 | +typedefsize_t (*hstoreCheckKeyLen_t) (size_tlen); |
| 22 | +statichstoreCheckKeyLen_thstoreCheckKeyLen_p; |
| 23 | +typedefsize_t (*hstoreCheckValLen_t) (size_tlen); |
| 24 | +statichstoreCheckValLen_thstoreCheckValLen_p; |
| 25 | + |
| 26 | + |
| 27 | +/* |
| 28 | + * Module initialize function: fetch function pointers for cross-module calls. |
| 29 | + */ |
| 30 | +void |
| 31 | +_PG_init(void) |
| 32 | +{ |
| 33 | +/* Asserts verify that typedefs above match original declarations */ |
| 34 | +AssertVariableIsOfType(&hstoreUpgrade,hstoreUpgrade_t); |
| 35 | +hstoreUpgrade_p= (hstoreUpgrade_t) |
| 36 | +load_external_function("$libdir/hstore","hstoreUpgrade", |
| 37 | + true,NULL); |
| 38 | +AssertVariableIsOfType(&hstoreUniquePairs,hstoreUniquePairs_t); |
| 39 | +hstoreUniquePairs_p= (hstoreUniquePairs_t) |
| 40 | +load_external_function("$libdir/hstore","hstoreUniquePairs", |
| 41 | + true,NULL); |
| 42 | +AssertVariableIsOfType(&hstorePairs,hstorePairs_t); |
| 43 | +hstorePairs_p= (hstorePairs_t) |
| 44 | +load_external_function("$libdir/hstore","hstorePairs", |
| 45 | + true,NULL); |
| 46 | +AssertVariableIsOfType(&hstoreCheckKeyLen,hstoreCheckKeyLen_t); |
| 47 | +hstoreCheckKeyLen_p= (hstoreCheckKeyLen_t) |
| 48 | +load_external_function("$libdir/hstore","hstoreCheckKeyLen", |
| 49 | + true,NULL); |
| 50 | +AssertVariableIsOfType(&hstoreCheckValLen,hstoreCheckValLen_t); |
| 51 | +hstoreCheckValLen_p= (hstoreCheckValLen_t) |
| 52 | +load_external_function("$libdir/hstore","hstoreCheckValLen", |
| 53 | + true,NULL); |
| 54 | +} |
| 55 | + |
| 56 | + |
| 57 | +/* These defines must be after the module init function */ |
| 58 | +#definehstoreUpgrade hstoreUpgrade_p |
| 59 | +#definehstoreUniquePairs hstoreUniquePairs_p |
| 60 | +#definehstorePairs hstorePairs_p |
| 61 | +#definehstoreCheckKeyLen hstoreCheckKeyLen_p |
| 62 | +#definehstoreCheckValLen hstoreCheckValLen_p |
| 63 | + |
10 | 64 |
|
11 | 65 | PG_FUNCTION_INFO_V1(hstore_to_plperl);
|
12 | 66 |
|
|