Skip to content

Commit

Permalink
Fix ruby 3.2 compile errors (#10)
Browse files Browse the repository at this point in the history
* Avoid deleting sketchup.rb when cleaning

* Add sketchup headers to include paths

* Setup file associations

* Fix all ruby 3.2 compile warnings

---------

Co-authored-by: Noel Warren <noelwarren@users.noreply.github.com>
  • Loading branch information
noelwarren and noelwarren authored Nov 6, 2024
1 parent 2902baa commit 88dbcd2
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 22 deletions.
1 change: 1 addition & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "Mac",
"includePath": [
"${workspaceFolder}/ext",
"${workspaceFolder}/sketchup-sdk-mac/headers",
"/opt/homebrew/opt/ruby@3.2/include/ruby-3.2.0",
"/opt/homebrew/opt/ruby@3.2/include/ruby-3.2.0/arm64-darwin*",
"/opt/homebrew/opt/ruby@2.7/include/ruby-2.7.0",
Expand Down
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"files.associations": {
"*.c": "c",
"*.h": "c",
"*.rb": "ruby"
}
}
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Bundler.setup
prefix = RbConfig::CONFIG['prefix']
ENV['PATH'] = "#{prefix}/msys64/usr/bin;#{prefix}/msys64/mingw64/bin;#{ENV['PATH']}"

CLEAN.include 'lib/sketchup.*', 'Makefile', 'tmp', '*.o', 'sketchup.bundle', 'sketchup.so'
CLEAN.include 'lib/sketchup.bundle', 'lib/sketchup.so', 'Makefile', 'tmp', '*.o', 'sketchup.bundle', 'sketchup.so'

Rake::ExtensionTask.new 'sketchup' do |ext|
ext.lib_dir = 'lib'
Expand Down
2 changes: 1 addition & 1 deletion ext/attribute_dictionaries.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static VALUE Sketchup_AttributeDictionaries_length(VALUE self)
SUModelRef model = {DATA_PTR(self)};
size_t count;
SUModelGetNumAttributeDictionaries(model, &count);
return INT2NUM(count);
return ULL2NUM(count);
}

VALUE AttributeDictionaries_Init(VALUE Sketchup, VALUE Sketchup_Entity)
Expand Down
6 changes: 3 additions & 3 deletions ext/color.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,20 @@ static VALUE Sketchup_Color_names(VALUE self)
size_t count = 0;
SUColorGetNumNames(&count);
SUStringRef* names = malloc(count * sizeof(SUStringRef));
for (int i = 0; i < count; i++)
for (size_t i = 0; i < count; i++)
{
names[i].ptr = 0;
SUStringCreate(&names[i]);
}
SUColorGetNames(names, count);
VALUE ary = rb_ary_new2(count);
for (int i = 0; i < count; i++)
for (size_t i = 0; i < count; i++)
{
VALUE name;
GETUTF8FROMSTRING(names[i], name);
rb_ary_push(ary, name);
}
for (int i = 0; i < count; i++)
for (size_t i = 0; i < count; i++)
{
SUStringRelease(&names[i]);
}
Expand Down
4 changes: 2 additions & 2 deletions ext/component_definition.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ static VALUE Sketchup_ComponentDefinition_count_instances(VALUE self)
SUComponentDefinitionRef definition = {DATA_PTR(self)};
size_t count = 0;
SUComponentDefinitionGetNumInstances(definition, &count);
return INT2NUM(count);
return ULL2NUM(count);
}

static VALUE Sketchup_ComponentDefinition_count_used_instances(VALUE self)
{
SUComponentDefinitionRef definition = {DATA_PTR(self)};
size_t count = 0;
SUComponentDefinitionGetNumUsedInstances(definition, &count);
return INT2NUM(count);
return ULL2NUM(count);
}

