Commit graph

38 commits

Author SHA1 Message Date
Felipe Contreras
777b02a7d7 ruby: add filenames helper
Right now it doesn't do much, but it will help for further
reorganization.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
2023-04-12 07:05:23 -03:00
Felipe Contreras
44924a6a09 ruby: remove Tags object
Not used anymore now that we return an array of strings directly.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
2023-04-02 19:11:10 -03:00
Felipe Contreras
ae1336dea5 ruby: add tags helper
Right now it doesn't do much, but it will help for further
reorganization.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
2023-04-02 19:00:49 -03:00
Felipe Contreras
2474bce8b1 ruby: cleanup object_destroy()
It was assumed the destructor of notmuch_rb_database_type did return a
notmuch_status_t because that's what notmuch_database_close returns, and
that value was checked by notmuch_rb_database_close in order to decide
if to raise an exception.

It turns out notmuch_database_destroy was called instead, so nothing was
returned (void).

All the destroy functions are void, and that's what we want.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
2021-08-03 20:30:15 -03:00
Felipe Contreras
7415b53fa5 ruby: split database close and destroy
Mirrors the C API: 7864350c (Split notmuch_database_close into two
functions, 2012-04-25).

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
2021-08-02 13:49:29 -03:00
Felipe Contreras
1a7f9fe055 ruby: enable garbage collection using talloc
We basically steal all the objects from their notmuch parents, therefore
they are completely under Ruby's gc control.

The order at which these objects are freed does not matter any more,
because destroying the database does not destroy all the children
objects, since they belong to Ruby now.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
2021-07-18 17:08:53 -03:00
Felipe Contreras
02b1621160 ruby: create an actual wrapper struct
Currently Ruby data points directly to a notmuch object (e.g.
notmuch_database_t), since we don't need any extra data that is fine.

However, in the next commit we will need extra data, therefore we create
a new struct notmuch_rb_object_t wrapper which contains nothing but a
pointer to the current pointer (e.g. notmuch_database_t).

This struct is tied to the Ruby object, and is freed when the Ruby
object is freed by the garbage collector.

We do nothing with this wrapper, so no functionality should be changed.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
2021-07-18 17:08:42 -03:00
Felipe Contreras
814abafc3e ruby: add keyword arguments to db.query
That way we don't need pass them to the query object ourselves.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
2021-06-27 14:13:03 -03:00
Felipe Contreras
5f49e3421f ruby: new notmuch_rb_object_destroy() helper
The struct used to store the types (rb_data_type_t) contains a "data"
field where we can store whatever we want. I use that field to store a
pointer to the corresponding destroy function. For example
notmuch_rb_database_type contains a pointer to notmuch_database_destroy.

I cast that pointer as a notmuch_status_t (func*)(void *) and call
that function passing the internal object (e.g. notmuch_database_t).

Using the rb_data_type_t data we can call the correct notmuch destroy
function.

Therefore this:

  ret = ((notmuch_status_t (*)(void *)) type->data) (nm_object);

Is effectively the same as this:

  ret = notmuch_database_destroy (database);

The advantage of doing it this way is that much less code is necesary
since each rb_data_type_t has the corresponding destroy function stored
in it.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
2021-05-17 07:25:14 -03:00
Felipe Contreras
9574fb6099 ruby: add all data types
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
2021-05-17 07:25:14 -03:00
Felipe Contreras
fba9774a81 ruby: move towards more modern RTypedData
Virtually the whole ruby core moved from RData to RTypeData, let's do so
ourselves too.

Basically the information typically passed through Data_Wrap_Struct is
now stored in a struct rb_data_type_t (mark and free functions). This
has the advantage that more information can be easily added, like the
name of the type, a custom data ponter, and more.

Data_Wrap_Struct is replaced with TypedData_Wrap_Struct, and the
information is stored in a struct rb_data_type_t, rather than passed
as arguments.

Check_Type is replaced with Check_TypedStruct, which is a wrapper for
rb_check_typeddata (with casts).

        #define Check_TypedStruct(v, t)      \
            rb_check_typeddata(RBIMPL_CAST((VALUE)(v)), (t))

We can use rb_check_typeddata directly, just like we use rb_data_object_get
directly.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
2021-05-17 07:25:14 -03:00
Felipe Contreras
12c36a5e3f ruby: create Data_Wrap_Notmuch_Object helper
This makes the code more maintainable and will help in further patches.

No functional changes.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
2021-05-17 07:25:14 -03:00
Felipe Contreras
682479592b ruby: add unlikely hint
The error path is very unlikely.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
2021-05-17 07:25:14 -03:00
Felipe Contreras
79bb82c217 ruby: fetch class name in case of error
There is not much point in complicating the code for error messages that
can be easily constructed.

Before:

  database closed (RuntimeError)

After:

  Notmuch::Database object destroyed (RuntimeError)

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
2021-05-17 07:25:14 -03:00
Felipe Contreras
78c059a24c ruby: simplify data get helper
Data_Get_Struct is nothing but a macro that calls
rb_data_object_get with a cast (unnecessary in C).

        #define Data_Get_Struct(obj, type, sval) \
            ((sval) = RBIMPL_CAST((type*)rb_data_object_get(obj)))

