Skip to content

Commit 373f805

Browse files
committed
Rearrange handling of pointer arguments
1 parent 4bf1e9a commit 373f805

File tree

4 files changed

+112
-307
lines changed

4 files changed

+112
-307
lines changed

generate/generate.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,16 @@ def handle_function(main, params):
357357
conv.append('{0} = SF.{2}({0}) unless {0}.is_a? {1}'.format(n, t, t.lower()))
358358
t = None
359359
if n in const and t not in classes:
360-
conv += 'if {0}\n if {0}.responds_to?(:to_unsafe)\n p{0} = {0}.to_unsafe\n else\n c{0} = {0}; p{0} = pointerof(c{0})\n end\nelse\n p{0} = nil\nend'.format(n).splitlines()
360+
conv += (
361+
'if {0}.responds_to?(:to_unsafe); '
362+
'p{0} = {0}.to_unsafe\n'
363+
'elsif {0}; '
364+
'c{0} = {0}; '
365+
'p{0} = pointerof(c{0})\n'
366+
'else; '
367+
'p{0} = nil; '
368+
'end'
369+
).format(n).splitlines()
361370
t = None
362371
oparams[i] = (n, t)
363372
sparams = ', '.join('{}: {}'.format(n, t) if t else n for n, t in oparams)

src/audio_obj.cr

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -870,15 +870,9 @@ module SF
870870
#
871871
# *Returns*: A new SoundBuffer object (NULL if failed)
872872
def self.from_samples(samples, sample_count: Int, channel_count: Int, sample_rate: Int)
873-
if samples
874-
if samples.responds_to?(:to_unsafe)
875-
psamples = samples.to_unsafe
876-
else
877-
csamples = samples; psamples = pointerof(csamples)
878-
end
879-
else
880-
psamples = nil
881-
end
873+
if samples.responds_to?(:to_unsafe); psamples = samples.to_unsafe
874+
elsif samples; csamples = samples; psamples = pointerof(csamples)
875+
else; psamples = nil; end
882876
sample_count = sample_count.to_u64
883877
channel_count = channel_count.to_i32
884878
sample_rate = sample_rate.to_i32

0 commit comments

Comments
 (0)