Skip to content

Commit 0dcbf35

Browse files
committed
Fix up bindings
1 parent 665bcf3 commit 0dcbf35

9 files changed

Lines changed: 44 additions & 34 deletions

File tree

ext/prism/extension.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include <ruby/win32.h>
55
#endif
66

7+
#include <errno.h>
8+
79
// NOTE: this file should contain only bindings. All non-trivial logic should be
810
// in libprism so it can be shared its the various callers.
911

include/prism/internal/bit.h

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,32 @@
1111
* (matching the behavior of __builtin_ctzll and _BitScanForward64).
1212
*/
1313
#if defined(__GNUC__) || defined(__clang__)
14-
#define pm_ctzll(v) ((unsigned) __builtin_ctzll(v))
14+
#define pm_ctzll(v) ((unsigned) __builtin_ctzll(v))
1515
#elif defined(_MSC_VER)
16-
#include <intrin.h>
17-
static PRISM_INLINE unsigned pm_ctzll(uint64_t v) {
18-
unsigned long index;
19-
_BitScanForward64(&index, v);
20-
return (unsigned) index;
21-
}
16+
#include <intrin.h>
17+
#include <stdint.h>
18+
19+
static PRISM_INLINE unsigned
20+
pm_ctzll(uint64_t v) {
21+
unsigned long index;
22+
_BitScanForward64(&index, v);
23+
return (unsigned) index;
24+
}
2225
#else
23-
static PRISM_INLINE unsigned
24-
pm_ctzll(uint64_t v) {
25-
unsigned c = 0;
26-
v &= (uint64_t) (-(int64_t) v);
27-
if (v & 0x00000000FFFFFFFFULL) c += 0; else c += 32;
28-
if (v & 0x0000FFFF0000FFFFULL) c += 0; else c += 16;
29-
if (v & 0x00FF00FF00FF00FFULL) c += 0; else c += 8;
30-
if (v & 0x0F0F0F0F0F0F0F0FULL) c += 0; else c += 4;
31-
if (v & 0x3333333333333333ULL) c += 0; else c += 2;
32-
if (v & 0x5555555555555555ULL) c += 0; else c += 1;
33-
return c;
34-
}
26+
#include <stdint.h>
27+
28+
static PRISM_INLINE unsigned
29+
pm_ctzll(uint64_t v) {
30+
unsigned c = 0;
31+
v &= (uint64_t) (-(int64_t) v);
32+
if (v & 0x00000000FFFFFFFFULL) c += 0; else c += 32;
33+
if (v & 0x0000FFFF0000FFFFULL) c += 0; else c += 16;
34+
if (v & 0x00FF00FF00FF00FFULL) c += 0; else c += 8;
35+
if (v & 0x0F0F0F0F0F0F0F0FULL) c += 0; else c += 4;
36+
if (v & 0x3333333333333333ULL) c += 0; else c += 2;
37+
if (v & 0x5555555555555555ULL) c += 0; else c += 1;
38+
return c;
39+
}
3540
#endif
3641

3742
#endif

java-wasm/src/main/java/org/jruby/parser/prism/wasm/Prism.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ public Prism(WasiOptions wasiOpts) {
4040
preOptionsPointer = exports.calloc(1, PACKED_OPTIONS_BUFFER_SIZE);
4141
preSourcePointer = exports.calloc(1, SOURCE_SIZE);
4242

43-
bufferPointer = exports.calloc(exports.pmBufferSizeof(), 1);
44-
exports.pmBufferInit(bufferPointer);
43+
bufferPointer = exports.pmBufferNew();
4544
}
4645

4746
public byte[] serialize(byte[] packedOptions, byte[] sourceBytes, int sourceLength) {
@@ -60,7 +59,8 @@ public byte[] serialize(byte[] packedOptions, byte[] sourceBytes, int sourceLeng
6059
exports.calloc(1, packedOptions.length) : preOptionsPointer;
6160
instance.memory().write(optionsPointer, packedOptions);
6261

63-
exports.pmBufferClear(bufferPointer);
62+
exports.pmBufferFree(bufferPointer);
63+
bufferPointer = exports.pmBufferNew();
6464

6565
exports.pmSerializeParse(
6666
bufferPointer, sourcePointer, sourceLength, optionsPointer);

src/json.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,10 @@
88

99
#include "prism/json.h"
1010

11-
/* We optionally support dumping to JSON. For systems that don not want or need
12-
* this functionality, it can be turned off with the PRISM_EXCLUDE_JSON define.
13-
*/
14-
#ifdef PRISM_EXCLUDE_JSON
15-
16-
void pm_dump_json(void) {}
11+
// Ensure this translation unit is never empty, even when JSON is excluded.
12+
typedef int pm_json_unused_t;
1713

18-
#else
14+
#ifndef PRISM_EXCLUDE_JSON
1915

2016
#include "prism/internal/buffer.h"
2117
#include "prism/internal/constant_pool.h"

src/prism.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
#include "prism/excludes.h"
3232
#include "prism/serialize.h"
33+
#include "prism/stream.h"
3334
#include "prism/version.h"
3435

3536
#include <assert.h>

templates/ext/prism/api_node.c.erb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#include "prism/extension.h"
33
#include "prism/internal/allocator.h"
44

5+
#include <assert.h>
6+
57
extern VALUE rb_cPrism;
68
extern VALUE rb_cPrismNode;
79
extern VALUE rb_cPrismSource;

templates/src/json.c.erb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#include "prism/json.h"
22

3-
/* We optionally support dumping to JSON. For systems that don not want or need
4-
* this functionality, it can be turned off with the PRISM_EXCLUDE_JSON define.
5-
*/
3+
// Ensure this translation unit is never empty, even when JSON is excluded.
4+
typedef int pm_json_unused_t;
5+
66
#ifndef PRISM_EXCLUDE_JSON
77

88
#include "prism/internal/buffer.h"

templates/src/prettyprint.c.erb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
* PRISM_EXCLUDE_PRETTYPRINT define. */
77
#ifdef PRISM_EXCLUDE_PRETTYPRINT
88

9-
void pm_prettyprint(void) {}
9+
/* Ensure this translation unit is never empty, even when prettyprint is
10+
* excluded. */
11+
typedef int pm_prettyprint_unused_t;
1012

1113
#else
1214

templates/src/serialize.c.erb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
* PRISM_EXCLUDE_SERIALIZATION define. */
66
#ifdef PRISM_EXCLUDE_SERIALIZATION
77

8-
void pm_serialize_lex(void) {}
8+
/* Ensure this translation unit is never empty, even when serialization is
9+
* excluded. */
10+
typedef int pm_serialize_unused_t;
911

1012
#else
1113

0 commit comments

Comments
 (0)