|
24 | 24 | */ |
25 | 25 |
|
26 | 26 | #include "gettextpo.h" |
| 27 | +#include <gettext-po.h> |
27 | 28 | #include <ruby/internal/core/rdata.h> |
28 | 29 | #include <ruby/internal/intern/variable.h> |
29 | 30 |
|
@@ -551,10 +552,17 @@ gettextpo_po_message_m_check_format (int argc, VALUE *argv, VALUE self) |
551 | 552 |
|
552 | 553 | /* ********** file ********** */ |
553 | 554 |
|
| 555 | +void |
| 556 | +gettextpo_file_free (void *file) |
| 557 | +{ |
| 558 | + if (file) |
| 559 | + po_file_free (file); |
| 560 | +} |
| 561 | + |
554 | 562 | static const rb_data_type_t gettextpo_po_file_type = { |
555 | 563 | .wrap_struct_name = "gettextpo PO file", |
556 | 564 | .function = { |
557 | | - .dfree = (void (*)(void *)) po_file_free, |
| 565 | + .dfree = gettextpo_file_free, |
558 | 566 | }, |
559 | 567 | .flags = RUBY_TYPED_FREE_IMMEDIATELY, |
560 | 568 | }; |
@@ -602,13 +610,17 @@ gettextpo_po_file_m_read (int argc, VALUE *argv, VALUE klass) |
602 | 610 | gettextpo_xerror_context.user_xerror = &kwargs_vals[0]; |
603 | 611 | if (kwargs_vals[1] != Qundef) |
604 | 612 | gettextpo_xerror_context.user_xerror2 = &kwargs_vals[1]; |
605 | | - /* TODO: po_file_read can return NULL when not found? Also check |
606 | | - null at file free. */ |
607 | | - DATA_PTR (self) |
| 613 | + po_file_t file |
608 | 614 | = po_file_read (StringValueCStr (filename), &gettextpo_xerror_handler); |
609 | | - if (gettextpo_xerror_context.error) |
610 | | - rb_raise (ERROR, "failed to read"); |
611 | | - return self; |
| 615 | + if (file) |
| 616 | + { |
| 617 | + DATA_PTR (self) = file; |
| 618 | + if (gettextpo_xerror_context.error) |
| 619 | + rb_raise (ERROR, "failed to read"); |
| 620 | + return self; |
| 621 | + } |
| 622 | + else |
| 623 | + rb_raise (ERROR, "failed to read file, maybe file not found?"); |
612 | 624 | } |
613 | 625 |
|
614 | 626 | /** |
|
0 commit comments