We can use rb_data_object_get directly, and this way we don't need to
pass the type, which is unnecessary information.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
2021-05-17 07:25:14 -03:00
Felipe Contreras
a34d7b4144 ruby: improve general data get helper
There's no need to do Check_Type, Data_Get_Struct calls
rb_data_object_get(), which already does that.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
2021-05-12 19:13:31 -03:00
Felipe Contreras
2e57ffb860 ruby: improve all Data_Get_Notmuch_* helpers
There's no need to repeat the same code over and over.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
2021-05-12 19:13:12 -03:00
Daniel Kahn Gillmor
6a833a6e83 Use https instead of http where possible
Many of the external links found in the notmuch source can be resolved
using https instead of http.  This changeset addresses as many as i
could find, without touching the e-mail corpus or expected outputs
found in tests.
2016-06-05 08:32:17 -03:00
Ludovic LANGE
7e6e23c36e ruby: add bindings for notmuch_database_get_all_tags
The Ruby bindings were missing a way to get all the tags of the
database. Now you should be able to access this with the public
instance method `all_tags` of your database object.

Example of use:
    notmuchdb = Notmuch::Database.new path, { :create => false,
    	:mode => Notmuch::MODE_READ_ONLY }

    my_tags = notmuchdb.all_tags

    my_tags.each { |tag|
      print tag
    }

    my_tags.destroy!

Amended by db: improve error reporting, add test
2016-05-19 08:02:43 -03:00
Wael M. Nasreddine
0629afeb26 ruby: Add wrapper for notmuch_query_count_threads 2014-05-18 06:39:58 +09:00
Austin Clements
c4f96d0931 ruby: Add bindings for notmuch_thread_get_messages 2013-02-18 20:23:40 -04:00
Tomi Ollila
d796dad4ed ruby: extern linkage portability improvement
Some C compilers are stricter when it comes to (tentative) definition
of a variable -- in those compilers introducing variable without 'extern'
keyword always allocates new 'storage' to the variable and linking all
these modules fails due to duplicate symbols.

This is reimplementation of Charlie Allom's patch:
id:"1336481467-66356-1-git-send-email-charlie@mediasp.com",
written originally by Ali Polatel. This version has
more accurate commit message.
2012-06-29 22:24:17 -03:00
Felipe Contreras
35cb1c95cc Revert "ruby: Add workarounds to use in-tree build not the installed one"
This reverts commit 82b73ffd73.

Only leave the copyright changes.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
2012-05-25 15:11:31 +02:00
Ali Polatel
a8e010962f ruby: Add wrapper for notmuch_query_set_omit_excluded() 2012-05-08 10:34:50 -03:00
Ali Polatel
82b73ffd73 ruby: Add workarounds to use in-tree build not the installed one
- Make mkmf use the notmuch.h under ../../lib
- Use libnotmuch.a instead of linking to the installed libnotmuch.so
2012-05-08 10:34:33 -03:00
Ali Polatel
92680f12eb ruby: Add wrapper for notmuch_query_add_tag_exclude 2012-05-08 10:32:56 -03:00
Ali Polatel
d0000daab3 ruby: Add wrapper for notmuch_query_count_messages 2012-05-08 10:32:45 -03:00
Ali Polatel
5c00af46ec ruby: Fix macros, use quoting
Fix Data_Get_Notmuch_* macro definitions broken by prev. commit
Adequate quoting for Data_Get_Notmuch_* macros
Remove duplicated RSTRING_PTR() macros, move it to defs.h
2011-10-04 16:57:33 +03:00
Ali Polatel
c8a88fe95d ruby: Really add wrappers for database_find_message*
Commit 898613116d only added wrapper
functions but did not register them. Register the functions in module's
initialization function.
2011-10-04 16:48:34 +03:00
Ali Polatel
05dddf883d ruby: be consistent with notmuch's coding style
No functional change, just indentation
2011-10-04 16:43:40 +03:00
Ali Polatel
59d2457bcc ruby: New exception Notmuch::UnbalancedAtomicError
This exception wraps NOTMUCH_STATUS_UNBALANCED_ATOMIC which was added
with the commit e59cc0031f.
2011-09-24 15:54:45 +03:00
Ali Polatel
bbb41081d7 ruby: Wrap notmuch_database_{begin,end}_atomic
Adding ruby wrappers for functions:
- notmuch_database_begin_atomic()
- notmuch_database_end_atomic()
added by 957f1ba3fc

New functions:
Notmuch::Database.begin_atomic()
Notmuch::Database.end_atomic()
2011-09-24 15:43:43 +03:00
Ali Polatel
90a66779e1 ruby: Add wrapper for message_get_filenames 2011-01-25 12:03:41 +02:00
Ali Polatel
02369d031c ruby: Add wrappers for maildir sync. interface
New wrappers:
notmuch_message_maildir_flags_to_tags(): MESSAGE.maildir_flags_to_tags
notmuch_message_tags_to_maildir_flags(): MESSAGE.tags_to_maildir_flags
2011-01-25 12:03:37 +02:00
Ali Polatel
ed38940323 ruby: Add wrappers for query_get_s{ort,tring}
New wrappers:
notmuch_query_get_sort(): QUERY.sort
notmuch_query_get_query_string(): QUERY.to_s
2011-01-25 12:03:32 +02:00
Ali Polatel
5c9e385591 ruby: Don't barf if an object is destroyed more than once
Raise RuntimeError instead.
Also revise Notmuch::Database a bit.
Add Notmuch::Database.open singleton method.
2010-06-06 09:18:00 +03:00
Ali Polatel
c7893408bb ruby: Kill garbage collection related cruft.
Let the user destroy objects that she wants explicitly.
It's not possible to specify the order objects are garbage collected.
See id:86y6f8v838.fsf@harikalardiyari.ev on ruby-talk for more
information.
2010-06-06 09:17:47 +03:00
Ali Polatel
06bf04500b Initial ruby bindings 2010-06-06 09:16:53 +03:00