static VALUE Sketchup_ComponentDefinition_live_component(VALUE self)
Expand Down
2 changes: 1 addition & 1 deletion ext/definition_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ static VALUE Sketchup_DefinitionList_count(VALUE self)
size_t gd_count = 0;
SUModelGetNumComponentDefinitions(model, &cd_count);
SUModelGetNumGroupDefinitions(model, &gd_count);
return INT2NUM(cd_count + gd_count);
return ULL2NUM(cd_count + gd_count);
}

static VALUE Sketchup_DefinitionList_load(VALUE self, VALUE path)
Expand Down
7 changes: 4 additions & 3 deletions ext/entity.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@ static VALUE Sketchup_Entity_remove_observer(VALUE self, VALUE observer)
return RTEST(result) ? Qtrue : Qfalse;
}

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wcompound-token-split-by-macro"
#pragma clang diagnostic ignored "-Wunused-but-set-variable"
static VALUE Sketchup_Entity_add_observer(VALUE self, VALUE observer)
{
VALUE observers = Qnil;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wcompound-token-split-by-macro"
if (RTEST(rb_ivar_defined(self, rb_intern("@observers"))))
#pragma clang diagnostic pop
{
observers = rb_iv_get(self, "@observers");
}
Expand All @@ -129,6 +129,7 @@ static VALUE Sketchup_Entity_add_observer(VALUE self, VALUE observer)
rb_hash_aset(self, observer, observer);
return Qtrue;
}
#pragma clang diagnostic pop

void Sketchup_Entity_attribute_dictionaries_Iterator(SUAttributeDictionaryRef dictionary, VALUE* ary)
{
Expand Down
11 changes: 4 additions & 7 deletions ext/material.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <stdbool.h>
#include <material.h>
#include <SketchUpAPI/sketchup.h>
#include <SketchUpAPI/model/material.h>
#include <utils.h>

static int GETCOLOR(VALUE obj)
Expand All @@ -25,11 +26,6 @@ static float GETALPHA(VALUE obj)
return alpha;
}

static void dealloc(SUColor* ptr)
{
free(ptr);
}

static VALUE VALUE2COLOR(VALUE obj)
{
if (rb_obj_is_kind_of(obj, rb_path2class(SKETCHUP_COLOR)))
Expand All @@ -54,7 +50,7 @@ static VALUE VALUE2COLOR(VALUE obj)
rb_raise(rb_eTypeError, "no implicit conversion to Color");
}

static VALUE VALUE2COLORIZATION(VALUE obj)
static enum SUMaterialColorizeType VALUE2COLORIZATION(VALUE obj)
{
int colorization = NUM2INT(obj);
if (colorization < 0)
Expand Down Expand Up @@ -130,7 +126,8 @@ static VALUE Sketchup_Material_Get_color(VALUE self)
static VALUE Sketchup_Material_Set_color(VALUE self, VALUE color)
{
SUMaterialRef material = {DATA_PTR(self)};
VALUE valueColor = VALUE2COLOR(color);
VALUE2COLOR(color);
SUMaterialSetColor(material, DATA_PTR(VALUE2COLOR(color)));
return color;
}

Expand Down
8 changes: 4 additions & 4 deletions ext/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
SUGetNum(ref, &num); \
SURef* array = malloc(num * sizeof(SURef)); \
SUGet(ref, num, array, &num); \
for( int i = 0; i < num; i++) \
for(size_t i = 0; i < num; i++) \
callback(array[i], userdata); \
free(array); \
}
Expand All @@ -48,15 +48,15 @@
size_t num; \
SUGetNum(ref, &num); \
SURef* array = malloc(num * sizeof(SURef)); \
for (int i = 0; i < num; i++) \
for (size_t i = 0; i < num; i++) \
{ \
array[i].ptr = 0; \
SUStringCreate(&array[i]); \
} \
SUGet(ref, num, array, &num); \
for (int i = 0; i < num; i++) \
for (size_t i = 0; i < num; i++) \
callback(array[i], userdata); \
for (int i = 0; i < num; i++) \
for (size_t i = 0; i < num; i++) \
SUStringRelease(&array[i]); \
free(array); \
}
Expand Down

0 comments on commit 88dbcd2

Please sign in to comment.